-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
print-pkg-names.py
35 lines (26 loc) · 952 Bytes
/
print-pkg-names.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import pathlib
import sys
from packaging import utils
def debug(msg: str):
print(f'::debug::{msg.title()}', file=sys.stderr)
def safe_parse_pkg_name(file_path: pathlib.Path) -> str | None:
if file_path.suffix == '.whl':
try:
return utils.parse_wheel_filename(file_path.name)[0]
except utils.InvalidWheelFilename:
debug(f'Invalid wheel filename: {file_path.name}')
return None
elif file_path.suffix == '.gz':
try:
return utils.parse_sdist_filename(file_path.name)[0]
except utils.InvalidSdistFilename:
debug(f'Invalid sdist filename: {file_path.name}')
return None
return None
packages_dir = pathlib.Path(sys.argv[1]).resolve()
pkg_names = {
pkg_name for file_path in packages_dir.iterdir() if
(pkg_name := safe_parse_pkg_name(file_path)) is not None
}
for package_name in sorted(pkg_names):
print(package_name)