pypistale 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.
- pypistale-0.1.0/.github/workflows/ci.yml +16 -0
- pypistale-0.1.0/.gitignore +19 -0
- pypistale-0.1.0/LICENSE +21 -0
- pypistale-0.1.0/PKG-INFO +141 -0
- pypistale-0.1.0/README.md +116 -0
- pypistale-0.1.0/pypistale/__init__.py +0 -0
- pypistale-0.1.0/pypistale/__main__.py +4 -0
- pypistale-0.1.0/pypistale/checker.py +70 -0
- pypistale-0.1.0/pypistale/cli.py +18 -0
- pypistale-0.1.0/pypistale/display.py +20 -0
- pypistale-0.1.0/pypistale/parsers.py +182 -0
- pypistale-0.1.0/pypistale/utils.py +29 -0
- pypistale-0.1.0/pyproject.toml +45 -0
- pypistale-0.1.0/tests/test_checker.py +88 -0
- pypistale-0.1.0/tests/test_display.py +17 -0
- pypistale-0.1.0/tests/test_get_dependency_files.py +87 -0
- pypistale-0.1.0/tests/test_parsers.py +214 -0
- pypistale-0.1.0/uv.lock +499 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: astral-sh/setup-uv@v5
|
|
15
|
+
- run: uv sync --dev
|
|
16
|
+
- run: uv run pytest tests/
|
pypistale-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Eemi Mäntylä
|
|
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.
|
pypistale-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pypistale
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A CLI tool that checks how recently your project's dependencies were last updated on PyPI.
|
|
5
|
+
Project-URL: Repository, https://github.com/eemim/pypistale
|
|
6
|
+
Project-URL: Issues, https://github.com/eemim/pypistale/issues
|
|
7
|
+
Author-email: eemim <eemim@protonmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Requires-Python: >=3.8
|
|
20
|
+
Requires-Dist: click>=8.0.0
|
|
21
|
+
Requires-Dist: httpx>=0.23.0
|
|
22
|
+
Requires-Dist: packaging>=21.0
|
|
23
|
+
Requires-Dist: tomli>=2.0.0; python_version < '3.11'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# PyPIstale
|
|
27
|
+
|
|
28
|
+
## INTRODUCTION
|
|
29
|
+
|
|
30
|
+
Dependency management is a key part of any software project, ensuring you stay up to date with secure and supported packages. Deprecating (and sometimes undeprecating) gives providers control over the lifecycle of their packages and versions. The **npm registry** makes this process clear by allowing creators to flag unmaintained packages and warning developers when they’re about to install deprecated ones.
|
|
31
|
+
|
|
32
|
+
But what about the **Python Package Index**? Yes, it’s possible — but digging into forum threads on this topic shows that it requires a LOT of work from the maintainer.
|
|
33
|
+
|
|
34
|
+
And sure, you can use commands like `pip list --outdated`, but that only tells you the latest version. It won’t tell you if the package hasn’t been updated in six years.
|
|
35
|
+
|
|
36
|
+
Do you really want to be ***dependable*** (pun totally intended) on another coder's motivation to go through all that hassle just for some old project?
|
|
37
|
+
|
|
38
|
+
If not...
|
|
39
|
+
|
|
40
|
+
Enter the **PyPIstale** !
|
|
41
|
+
|
|
42
|
+
## WHAT DOES IT DO?
|
|
43
|
+
|
|
44
|
+
- Searches your project for a dependency file whether that's a `requirements.txt`,`requirements-dev.txt`, `pyproject.toml`, `Pipfile`, `setup.cfg` or a `uv/poetry.lock` file for full transitive dependency inspection. Dev dependencies are included by default.
|
|
45
|
+
|
|
46
|
+
> **pyproject.toml support:**
|
|
47
|
+
>
|
|
48
|
+
> PEP 621 (`[project.dependencies]`, `[project.optional-dependencies]`)
|
|
49
|
+
>
|
|
50
|
+
> PEP 735 (`[dependency-groups]`)
|
|
51
|
+
>
|
|
52
|
+
> Poetry (`[tool.poetry.dependencies]`, `[tool.poetry.dev-dependencies]`, `[tool.poetry.group.X.dependencies]`)
|
|
53
|
+
|
|
54
|
+
- Scans the dependencies and looks them up on **PyPI**
|
|
55
|
+
- Shows your project’s dependency version, the latest **PyPI** version, and ***clearly indicates how long it’s been since the package was last updated on PyPI***
|
|
56
|
+
- Comes with a clear color coding for an engaging UX/UI experience!
|
|
57
|
+
|
|
58
|
+
> **Color coding:** Green = updated within the last year, Yellow = 1–3 years, Red = 3+ years without an update.
|
|
59
|
+
>
|
|
60
|
+
> A red package is not necessarily bad, it just hasn't been updated recently. Some packages are stable and simply don't need updates. Use your own judgement.
|
|
61
|
+
|
|
62
|
+
## INSTALLATION
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install pypistale
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## HOW TO USE?
|
|
69
|
+
|
|
70
|
+
Run the tool in your project directory:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pypistale
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### FLAGS
|
|
77
|
+
|
|
78
|
+
| Flag | Description |
|
|
79
|
+
|----------------|--------------------------------------------------------------------------------------------------------------|
|
|
80
|
+
| `--transitive` | Use the project's `.lock` file to include transitive dependencies (deps of deps) instead of just direct ones |
|
|
81
|
+
| `--json` | Output results as JSON instead of the default terminal output |
|
|
82
|
+
|
|
83
|
+
### EXAMPLES
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
# Check direct dependencies
|
|
87
|
+
pypistale
|
|
88
|
+
|
|
89
|
+
# Check all dependencies including transitive
|
|
90
|
+
pypistale --transitive
|
|
91
|
+
|
|
92
|
+
# Output results as JSON
|
|
93
|
+
pypistale --json
|
|
94
|
+
|
|
95
|
+
# Combine flags
|
|
96
|
+
pypistale --transitive --json
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### Example output
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
click
|
|
103
|
+
• Latest PyPI version: 8.4.1
|
|
104
|
+
• Project dependency: 8.0.0
|
|
105
|
+
• Last updated in PyPI: 13 days ago
|
|
106
|
+
|
|
107
|
+
packaging
|
|
108
|
+
• Latest PyPI version: 26.2
|
|
109
|
+
• Project dependency: 21.0
|
|
110
|
+
• Last updated in PyPI: 40 days ago
|
|
111
|
+
|
|
112
|
+
tomli
|
|
113
|
+
• Latest PyPI version: 2.4.1
|
|
114
|
+
• Project dependency: 2.0.0
|
|
115
|
+
• Last updated in PyPI: 70 days ago
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Example output `--json`
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
[
|
|
122
|
+
{
|
|
123
|
+
"name": "click",
|
|
124
|
+
"latest_pypi_version": "8.4.1",
|
|
125
|
+
"project_version": ">=8.0.0",
|
|
126
|
+
"days_since_pypi_update": 13
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
"name": "packaging",
|
|
130
|
+
"latest_pypi_version": "26.2",
|
|
131
|
+
"project_version": ">=21.0",
|
|
132
|
+
"days_since_pypi_update": 40
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"name": "tomli",
|
|
136
|
+
"latest_pypi_version": "2.4.1",
|
|
137
|
+
"project_version": ">=2.0.0",
|
|
138
|
+
"days_since_pypi_update": 70
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
```
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# PyPIstale
|
|
2
|
+
|
|
3
|
+
## INTRODUCTION
|
|
4
|
+
|
|
5
|
+
Dependency management is a key part of any software project, ensuring you stay up to date with secure and supported packages. Deprecating (and sometimes undeprecating) gives providers control over the lifecycle of their packages and versions. The **npm registry** makes this process clear by allowing creators to flag unmaintained packages and warning developers when they’re about to install deprecated ones.
|
|
6
|
+
|
|
7
|
+
But what about the **Python Package Index**? Yes, it’s possible — but digging into forum threads on this topic shows that it requires a LOT of work from the maintainer.
|
|
8
|
+
|
|
9
|
+
And sure, you can use commands like `pip list --outdated`, but that only tells you the latest version. It won’t tell you if the package hasn’t been updated in six years.
|
|
10
|
+
|
|
11
|
+
Do you really want to be ***dependable*** (pun totally intended) on another coder's motivation to go through all that hassle just for some old project?
|
|
12
|
+
|
|
13
|
+
If not...
|
|
14
|
+
|
|
15
|
+
Enter the **PyPIstale** !
|
|
16
|
+
|
|
17
|
+
## WHAT DOES IT DO?
|
|
18
|
+
|
|
19
|
+
- Searches your project for a dependency file whether that's a `requirements.txt`,`requirements-dev.txt`, `pyproject.toml`, `Pipfile`, `setup.cfg` or a `uv/poetry.lock` file for full transitive dependency inspection. Dev dependencies are included by default.
|
|
20
|
+
|
|
21
|
+
> **pyproject.toml support:**
|
|
22
|
+
>
|
|
23
|
+
> PEP 621 (`[project.dependencies]`, `[project.optional-dependencies]`)
|
|
24
|
+
>
|
|
25
|
+
> PEP 735 (`[dependency-groups]`)
|
|
26
|
+
>
|
|
27
|
+
> Poetry (`[tool.poetry.dependencies]`, `[tool.poetry.dev-dependencies]`, `[tool.poetry.group.X.dependencies]`)
|
|
28
|
+
|
|
29
|
+
- Scans the dependencies and looks them up on **PyPI**
|
|
30
|
+
- Shows your project’s dependency version, the latest **PyPI** version, and ***clearly indicates how long it’s been since the package was last updated on PyPI***
|
|
31
|
+
- Comes with a clear color coding for an engaging UX/UI experience!
|
|
32
|
+
|
|
33
|
+
> **Color coding:** Green = updated within the last year, Yellow = 1–3 years, Red = 3+ years without an update.
|
|
34
|
+
>
|
|
35
|
+
> A red package is not necessarily bad, it just hasn't been updated recently. Some packages are stable and simply don't need updates. Use your own judgement.
|
|
36
|
+
|
|
37
|
+
## INSTALLATION
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install pypistale
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## HOW TO USE?
|
|
44
|
+
|
|
45
|
+
Run the tool in your project directory:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pypistale
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### FLAGS
|
|
52
|
+
|
|
53
|
+
| Flag | Description |
|
|
54
|
+
|----------------|--------------------------------------------------------------------------------------------------------------|
|
|
55
|
+
| `--transitive` | Use the project's `.lock` file to include transitive dependencies (deps of deps) instead of just direct ones |
|
|
56
|
+
| `--json` | Output results as JSON instead of the default terminal output |
|
|
57
|
+
|
|
58
|
+
### EXAMPLES
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Check direct dependencies
|
|
62
|
+
pypistale
|
|
63
|
+
|
|
64
|
+
# Check all dependencies including transitive
|
|
65
|
+
pypistale --transitive
|
|
66
|
+
|
|
67
|
+
# Output results as JSON
|
|
68
|
+
pypistale --json
|
|
69
|
+
|
|
70
|
+
# Combine flags
|
|
71
|
+
pypistale --transitive --json
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### Example output
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
click
|
|
78
|
+
• Latest PyPI version: 8.4.1
|
|
79
|
+
• Project dependency: 8.0.0
|
|
80
|
+
• Last updated in PyPI: 13 days ago
|
|
81
|
+
|
|
82
|
+
packaging
|
|
83
|
+
• Latest PyPI version: 26.2
|
|
84
|
+
• Project dependency: 21.0
|
|
85
|
+
• Last updated in PyPI: 40 days ago
|
|
86
|
+
|
|
87
|
+
tomli
|
|
88
|
+
• Latest PyPI version: 2.4.1
|
|
89
|
+
• Project dependency: 2.0.0
|
|
90
|
+
• Last updated in PyPI: 70 days ago
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
#### Example output `--json`
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
[
|
|
97
|
+
{
|
|
98
|
+
"name": "click",
|
|
99
|
+
"latest_pypi_version": "8.4.1",
|
|
100
|
+
"project_version": ">=8.0.0",
|
|
101
|
+
"days_since_pypi_update": 13
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"name": "packaging",
|
|
105
|
+
"latest_pypi_version": "26.2",
|
|
106
|
+
"project_version": ">=21.0",
|
|
107
|
+
"days_since_pypi_update": 40
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"name": "tomli",
|
|
111
|
+
"latest_pypi_version": "2.4.1",
|
|
112
|
+
"project_version": ">=2.0.0",
|
|
113
|
+
"days_since_pypi_update": 70
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
```
|
|
File without changes
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import httpx
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from packaging.version import parse
|
|
6
|
+
|
|
7
|
+
from .parsers import get_dependency_file
|
|
8
|
+
from .display import print_package_info
|
|
9
|
+
from .utils import days_since
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
async def fetch_newest_release(package: str, client: httpx.AsyncClient) -> dict | None:
|
|
13
|
+
try:
|
|
14
|
+
res = await client.get(
|
|
15
|
+
url=f"https://pypi.org/pypi/{package}/json",
|
|
16
|
+
headers={"Accept": "application/json"},
|
|
17
|
+
)
|
|
18
|
+
data = res.json()
|
|
19
|
+
|
|
20
|
+
# Handle KeyError for not found packages
|
|
21
|
+
if "releases" not in data or not data["releases"]:
|
|
22
|
+
print(f"\nNo PyPi releases found for: {package}", file=sys.stderr)
|
|
23
|
+
return None
|
|
24
|
+
|
|
25
|
+
releases = data["releases"]
|
|
26
|
+
|
|
27
|
+
# Sort versions, newest first
|
|
28
|
+
versions = sorted(releases.keys(), key=parse, reverse=True)
|
|
29
|
+
|
|
30
|
+
# Handle empty release and return latest release according to (version)number
|
|
31
|
+
for version in versions:
|
|
32
|
+
if releases[version]:
|
|
33
|
+
last_release_data = releases[version][-1]
|
|
34
|
+
return dict(release=version, date=last_release_data["upload_time"])
|
|
35
|
+
|
|
36
|
+
print(f"\nNo valid release files found for package: {package}", file=sys.stderr)
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
# Handle errors outside previous checks
|
|
40
|
+
except (KeyError, IndexError, httpx.HTTPError) as e:
|
|
41
|
+
print(f"\nFailed to fetch release for '{package}': {e}", file=sys.stderr)
|
|
42
|
+
return None
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async def run_check(transitive: bool = False, json_output: bool = False):
|
|
46
|
+
deps = get_dependency_file(transitive=transitive)
|
|
47
|
+
|
|
48
|
+
async with httpx.AsyncClient() as client:
|
|
49
|
+
results = await asyncio.gather(
|
|
50
|
+
*[fetch_newest_release(name, client) for name in deps]
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
output = []
|
|
54
|
+
|
|
55
|
+
for (name, project_version), new_version in zip(deps.items(), results):
|
|
56
|
+
if new_version:
|
|
57
|
+
days = days_since(new_version["date"])
|
|
58
|
+
if json_output:
|
|
59
|
+
output.append(
|
|
60
|
+
{
|
|
61
|
+
"name": name,
|
|
62
|
+
"latest_pypi_version": new_version["release"],
|
|
63
|
+
"project_version": project_version,
|
|
64
|
+
"days_since_pypi_update": days,
|
|
65
|
+
}
|
|
66
|
+
)
|
|
67
|
+
else:
|
|
68
|
+
print_package_info(name, new_version, project_version, days)
|
|
69
|
+
|
|
70
|
+
return output if json_output else None
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import click
|
|
3
|
+
import json
|
|
4
|
+
|
|
5
|
+
from .checker import run_check
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@click.command()
|
|
9
|
+
@click.option(
|
|
10
|
+
"--transitive", is_flag=True, help="Include transitive dependencies from lock files"
|
|
11
|
+
)
|
|
12
|
+
@click.option(
|
|
13
|
+
"--json", "json_output", is_flag=True, help="Output results in JSON format"
|
|
14
|
+
)
|
|
15
|
+
def main(transitive: bool, json_output: bool):
|
|
16
|
+
result = asyncio.run(run_check(transitive=transitive, json_output=json_output))
|
|
17
|
+
if json_output and result:
|
|
18
|
+
click.echo(json.dumps(result, indent=2))
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
|
|
3
|
+
from .utils import format_specifier, severity_for_days
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def print_package_info(name: str, new_version: str, project_version: str, days: int):
|
|
7
|
+
if not sys.stdout.isatty():
|
|
8
|
+
print(
|
|
9
|
+
f"{name}: {project_version} -> {new_version['release']} (updated in PyPI {days} days ago)"
|
|
10
|
+
)
|
|
11
|
+
return
|
|
12
|
+
|
|
13
|
+
bullet, color, reset = severity_for_days(days)
|
|
14
|
+
print(
|
|
15
|
+
f"\n{color}{name}\n"
|
|
16
|
+
f"{bullet} Latest PyPI version: {new_version['release']}\n"
|
|
17
|
+
f"{bullet} Project dependency: {format_specifier(project_version)}\n"
|
|
18
|
+
f"{bullet} Last updated in PyPI: {days} days ago"
|
|
19
|
+
f"{reset}"
|
|
20
|
+
)
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from configparser import ConfigParser
|
|
5
|
+
from packaging.requirements import Requirement
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
import tomllib # Python 3.11+
|
|
9
|
+
|
|
10
|
+
def load_toml(file):
|
|
11
|
+
return tomllib.load(file)
|
|
12
|
+
|
|
13
|
+
except ImportError:
|
|
14
|
+
import tomli as tomllib
|
|
15
|
+
|
|
16
|
+
def load_toml(file):
|
|
17
|
+
return tomllib.load(file)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Handle requirements.txt file
|
|
21
|
+
def parse_requirement(dependency_file: str) -> dict[str, str]:
|
|
22
|
+
packages = {}
|
|
23
|
+
with open(dependency_file, "r") as file:
|
|
24
|
+
lines = file.readlines()
|
|
25
|
+
|
|
26
|
+
for line in lines:
|
|
27
|
+
if line.strip() and not line.strip().startswith("#"):
|
|
28
|
+
req = _parse_requirement_line(line)
|
|
29
|
+
if req:
|
|
30
|
+
name, specifier = req
|
|
31
|
+
packages[name] = specifier
|
|
32
|
+
return packages
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# Handle .lock files
|
|
36
|
+
# Works for both Poetry and uv.lock files since they have the same format for package entries
|
|
37
|
+
def parse_lockfile(dependency_file: str) -> dict[str, str]:
|
|
38
|
+
packages = {}
|
|
39
|
+
with open(dependency_file, "r") as file:
|
|
40
|
+
lines = file.readlines()
|
|
41
|
+
|
|
42
|
+
i = 0
|
|
43
|
+
while i < len(lines):
|
|
44
|
+
if lines[i].strip() == "[[package]]":
|
|
45
|
+
name = version = None
|
|
46
|
+
j = i + 1
|
|
47
|
+
while j < len(lines) and lines[j].strip() != "[[package]]":
|
|
48
|
+
if lines[j].strip().startswith("name ="):
|
|
49
|
+
name = lines[j].split("=", 1)[1].strip().strip('"')
|
|
50
|
+
elif lines[j].strip().startswith("version ="):
|
|
51
|
+
version = lines[j].split("=", 1)[1].strip().strip('"')
|
|
52
|
+
j += 1
|
|
53
|
+
if name and version:
|
|
54
|
+
packages[name] = version
|
|
55
|
+
i = j
|
|
56
|
+
else:
|
|
57
|
+
i += 1
|
|
58
|
+
return packages
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# Handle pyproject.toml file
|
|
62
|
+
def parse_tomlfile(dependency_file: str) -> dict[str, str]:
|
|
63
|
+
with open(dependency_file, "rb") as file:
|
|
64
|
+
data = load_toml(file)
|
|
65
|
+
|
|
66
|
+
packages = {}
|
|
67
|
+
|
|
68
|
+
# PEP 621 [project.dependencies]
|
|
69
|
+
_parse_dep_list(data.get("project", {}).get("dependencies", []), packages)
|
|
70
|
+
|
|
71
|
+
# PEP 621 [project.optional-dependencies] - all groups including dev
|
|
72
|
+
for group_deps in data.get("project", {}).get("optional-dependencies", {}).values():
|
|
73
|
+
_parse_dep_list(group_deps, packages)
|
|
74
|
+
|
|
75
|
+
# PEP 735 [dependency-groups] - uv and newer tools
|
|
76
|
+
for group_deps in data.get("dependency-groups", {}).values():
|
|
77
|
+
_parse_dep_list(group_deps, packages)
|
|
78
|
+
|
|
79
|
+
# Poetry [tool.poetry.dependencies] and [tool.poetry.dev-dependencies]
|
|
80
|
+
poetry = data.get("tool", {}).get("poetry", {})
|
|
81
|
+
for section in ["dependencies", "dev-dependencies"]:
|
|
82
|
+
packages.update(poetry.get(section, {}))
|
|
83
|
+
|
|
84
|
+
# Poetry newer group format [tool.poetry.group.X.dependencies]
|
|
85
|
+
for group in poetry.get("group", {}).values():
|
|
86
|
+
packages.update(group.get("dependencies", {}))
|
|
87
|
+
|
|
88
|
+
return packages
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# Handle Pipfile file
|
|
92
|
+
def parse_pipfile(dependency_file: str) -> dict[str, str]:
|
|
93
|
+
with open(dependency_file, "rb") as file:
|
|
94
|
+
data = load_toml(file)
|
|
95
|
+
|
|
96
|
+
packages = {}
|
|
97
|
+
for section in ["packages", "dev-packages"]:
|
|
98
|
+
if section in data:
|
|
99
|
+
packages.update(data[section])
|
|
100
|
+
return packages
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
# Handle setup.cfg file
|
|
104
|
+
def parse_setupcfg(dependency_file: str) -> dict[str, str]:
|
|
105
|
+
|
|
106
|
+
config = ConfigParser()
|
|
107
|
+
config.read(dependency_file)
|
|
108
|
+
|
|
109
|
+
packages = {}
|
|
110
|
+
if "options" in config and "install_requires" in config["options"]:
|
|
111
|
+
for line in config["options"]["install_requires"].splitlines():
|
|
112
|
+
if line.strip():
|
|
113
|
+
req = _parse_requirement_line(line)
|
|
114
|
+
if req:
|
|
115
|
+
name, specifier = req
|
|
116
|
+
packages[name] = specifier
|
|
117
|
+
return packages
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
# --transitive not set, so we only parse direct dependencies from the main files
|
|
121
|
+
# We check for pyproject.toml first, then Pipfile, then setup.cfg, and finally requirements.txt
|
|
122
|
+
DIRECT_PARSERS: dict[str, Callable] = {
|
|
123
|
+
"pyproject.toml": parse_tomlfile,
|
|
124
|
+
"Pipfile": parse_pipfile,
|
|
125
|
+
"setup.cfg": parse_setupcfg,
|
|
126
|
+
"requirements.txt": parse_requirement,
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
# --transitive set, so we also parse transitive dependencies from lock files
|
|
130
|
+
TRANSITIVE_PARSERS: dict[str, Callable] = {
|
|
131
|
+
"*.lock": parse_lockfile,
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
# Get dependency file and handle it appropriately
|
|
136
|
+
def get_dependency_file(transitive: bool = False) -> dict[str, str]:
|
|
137
|
+
if transitive:
|
|
138
|
+
for pattern, parser in TRANSITIVE_PARSERS.items():
|
|
139
|
+
matches = list(Path(".").glob(pattern))
|
|
140
|
+
if matches:
|
|
141
|
+
return parser(str(matches[0]))
|
|
142
|
+
raise FileNotFoundError("No lock file found.")
|
|
143
|
+
|
|
144
|
+
# For direct deps, check for pyproject.toml/Pipfile/setup.cfg first
|
|
145
|
+
for pattern, parser in DIRECT_PARSERS.items():
|
|
146
|
+
if pattern.startswith("requirements"):
|
|
147
|
+
continue
|
|
148
|
+
matches = list(Path(".").glob(pattern))
|
|
149
|
+
if matches:
|
|
150
|
+
result = parser(str(matches[0]))
|
|
151
|
+
if result: # only return if actually found dependencies
|
|
152
|
+
return result
|
|
153
|
+
|
|
154
|
+
# Fall back to requirements files, merging all of them (requirements.txt + requirements-dev.txt)
|
|
155
|
+
packages = {}
|
|
156
|
+
for pattern in ["requirements*.txt"]:
|
|
157
|
+
for match in Path(".").glob(pattern):
|
|
158
|
+
packages.update(parse_requirement(str(match)))
|
|
159
|
+
if packages:
|
|
160
|
+
return packages
|
|
161
|
+
|
|
162
|
+
raise FileNotFoundError("No supported dependency file found.")
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _parse_requirement_line(line: str) -> tuple[str, str] | None:
|
|
166
|
+
try:
|
|
167
|
+
req = Requirement(line.strip())
|
|
168
|
+
name = req.name
|
|
169
|
+
specifier = str(req.specifier) if req.specifier else ""
|
|
170
|
+
return name, specifier
|
|
171
|
+
except Exception as e:
|
|
172
|
+
print(f"Failed to parse line '{line.strip()}': {e}", file=sys.stderr)
|
|
173
|
+
return None
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _parse_dep_list(deps: list, packages: dict) -> None:
|
|
177
|
+
for dep in deps:
|
|
178
|
+
if isinstance(dep, str): # skip PEP 735 dicts like {include-group = "typing"}
|
|
179
|
+
req = _parse_requirement_line(dep)
|
|
180
|
+
if req:
|
|
181
|
+
name, specifier = req
|
|
182
|
+
packages[name] = specifier
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
POSITIVE = ("\U00002022", "\033[0;32m", "\033[0m")
|
|
6
|
+
NEUTRAL = ("\U00002022", "\033[0;33m", "\033[0m")
|
|
7
|
+
NEGATIVE = ("\U00002022", "\033[0;31m", "\033[0m")
|
|
8
|
+
|
|
9
|
+
ITALIC = "\033[3m"
|
|
10
|
+
RESET_ITALIC = "\033[23m"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def severity_for_days(result: int):
|
|
14
|
+
if result <= 365:
|
|
15
|
+
return POSITIVE
|
|
16
|
+
elif result <= 1095:
|
|
17
|
+
return NEUTRAL
|
|
18
|
+
return NEGATIVE
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def format_specifier(specifier: str) -> str:
|
|
22
|
+
"""Display specifier in a more user-friendly way, removing operators and formatting unpinned dependencies."""
|
|
23
|
+
if not specifier:
|
|
24
|
+
return f"{ITALIC}unpinned{RESET_ITALIC}"
|
|
25
|
+
return re.sub(r"^[=<>!~^]+", "", specifier).strip()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def days_since(date: str) -> int:
|
|
29
|
+
return (datetime.now() - datetime.fromisoformat(date)).days
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
authors = [{ name = "eemim", email = "eemim@protonmail.com" }]
|
|
3
|
+
name = "pypistale"
|
|
4
|
+
license = {text = "MIT"}
|
|
5
|
+
version = "0.1.0"
|
|
6
|
+
description = "A CLI tool that checks how recently your project's dependencies were last updated on PyPI."
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
requires-python = ">=3.8"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"click>=8.0.0",
|
|
11
|
+
"httpx>=0.23.0",
|
|
12
|
+
"packaging>=21.0",
|
|
13
|
+
'tomli>=2.0.0; python_version < "3.11"',
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.8",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
24
|
+
"Environment :: Console",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Repository = "https://github.com/eemim/pypistale"
|
|
29
|
+
Issues = "https://github.com/eemim/pypistale/issues"
|
|
30
|
+
|
|
31
|
+
[project.scripts]
|
|
32
|
+
pypistale = "pypistale.cli:main"
|
|
33
|
+
|
|
34
|
+
[build-system]
|
|
35
|
+
requires = ["hatchling"]
|
|
36
|
+
build-backend = "hatchling.build"
|
|
37
|
+
|
|
38
|
+
[tool.hatch.build.targets.wheel]
|
|
39
|
+
packages = ["pypistale"]
|
|
40
|
+
|
|
41
|
+
[dependency-groups]
|
|
42
|
+
dev = [
|
|
43
|
+
"pytest>=8.3.5",
|
|
44
|
+
"pytest-asyncio>=0.24.0",
|
|
45
|
+
]
|