Skip to content

Improve env var support #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 3, 2025
403 changes: 403 additions & 0 deletions resolve_cli.python

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/python_inspector/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ScanCode is a trademark of nexB Inc.
# SPDX-License-Identifier: Apache-2.0
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
# See https://aboutcode-orgnexB/python-inspector for support or download.
# See https://aboutcode-org/python-inspector for support or download.
# See https://aboutcode.org for more information about nexB OSS projects.
#
import asyncio
Expand Down Expand Up @@ -42,6 +42,7 @@
from python_inspector.resolution import get_reqs_insecurely
from python_inspector.resolution import get_requirements_from_python_manifest
from python_inspector.utils import Candidate
from python_inspector.utils import unique
from python_inspector.utils_pypi import PLATFORMS_BY_OS
from python_inspector.utils_pypi import Environment
from python_inspector.utils_pypi import PypiSimpleRepository
Expand Down Expand Up @@ -336,7 +337,7 @@ def get_index_urls(index_urls: Tuple, extra_data: Dict) -> Tuple:
index_urls = (*index_urls, *tuple(extra_index_urls))
if isinstance(index_url, str):
index_urls = (*index_urls, *tuple([index_url]))
return tuple(set(index_urls))
return tuple(unique(index_urls))


resolver_api = resolve_dependencies
Expand Down
3 changes: 3 additions & 0 deletions src/python_inspector/resolve_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def print_version(ctx, param, value):
@click.option(
"--index-url",
"index_urls",
envvar="PYINSP_INDEX_URL",
type=str,
metavar="INDEX",
show_default=True,
Expand Down Expand Up @@ -122,6 +123,7 @@ def print_version(ctx, param, value):
"--netrc",
"netrc_file",
type=click.Path(exists=True, readable=True, path_type=str, dir_okay=False),
envvar="PYINSP_NETRC_FILE",
metavar="NETRC-FILE",
hidden=True,
required=False,
Expand Down Expand Up @@ -163,6 +165,7 @@ def print_version(ctx, param, value):
)
@click.option(
"--verbose",
envvar="PYINSP_VERBOSE",
is_flag=True,
help="Enable verbose debug output.",
)
Expand Down
4 changes: 2 additions & 2 deletions src/python_inspector/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class Settings(BaseSettings):
"""
Reference: https://docs.pydantic.dev/latest/concepts/pydantic_settings/
A settings object: use it with an .env file and/or environment variables all prefixed with
PYTHON_INSPECTOR_
PYINSP_
"""

model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
env_prefix="PYTHON_INSPECTOR_",
env_prefix="PYINSP_",
case_sensitive=True,
extra="allow",
)
Expand Down
17 changes: 17 additions & 0 deletions src/python_inspector/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,20 @@ def remove_test_data_dir_variable_prefix(path, placeholder="<file>"):
return cleaned.replace("\\", "/")
else:
return placeholder


def unique(sequence):
"""
Return a list of unique items found in sequence. Preserve the original sequence order.
Items must be hashable.
For example:
>>> unique([1, 5, 3, 5])
[1, 5, 3]
"""
seen = set()
deduped = []
for item in sequence:
if item not in seen:
deduped.append(item)
seen.add(item)
return deduped
1 change: 1 addition & 0 deletions src/python_inspector/utils_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ async def download_wheel(
)
continue
for wheel in supported_and_valid_wheels:
wheel.credentials = repo.credentials
fetched_wheel_filename = await wheel.download(
dest_dir=dest_dir,
verbose=verbose,
Expand Down
Loading
Loading