Skip to content

Commit 9c56374

Browse files
committed
Streamline settings and update tests
Also bump version Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 1dcd761 commit 9c56374

File tree

8 files changed

+707
-45
lines changed

8 files changed

+707
-45
lines changed

src/python_inspector/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from _packagedcode.pypi import can_process_dependent_package
3030
from _packagedcode.pypi import get_resolved_purl
3131
from python_inspector import dependencies
32-
from python_inspector import pyinspector_settings as settings
32+
from python_inspector import pyinspector_settings
3333
from python_inspector import utils
3434
from python_inspector import utils_pypi
3535
from python_inspector.package_data import get_pypi_data_from_purl
@@ -82,7 +82,7 @@ def resolve_dependencies(
8282
specifiers=tuple(),
8383
python_version=None,
8484
operating_system=None,
85-
index_urls: tuple[str, ...] = settings.INDEX_URL,
85+
index_urls: tuple[str, ...] = pyinspector_settings.INDEX_URL,
8686
pdt_output=None,
8787
netrc_file=None,
8888
max_rounds=200000,
@@ -251,10 +251,10 @@ def resolve_dependencies(
251251
repos_by_url = {}
252252
if not use_pypi_json_api:
253253
# Collect PyPI repos
254-
use_only_confed = settings.USE_ONLY_CONFIGURED_INDEX_URLS
254+
use_only_confed = pyinspector_settings.USE_ONLY_CONFIGURED_INDEX_URLS
255255
for index_url in index_urls:
256256
index_url = index_url.strip("/")
257-
if use_only_confed and index_url not in settings.INDEX_URL:
257+
if use_only_confed and index_url not in pyinspector_settings.INDEX_URL:
258258
if verbose:
259259
printer(f"Skipping index URL unknown in settings: {index_url!r}")
260260
continue

src/python_inspector/resolve_cli.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@
1313

1414
import click
1515

16-
from python_inspector import pyinspector_settings as settings
16+
from python_inspector import settings
1717
from python_inspector import utils_pypi
1818
from python_inspector.cli_utils import FileOptionType
1919
from python_inspector.utils import write_output_in_file
2020

2121
TRACE = False
2222

23-
__version__ = "0.13.0"
23+
__version__ = "0.14.0"
2424

2525
DEFAULT_PYTHON_VERSION = settings.DEFAULT_PYTHON_VERSION
26+
PYPI_SIMPLE_URL = settings.PYPI_SIMPLE_URL
2627

2728

2829
def print_version(ctx, param, value):
@@ -71,7 +72,6 @@ def print_version(ctx, param, value):
7172
"python_version",
7273
type=click.Choice(utils_pypi.valid_python_versions),
7374
metavar="PYVER",
74-
default=settings.DEFAULT_PYTHON_VERSION,
7575
show_default=True,
7676
required=True,
7777
help="Python version to use for dependency resolution. One of "
@@ -83,19 +83,18 @@ def print_version(ctx, param, value):
8383
"operating_system",
8484
type=click.Choice(utils_pypi.PLATFORMS_BY_OS),
8585
metavar="OS",
86-
default=settings.DEFAULT_OS,
8786
show_default=True,
8887
required=True,
8988
help="OS to use for dependency resolution. One of " + ", ".join(utils_pypi.PLATFORMS_BY_OS),
9089
)
9190
@click.option(
9291
"--index-url",
9392
"index_urls",
94-
envvar="PYINSP_INDEX_URL",
9593
type=str,
9694
metavar="INDEX",
9795
show_default=True,
98-
default=tuple(settings.INDEX_URL),
96+
# since multiple is True, this is a sequence
97+
default=[settings.PYPI_SIMPLE_URL],
9998
multiple=True,
10099
help="PyPI simple index URL(s) to use in order of preference. "
101100
"This option can be used multiple times.",
@@ -123,7 +122,6 @@ def print_version(ctx, param, value):
123122
"--netrc",
124123
"netrc_file",
125124
type=click.Path(exists=True, readable=True, path_type=str, dir_okay=False),
126-
envvar="PYINSP_NETRC_FILE",
127125
metavar="NETRC-FILE",
128126
hidden=True,
129127
required=False,
@@ -165,7 +163,6 @@ def print_version(ctx, param, value):
165163
)
166164
@click.option(
167165
"--verbose",
168-
envvar="PYINSP_VERBOSE",
169166
is_flag=True,
170167
help="Enable verbose debug output.",
171168
)

src/python_inspector/settings.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
from pydantic_settings import BaseSettings
1414
from pydantic_settings import SettingsConfigDict
1515

16+
DEFAULT_PYTHON_VERSION = "39"
17+
PYPI_SIMPLE_URL = "https://pypi.org/simple"
18+
1619

1720
class Settings(BaseSettings):
1821
"""
@@ -27,28 +30,30 @@ class Settings(BaseSettings):
2730
env_prefix="PYINSP_",
2831
case_sensitive=True,
2932
extra="allow",
33+
# never treat data as JSON
34+
enable_decoding=False,
3035
)
3136

3237
# the default Python version to use if none is provided
33-
DEFAULT_PYTHON_VERSION: str = "39"
38+
DEFAULT_PYTHON_VERSION: str = DEFAULT_PYTHON_VERSION
3439

3540
# the default OS to use if none is provided
3641
DEFAULT_OS: str = "linux"
3742

38-
# a list of PyPI simple index URLs. Use a JSON array to represent multiple URLs
39-
INDEX_URL: tuple[str, ...] = ("https://pypi.org/simple",)
43+
# a string with a tuple of PyPI simple index URLs, each separated by a space
44+
INDEX_URL: tuple[str, ...] = (PYPI_SIMPLE_URL,)
4045

4146
# If True, only uses configured INDEX_URLs listed above and ignore other URLs found in requirements
4247
USE_ONLY_CONFIGURED_INDEX_URLS: bool = False
4348

4449
# a path string where to store the cached downloads. Will be created if it does not exists.
4550
CACHE_THIRDPARTY_DIR: str = str(Path(Path.home() / ".cache/python_inspector"))
4651

47-
@field_validator("INDEX_URL")
52+
@field_validator("INDEX_URL", mode="before")
4853
@classmethod
4954
def validate_index_url(cls, value):
5055
if isinstance(value, str):
51-
return (value,)
56+
return tuple(value.split())
5257
elif isinstance(value, (tuple, list)):
5358
return tuple(value)
5459
else:

tests/data/pinned-pdt-requirements.txt-expected.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"headers": {
33
"tool_name": "python-inspector",
44
"tool_homepageurl": "https://github.com/aboutcode-org/python-inspector",
5-
"tool_version": "0.13.0",
65
"options": [
76
"--index-url https://pypi.org/simple",
87
"--json-pdt <file>",

tests/data/pinned-requirements.txt-expected.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"headers": {
33
"tool_name": "python-inspector",
44
"tool_homepageurl": "https://github.com/aboutcode-org/python-inspector",
5-
"tool_version": "0.13.0",
65
"options": [
76
"--index-url https://pypi.org/simple",
87
"--json <file>",

0 commit comments

Comments
 (0)