importguardpy 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,114 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ lint:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+
15
+ - name: Set up Python
16
+ uses: actions/setup-python@v5
17
+ with:
18
+ python-version: "3.11"
19
+
20
+ - name: Install dependencies
21
+ run: |
22
+ python -m pip install --upgrade pip
23
+ pip install ruff
24
+
25
+ - name: Run ruff linter
26
+ run: ruff check src/ tests/
27
+
28
+ - name: Run ruff formatter check
29
+ run: ruff format --check src/ tests/
30
+
31
+ typecheck:
32
+ runs-on: ubuntu-latest
33
+ steps:
34
+ - uses: actions/checkout@v4
35
+
36
+ - name: Set up Python
37
+ uses: actions/setup-python@v5
38
+ with:
39
+ python-version: "3.11"
40
+
41
+ - name: Install dependencies
42
+ run: |
43
+ python -m pip install --upgrade pip
44
+ pip install mypy
45
+
46
+ - name: Run mypy
47
+ run: mypy src/importguard
48
+
49
+ test:
50
+ runs-on: ${{ matrix.os }}
51
+ strategy:
52
+ fail-fast: false
53
+ matrix:
54
+ os: [ubuntu-latest, macos-latest, windows-latest]
55
+ python-version: ["3.9", "3.10", "3.11", "3.12"]
56
+ exclude:
57
+ # Reduce CI time by testing fewer combinations
58
+ - os: macos-latest
59
+ python-version: "3.9"
60
+ - os: macos-latest
61
+ python-version: "3.10"
62
+ - os: windows-latest
63
+ python-version: "3.9"
64
+ - os: windows-latest
65
+ python-version: "3.10"
66
+ steps:
67
+ - uses: actions/checkout@v4
68
+
69
+ - name: Set up Python ${{ matrix.python-version }}
70
+ uses: actions/setup-python@v5
71
+ with:
72
+ python-version: ${{ matrix.python-version }}
73
+
74
+ - name: Install dependencies
75
+ run: |
76
+ python -m pip install --upgrade pip
77
+ pip install -e ".[dev]"
78
+
79
+ - name: Run tests
80
+ run: pytest tests/ -v --tb=short
81
+
82
+ - name: Test CLI works
83
+ run: |
84
+ python -m importguard check json
85
+ python -m importguard check os --max-ms 5000
86
+
87
+ - name: Test JSON output
88
+ run: python -m importguard check json --json
89
+
90
+ - name: Test repeat functionality
91
+ run: python -m importguard check json --repeat 3 --max-ms 100
92
+
93
+ build:
94
+ runs-on: ubuntu-latest
95
+ needs: [lint, typecheck, test]
96
+ steps:
97
+ - uses: actions/checkout@v4
98
+
99
+ - name: Set up Python
100
+ uses: actions/setup-python@v5
101
+ with:
102
+ python-version: "3.11"
103
+
104
+ - name: Install build tools
105
+ run: pip install build
106
+
107
+ - name: Build package
108
+ run: python -m build
109
+
110
+ - name: Upload artifacts
111
+ uses: actions/upload-artifact@v4
112
+ with:
113
+ name: dist
114
+ path: dist/
@@ -0,0 +1,31 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ environment: pypi
11
+ permissions:
12
+ id-token: write # Required for trusted publishing
13
+
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - name: Set up Python
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: "3.11"
21
+
22
+ - name: Install build tools
23
+ run: pip install build
24
+
25
+ - name: Build package
26
+ run: python -m build
27
+
28
+ - name: Publish to PyPI
29
+ uses: pypa/gh-action-pypi-publish@release/v1
30
+ # Uses trusted publishing - no API token needed
31
+ # Configure at: https://pypi.org/manage/project/importguardpy/settings/publishing/
@@ -0,0 +1,13 @@
1
+ tests/__pycache__/
2
+ src/__pycache__/
3
+ .pytest_cache/
4
+ .ruff_cache/
5
+ .mypy_cache/
6
+ .coverage
7
+ .coverage.*
8
+ .coverage.*.*
9
+ .coverage.*.*.*
10
+ .coverage.*.*.*.*
11
+ .coverage.*.*.*.*.*
12
+ __pycache__/
13
+ dist
@@ -0,0 +1,15 @@
1
+ [importguard]
2
+ # Global budget for any module not explicitly configured
3
+ max_total_ms = 500
4
+
5
+ # Per-module budgets
6
+ [importguard.budgets]
7
+ "json" = 50
8
+ "urllib.request" = 100
9
+ "requests" = 200
10
+
11
+ # Banned top-level imports per module
12
+ [importguard.banned]
13
+ "urllib.request" = ["ssl"]
14
+ "requests" = ["pandas", "torch"]
15
+
@@ -0,0 +1,58 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.0] - 2025-01-01
9
+
10
+ ### Added
11
+
12
+ - **CLI**: `importguard check <module>` command with full option support
13
+ - `--max-ms MS` — Fail if import exceeds time budget
14
+ - `--ban MODULE` — Ban modules from being imported (repeatable)
15
+ - `--config FILE` — Load `.importguard.toml` configuration
16
+ - `--top N` — Show top N slowest imports
17
+ - `--json` — Machine-readable JSON output for CI
18
+ - `--quiet` — Only output on failure
19
+ - `--repeat K` — Run K times, report median (reduces noise)
20
+ - `--python PATH` — Use specific Python interpreter
21
+
22
+ - **Configuration**: `.importguard.toml` support
23
+ - Global `max_total_ms` budget
24
+ - Per-module budgets via `[importguard.budgets]`
25
+ - Per-module banned imports via `[importguard.banned]`
26
+ - Auto-discovery walking up directory tree
27
+
28
+ - **Python API**: `check_import()` function
29
+ - Returns `ImportResult` with full timing data
30
+ - Supports `max_ms`, `banned`, `repeat`, `python_path` parameters
31
+ - Accepts both `list` and `set` for banned modules
32
+
33
+ - **Core Engine**
34
+ - Uses Python's `-X importtime` for accurate timing
35
+ - Wall-clock backup measurement via `time.perf_counter_ns()`
36
+ - Runs in isolated subprocess (no interpreter pollution)
37
+ - Handles import failures gracefully
38
+
39
+ - **CI Integration**
40
+ - GitHub Actions workflow example
41
+ - Pre-commit hook example
42
+ - JSON output for machine parsing
43
+ - Warnings for near-budget imports
44
+
45
+ - **Documentation**
46
+ - Comprehensive README with examples
47
+ - "Why Results Differ on CI?" troubleshooting guide
48
+ - "How to Keep Imports Fast" best practices
49
+
50
+ ### Technical Details
51
+
52
+ - Zero runtime dependencies
53
+ - Python 3.9+ support
54
+ - Full type annotations (mypy strict)
55
+ - 64+ test cases
56
+
57
+ [0.1.0]: https://github.com/AryanKumar1401/importguard/releases/tag/v0.1.0
58
+
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Aryan Kumar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+