python-auto-req 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,34 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ["main", "master"]
6
+ pull_request:
7
+ branches: ["main", "master"]
8
+
9
+ jobs:
10
+ test:
11
+ name: "Test Python ${{ matrix.python-version }} / ${{ matrix.os }}"
12
+ runs-on: ${{ matrix.os }}
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ os: [ubuntu-latest, windows-latest]
17
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
18
+
19
+ steps:
20
+ - uses: actions/checkout@v6
21
+
22
+ - name: Set up Python ${{ matrix.python-version }}
23
+ uses: actions/setup-python@v6
24
+ with:
25
+ python-version: ${{ matrix.python-version }}
26
+
27
+ - name: Install package + pytest
28
+ run: |
29
+ python -m pip install --upgrade pip
30
+ pip install -e .
31
+ pip install pytest
32
+
33
+ - name: Run tests
34
+ run: pytest tests/ -v
@@ -0,0 +1,101 @@
1
+ name: Publish to PyPI
2
+
3
+ # Triggers when you push a version tag: git tag v0.1.0 && git push --tags
4
+ on:
5
+ push:
6
+ tags:
7
+ - "v*.*.*"
8
+
9
+ # Required for PyPI Trusted Publishing (OIDC) – no API token needed.
10
+ permissions:
11
+ contents: read
12
+ id-token: write # allows the job to request an OIDC token from GitHub
13
+
14
+ jobs:
15
+ # -------------------------------------------------------------------------
16
+ # 1. Run the full test suite before publishing
17
+ # -------------------------------------------------------------------------
18
+ test:
19
+ name: "Test before publish"
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@v6
23
+
24
+ - uses: actions/setup-python@v6
25
+ with:
26
+ python-version: "3.13"
27
+
28
+ - name: Install package + pytest
29
+ run: |
30
+ python -m pip install --upgrade pip
31
+ pip install -e .
32
+ pip install pytest
33
+
34
+ - name: Run tests
35
+ run: pytest tests/ -v
36
+
37
+ # -------------------------------------------------------------------------
38
+ # 2. Build the distribution
39
+ # -------------------------------------------------------------------------
40
+ build:
41
+ name: "Build distribution"
42
+ runs-on: ubuntu-latest
43
+ needs: test
44
+ steps:
45
+ - uses: actions/checkout@v6
46
+
47
+ - uses: actions/setup-python@v6
48
+ with:
49
+ python-version: "3.13"
50
+
51
+ - name: Install build tools
52
+ run: python -m pip install --upgrade pip hatchling build
53
+
54
+ - name: Build wheel + sdist
55
+ run: python -m build
56
+
57
+ - name: Verify tag matches package version
58
+ # Exits non-zero (fails the build) if the git tag doesn't match
59
+ # the version declared in pyproject.toml.
60
+ run: |
61
+ TAG="${GITHUB_REF_NAME#v}" # strip leading 'v'
62
+ PKG=$(python -c "import tomllib; f=open('pyproject.toml','rb'); print(tomllib.load(f)['project']['version'])")
63
+ echo "Tag version : $TAG"
64
+ echo "Package version: $PKG"
65
+ [ "$TAG" = "$PKG" ] || { echo "Version mismatch!"; exit 1; }
66
+
67
+ - name: Upload build artifacts
68
+ uses: actions/upload-artifact@v7
69
+ with:
70
+ name: dist
71
+ path: dist/
72
+
73
+ # -------------------------------------------------------------------------
74
+ # 3. Publish to PyPI via Trusted Publishing (OIDC – no API token required)
75
+ #
76
+ # One-time setup on PyPI:
77
+ # 1. Go to https://pypi.org/manage/account/publishing/
78
+ # 2. Add a new "pending publisher":
79
+ # PyPI project name : python-auto-req
80
+ # GitHub owner : Amit-Roy
81
+ # Repository name : python-auto-req
82
+ # Workflow filename : publish.yml
83
+ # Environment name : pypi (must match the environment: below)
84
+ # -------------------------------------------------------------------------
85
+ publish:
86
+ name: "Publish to PyPI"
87
+ runs-on: ubuntu-latest
88
+ needs: build
89
+ environment:
90
+ name: pypi
91
+ url: https://pypi.org/project/python-auto-req/
92
+ steps:
93
+ - name: Download build artifacts
94
+ uses: actions/download-artifact@v8
95
+ with:
96
+ name: dist
97
+ path: dist/
98
+
99
+ - name: Publish to PyPI
100
+ uses: pypa/gh-action-pypi-publish@release/v1
101
+ # No 'with: password:' token needed – OIDC handles authentication.
@@ -0,0 +1,39 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.pyo
5
+ *.pyd
6
+ .Python
7
+
8
+ # Packaging / build
9
+ dist/
10
+ build/
11
+ *.egg-info/
12
+ *.egg
13
+ .eggs/
14
+
15
+ # Virtual environments
16
+ .venv/
17
+ venv/
18
+ env/
19
+ ENV/
20
+
21
+ # Test / coverage
22
+ .pytest_cache/
23
+ .coverage
24
+ coverage.xml
25
+ htmlcov/
26
+
27
+ # Type checkers
28
+ .mypy_cache/
29
+ .ruff_cache/
30
+
31
+ # IDE
32
+ .vscode/
33
+ .idea/
34
+ *.sublime-project
35
+ *.sublime-workspace
36
+
37
+ # OS
38
+ .DS_Store
39
+ Thumbs.db
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
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.
@@ -0,0 +1,177 @@
1
+ Metadata-Version: 2.4
2
+ Name: python-auto-req
3
+ Version: 0.1.0
4
+ Summary: Scan project source files and populate requirements.txt – with PyPI search and interactive resolution.
5
+ Project-URL: Homepage, https://github.com/Amit-Roy/python-auto-req
6
+ Project-URL: Repository, https://github.com/Amit-Roy/python-auto-req
7
+ Project-URL: Issues, https://github.com/Amit-Roy/python-auto-req/issues
8
+ Author-email: Amit Roy <a.roy.0593@gmail.com>
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: dependencies,pypi,requirements,scanner
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Topic :: Utilities
23
+ Requires-Python: >=3.10
24
+ Provides-Extra: dev
25
+ Requires-Dist: build; extra == 'dev'
26
+ Requires-Dist: hatchling; extra == 'dev'
27
+ Requires-Dist: pytest; extra == 'dev'
28
+ Requires-Dist: twine; extra == 'dev'
29
+ Description-Content-Type: text/markdown
30
+
31
+ # python-auto-req
32
+
33
+ Scan your Python project's `.py` and `.ipynb` files, discover every third-party
34
+ package that is actually **imported**, and add them to `requirements.txt`.
35
+
36
+ > **Only packages explicitly referenced in your source files are considered.**
37
+ > Packages installed in `.venv` but never imported are ignored.
38
+
39
+ ---
40
+
41
+ ## Features
42
+
43
+ - Recursively scans `.py` and `.ipynb` files (skips `.venv`, `.git`, `__pycache__`, etc.)
44
+ - Uses the active Python environment to resolve module → distribution name + version
45
+ - Falls back to a **live PyPI search** for unknown modules with an interactive menu:
46
+ - Pick from top-5 results ranked by n-gram similarity
47
+ - Auto-select top match (`[a]` or `--auto`)
48
+ - Enter a name manually (`[m]`)
49
+ - Skip (`[s]`) or quit (`[q]`)
50
+ - Offers to run `pip install -r requirements.txt` after writing
51
+
52
+ ---
53
+
54
+ ## Installation
55
+
56
+ ```bash
57
+ pip install python-auto-req
58
+ ```
59
+
60
+ Or from source:
61
+
62
+ ```bash
63
+ git clone https://github.com/Amit-Roy/python-auto-req
64
+ cd python-auto-req
65
+ pip install -e .
66
+ ```
67
+
68
+ ---
69
+
70
+ ## Usage
71
+
72
+ ```bash
73
+ # Preview what would be added (dry-run, interactive)
74
+ auto-req
75
+
76
+ # Write requirements.txt
77
+ auto-req --dry-run 0
78
+
79
+ # Write requirements.txt, auto-pick top PyPI match for unknowns
80
+ auto-req --dry-run 0 --auto
81
+
82
+ # Scan a specific directory
83
+ auto-req --dir /path/to/project --dry-run 0
84
+ ```
85
+
86
+ Or via Python:
87
+
88
+ ```bash
89
+ python -m auto_req --dry-run 0
90
+ ```
91
+
92
+ ### CLI options
93
+
94
+ | Option | Default | Description |
95
+ |---|---|---|
96
+ | `--dry-run 0\|1` | `1` | `1` = preview only; `0` = write to file |
97
+ | `--auto` | off | Always pick the top PyPI match (no prompts) |
98
+ | `--dir DIR` | `.` | Project root to scan |
99
+ | `--requirements FILE` | `./requirements.txt` | Path to requirements.txt |
100
+
101
+ ---
102
+
103
+ ## Interactive resolution example
104
+
105
+ ```
106
+ Unrecognised module: 'yfinance'
107
+ Searching PyPI for 'yfinance'... 5 result(s).
108
+ Top PyPI matches:
109
+ [1] yfinance (similarity 1.00)
110
+ [2] yfinance-cache (similarity 0.78)
111
+ [3] yfinance-ez (similarity 0.72)
112
+ ...
113
+
114
+ [1-5] select a match above
115
+ [a] auto-select top match for ALL remaining unknowns
116
+ [m] enter the correct dist name manually
117
+ [s] skip (omit from requirements, continue)
118
+ [q] quit (stop resolution now)
119
+
120
+ Your choice: 1
121
+ ```
122
+
123
+ ---
124
+
125
+ ## Development
126
+
127
+ ```bash
128
+ pip install -e ".[dev]"
129
+ pytest
130
+ ```
131
+
132
+ ---
133
+
134
+ ## Publishing to PyPI
135
+
136
+ Publishing is handled automatically by GitHub Actions ([.github/workflows/publish.yml](.github/workflows/publish.yml)) whenever you push a version tag.
137
+
138
+ ### One-time PyPI Trusted Publisher setup
139
+
140
+ 1. Go to <https://pypi.org/manage/account/publishing/>
141
+ 2. Add a **pending publisher** with:
142
+ - **PyPI project name**: `python-auto-req`
143
+ - **GitHub owner**: `Amit-Roy`
144
+ - **Repository name**: `python-auto-req`
145
+ - **Workflow filename**: `publish.yml`
146
+ - **Environment name**: `pypi`
147
+ 3. On GitHub, create a repository **Environment** named `pypi`
148
+ *(Settings → Environments → New environment)*
149
+
150
+ ### Releasing a new version
151
+
152
+ ```bash
153
+ # 1. Bump the version in pyproject.toml (and src/auto_req/__init__.py)
154
+ # 2. Commit and push
155
+ git add pyproject.toml src/auto_req/__init__.py
156
+ git commit -m "chore: release v0.2.0"
157
+ git push
158
+
159
+ # 3. Tag and push – this triggers the publish workflow
160
+ git tag v0.2.0
161
+ git push --tags
162
+ ```
163
+
164
+ The workflow will:
165
+ 1. Run the full test matrix
166
+ 2. Build wheel + sdist
167
+ 3. Verify the tag matches the package version
168
+ 4. Publish to PyPI via OIDC (no API token required)
169
+
170
+ ### Local build (optional)
171
+
172
+ ```bash
173
+ pip install -e ".[dev]"
174
+ python -m build
175
+ ```
176
+
177
+ MIT
@@ -0,0 +1,147 @@
1
+ # python-auto-req
2
+
3
+ Scan your Python project's `.py` and `.ipynb` files, discover every third-party
4
+ package that is actually **imported**, and add them to `requirements.txt`.
5
+
6
+ > **Only packages explicitly referenced in your source files are considered.**
7
+ > Packages installed in `.venv` but never imported are ignored.
8
+
9
+ ---
10
+
11
+ ## Features
12
+
13
+ - Recursively scans `.py` and `.ipynb` files (skips `.venv`, `.git`, `__pycache__`, etc.)
14
+ - Uses the active Python environment to resolve module → distribution name + version
15
+ - Falls back to a **live PyPI search** for unknown modules with an interactive menu:
16
+ - Pick from top-5 results ranked by n-gram similarity
17
+ - Auto-select top match (`[a]` or `--auto`)
18
+ - Enter a name manually (`[m]`)
19
+ - Skip (`[s]`) or quit (`[q]`)
20
+ - Offers to run `pip install -r requirements.txt` after writing
21
+
22
+ ---
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pip install python-auto-req
28
+ ```
29
+
30
+ Or from source:
31
+
32
+ ```bash
33
+ git clone https://github.com/Amit-Roy/python-auto-req
34
+ cd python-auto-req
35
+ pip install -e .
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Usage
41
+
42
+ ```bash
43
+ # Preview what would be added (dry-run, interactive)
44
+ auto-req
45
+
46
+ # Write requirements.txt
47
+ auto-req --dry-run 0
48
+
49
+ # Write requirements.txt, auto-pick top PyPI match for unknowns
50
+ auto-req --dry-run 0 --auto
51
+
52
+ # Scan a specific directory
53
+ auto-req --dir /path/to/project --dry-run 0
54
+ ```
55
+
56
+ Or via Python:
57
+
58
+ ```bash
59
+ python -m auto_req --dry-run 0
60
+ ```
61
+
62
+ ### CLI options
63
+
64
+ | Option | Default | Description |
65
+ |---|---|---|
66
+ | `--dry-run 0\|1` | `1` | `1` = preview only; `0` = write to file |
67
+ | `--auto` | off | Always pick the top PyPI match (no prompts) |
68
+ | `--dir DIR` | `.` | Project root to scan |
69
+ | `--requirements FILE` | `./requirements.txt` | Path to requirements.txt |
70
+
71
+ ---
72
+
73
+ ## Interactive resolution example
74
+
75
+ ```
76
+ Unrecognised module: 'yfinance'
77
+ Searching PyPI for 'yfinance'... 5 result(s).
78
+ Top PyPI matches:
79
+ [1] yfinance (similarity 1.00)
80
+ [2] yfinance-cache (similarity 0.78)
81
+ [3] yfinance-ez (similarity 0.72)
82
+ ...
83
+
84
+ [1-5] select a match above
85
+ [a] auto-select top match for ALL remaining unknowns
86
+ [m] enter the correct dist name manually
87
+ [s] skip (omit from requirements, continue)
88
+ [q] quit (stop resolution now)
89
+
90
+ Your choice: 1
91
+ ```
92
+
93
+ ---
94
+
95
+ ## Development
96
+
97
+ ```bash
98
+ pip install -e ".[dev]"
99
+ pytest
100
+ ```
101
+
102
+ ---
103
+
104
+ ## Publishing to PyPI
105
+
106
+ Publishing is handled automatically by GitHub Actions ([.github/workflows/publish.yml](.github/workflows/publish.yml)) whenever you push a version tag.
107
+
108
+ ### One-time PyPI Trusted Publisher setup
109
+
110
+ 1. Go to <https://pypi.org/manage/account/publishing/>
111
+ 2. Add a **pending publisher** with:
112
+ - **PyPI project name**: `python-auto-req`
113
+ - **GitHub owner**: `Amit-Roy`
114
+ - **Repository name**: `python-auto-req`
115
+ - **Workflow filename**: `publish.yml`
116
+ - **Environment name**: `pypi`
117
+ 3. On GitHub, create a repository **Environment** named `pypi`
118
+ *(Settings → Environments → New environment)*
119
+
120
+ ### Releasing a new version
121
+
122
+ ```bash
123
+ # 1. Bump the version in pyproject.toml (and src/auto_req/__init__.py)
124
+ # 2. Commit and push
125
+ git add pyproject.toml src/auto_req/__init__.py
126
+ git commit -m "chore: release v0.2.0"
127
+ git push
128
+
129
+ # 3. Tag and push – this triggers the publish workflow
130
+ git tag v0.2.0
131
+ git push --tags
132
+ ```
133
+
134
+ The workflow will:
135
+ 1. Run the full test matrix
136
+ 2. Build wheel + sdist
137
+ 3. Verify the tag matches the package version
138
+ 4. Publish to PyPI via OIDC (no API token required)
139
+
140
+ ### Local build (optional)
141
+
142
+ ```bash
143
+ pip install -e ".[dev]"
144
+ python -m build
145
+ ```
146
+
147
+ MIT
@@ -0,0 +1,50 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "python-auto-req"
7
+ version = "0.1.0"
8
+ description = "Scan project source files and populate requirements.txt – with PyPI search and interactive resolution."
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ authors = [{ name = "Amit Roy", email = "a.roy.0593@gmail.com" }]
12
+ requires-python = ">=3.10"
13
+ keywords = ["requirements", "dependencies", "pypi", "scanner"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Environment :: Console",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Topic :: Software Development :: Libraries :: Python Modules",
25
+ "Topic :: Utilities",
26
+ ]
27
+ # No runtime dependencies – only stdlib is used.
28
+ dependencies = []
29
+
30
+ [project.optional-dependencies]
31
+ dev = ["pytest", "build", "hatchling", "twine"]
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/Amit-Roy/python-auto-req"
35
+ Repository = "https://github.com/Amit-Roy/python-auto-req"
36
+ Issues = "https://github.com/Amit-Roy/python-auto-req/issues"
37
+
38
+ [project.scripts]
39
+ auto-req = "auto_req.cli:main"
40
+
41
+ [tool.hatch.build.targets.wheel]
42
+ packages = ["src/auto_req"]
43
+
44
+ [tool.pytest.ini_options]
45
+ testpaths = ["tests"]
46
+ addopts = "-v"
47
+
48
+ [tool.ruff]
49
+ line-length = 100
50
+ target-version = "py310"
@@ -0,0 +1,16 @@
1
+ """python-auto-req – scan project files and populate requirements.txt."""
2
+
3
+ from .scanner import collect_imports, imports_from_source, imports_from_notebook, stdlib_module_names
4
+ from .resolver import resolve_all, resolve_from_env, search_pypi, ngram_score
5
+
6
+ __version__ = "0.1.0"
7
+ __all__ = [
8
+ "collect_imports",
9
+ "imports_from_source",
10
+ "imports_from_notebook",
11
+ "stdlib_module_names",
12
+ "resolve_all",
13
+ "resolve_from_env",
14
+ "search_pypi",
15
+ "ngram_score",
16
+ ]
@@ -0,0 +1,5 @@
1
+ """Allow running as: python -m auto_req"""
2
+ from .cli import main
3
+ import sys
4
+
5
+ sys.exit(main())