Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,46 @@ jobs:
parameters:
job_name: ubuntu20_cpython
image_name: ubuntu-20.04
python_versions: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python_versions: ["3.9", "3.10", "3.11", "3.12"]
test_suites:
all: venv/bin/pytest -n 2 -vvs --reruns 2

- template: etc/ci/azure-posix.yml
parameters:
job_name: ubuntu22_cpython
image_name: ubuntu-22.04
python_versions: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python_versions: ["3.9", "3.10", "3.11", "3.12"]
test_suites:
all: venv/bin/pytest -n 2 -vvs --reruns 2

- template: etc/ci/azure-posix.yml
parameters:
job_name: macos12_cpython
image_name: macOS-12
python_versions: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
job_name: macos14_cpython
image_name: macOS-14
python_versions: ["3.9", "3.10", "3.11", "3.12"]
test_suites:
all: venv/bin/pytest -n 2 -vvs --reruns 2

- template: etc/ci/azure-posix.yml
parameters:
job_name: macos13_cpython
image_name: macos-13
python_versions: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python_versions: ["3.9", "3.10", "3.11", "3.12"]
test_suites:
all: venv/bin/pytest -n 2 -vvs --reruns 2

- template: etc/ci/azure-win.yml
parameters:
job_name: win2019_cpython
image_name: windows-2019
python_versions: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python_versions: ["3.9", "3.10", "3.11", "3.12"]
test_suites:
all: venv\Scripts\pytest -n 2 -vvs --reruns 2

- template: etc/ci/azure-win.yml
parameters:
job_name: win2022_cpython
image_name: windows-2022
python_versions: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python_versions: ["3.9", "3.10", "3.11", "3.12"]
test_suites:
all: venv\Scripts\pytest -n 2 -vvs --reruns 2
30 changes: 10 additions & 20 deletions src/python_inspector/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ def to_dict(self, generic_paths=False):
# clean file paths
for file in files:
path = file["path"]
file["path"] = utils.remove_test_data_dir_variable_prefix(
path=path)
file["path"] = utils.remove_test_data_dir_variable_prefix(path=path)
return {
"files": files,
"packages": [package for package in self.packages],
Expand Down Expand Up @@ -152,20 +151,16 @@ def resolve_dependencies(

# requirements
for req_file in requirement_files:
deps = dependencies.get_dependencies_from_requirements(
requirements_file=req_file)
deps = dependencies.get_dependencies_from_requirements(requirements_file=req_file)
for extra_data in dependencies.get_extra_data_from_requirements(requirements_file=req_file):
index_urls = (
*index_urls, *tuple(extra_data.get("extra_index_urls") or []))
index_urls = (
*index_urls, *tuple(extra_data.get("index_url") or []))
index_urls = (*index_urls, *tuple(extra_data.get("extra_index_urls") or []))
index_urls = (*index_urls, *tuple(extra_data.get("index_url") or []))
direct_dependencies.extend(deps)
package_data = [
pkg_data.to_dict() for pkg_data in PipRequirementsFileHandler.parse(location=req_file)
]
if generic_paths:
req_file = utils.remove_test_data_dir_variable_prefix(
path=req_file)
req_file = utils.remove_test_data_dir_variable_prefix(path=req_file)

files.append(
dict(
Expand Down Expand Up @@ -218,15 +213,13 @@ def resolve_dependencies(
files=[setup_py_file],
analyze_setup_py_insecurely=analyze_setup_py_insecurely,
)
setup_py_file_deps = list(
get_dependent_packages_from_reqs(reqs))
setup_py_file_deps = list(get_dependent_packages_from_reqs(reqs))
direct_dependencies.extend(setup_py_file_deps)

package_data.dependencies = setup_py_file_deps
file_package_data = [package_data.to_dict()]
if generic_paths:
setup_py_file = utils.remove_test_data_dir_variable_prefix(
path=setup_py_file)
setup_py_file = utils.remove_test_data_dir_variable_prefix(path=setup_py_file)
files.append(
dict(
type="file",
Expand Down Expand Up @@ -267,11 +260,9 @@ def resolve_dependencies(
else:
credentials = None
if parsed_netrc:
login, password = utils.get_netrc_auth(
index_url, parsed_netrc)
login, password = utils.get_netrc_auth(index_url, parsed_netrc)
credentials = (
dict(login=login,
password=password) if login and password else None
dict(login=login, password=password) if login and password else None
)
repo = utils_pypi.PypiSimpleRepository(
index_url=index_url,
Expand Down Expand Up @@ -391,8 +382,7 @@ def get_resolved_dependencies(
),
reporter=BaseReporter(),
)
resolver_results = resolver.resolve(
requirements=requirements, max_rounds=max_rounds)
resolver_results = resolver.resolve(requirements=requirements, max_rounds=max_rounds)
package_list = get_package_list(results=resolver_results)
if pdt_output:
return (format_pdt_tree(resolver_results), package_list)
Expand Down
3 changes: 1 addition & 2 deletions src/python_inspector/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class FileOptionType(click.File):

def convert(self, value, param, ctx):
known_opts = set(
chain.from_iterable(
p.opts for p in ctx.command.params if isinstance(p, click.Option))
chain.from_iterable(p.opts for p in ctx.command.params if isinstance(p, click.Option))
)
if value in known_opts:
self.fail(
Expand Down
3 changes: 1 addition & 2 deletions src/python_inspector/package_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ def get_pypi_data_from_purl(
project_urls = info.get("project_urls") or {}
code_view_url = get_pypi_codeview_url(project_urls)
bug_tracking_url = get_pypi_bugtracker_url(project_urls)
python_version = get_python_version_from_env_tag(
python_version=environment.python_version)
python_version = get_python_version_from_env_tag(python_version=environment.python_version)
valid_distribution_urls = []

valid_distribution_urls.append(
Expand Down
33 changes: 11 additions & 22 deletions src/python_inspector/resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,13 @@ def get_sdist_file_path_from_filename(sdist):
sdist_file = sdist.rstrip(".tar.gz")
with tarfile.open(os.path.join(utils_pypi.CACHE_THIRDPARTY_DIR, sdist)) as file:
file.extractall(
os.path.join(utils_pypi.CACHE_THIRDPARTY_DIR,
"extracted_sdists", sdist_file)
os.path.join(utils_pypi.CACHE_THIRDPARTY_DIR, "extracted_sdists", sdist_file)
)
elif sdist.endswith(".zip"):
sdist_file = sdist.rstrip(".zip")
with ZipFile(os.path.join(utils_pypi.CACHE_THIRDPARTY_DIR, sdist)) as zip:
zip.extractall(
os.path.join(utils_pypi.CACHE_THIRDPARTY_DIR,
"extracted_sdists", sdist_file)
os.path.join(utils_pypi.CACHE_THIRDPARTY_DIR, "extracted_sdists", sdist_file)
)

else:
Expand Down Expand Up @@ -361,8 +359,7 @@ def __init__(
ignore_errors=False,
):
self.environment = environment
self.environment_marker = get_environment_marker_from_environment(
self.environment)
self.environment_marker = get_environment_marker_from_environment(self.environment)
self.repos = repos or []
self.versions_by_package = {}
self.dependencies_by_purl = {}
Expand Down Expand Up @@ -411,11 +408,9 @@ def get_versions_for_package_from_repo(
versions = []
for version, package in repo.get_package_versions(name).items():
python_version = parse_version(
get_python_version_from_env_tag(
python_version=self.environment.python_version)
get_python_version_from_env_tag(python_version=self.environment.python_version)
)
wheels = list(package.get_supported_wheels(
environment=self.environment))
wheels = list(package.get_supported_wheels(environment=self.environment))
valid_wheel_present = False
pypi_valid_python_version = False
if wheels:
Expand Down Expand Up @@ -464,8 +459,7 @@ def get_requirements_for_package_from_pypi_simple(
Return requirements for a package from the simple repositories.
"""
python_version = parse_version(
get_python_version_from_env_tag(
python_version=self.environment.python_version)
get_python_version_from_env_tag(python_version=self.environment.python_version)
)

wheels = utils_pypi.download_wheel(
Expand All @@ -478,8 +472,7 @@ def get_requirements_for_package_from_pypi_simple(

if wheels:
for wheel in wheels:
wheel_location = os.path.join(
utils_pypi.CACHE_THIRDPARTY_DIR, wheel)
wheel_location = os.path.join(utils_pypi.CACHE_THIRDPARTY_DIR, wheel)
requirements = get_requirements_from_distribution(
handler=PypiWheelHandler,
location=wheel_location,
Expand Down Expand Up @@ -571,8 +564,7 @@ def get_candidates(
):
valid_versions.append(parsed_version)
if not all(version.is_prerelease for version in valid_versions):
valid_versions = [
version for version in valid_versions if not version.is_prerelease]
valid_versions = [version for version in valid_versions if not version.is_prerelease]
for version in valid_versions:
yield Candidate(name=name, version=version, extras=extras)

Expand All @@ -593,8 +585,7 @@ def _iter_matches(
versions.extend(self.get_versions_for_package(name=name))
else:
for repo in self.repos:
versions.extend(
self.get_versions_for_package(name=name, repo=repo))
versions.extend(self.get_versions_for_package(name=name, repo=repo))

if not versions:
if self.ignore_errors:
Expand Down Expand Up @@ -685,8 +676,7 @@ def dfs(mapping: Dict, graph: DirectedGraph, src: str):

return dict(
package=str(src_purl),
dependencies=sorted([dfs(mapping, graph, c)
for c in children], key=lambda d: d["package"]),
dependencies=sorted([dfs(mapping, graph, c) for c in children], key=lambda d: d["package"]),
)


Expand Down Expand Up @@ -804,8 +794,7 @@ def get_setup_requirements(sdist_location: str, setup_py_location: str, setup_cf
"""

if not os.path.exists(setup_py_location) and not os.path.exists(setup_cfg_location):
raise Exception(
f"No setup.py or setup.cfg found in pypi sdist {sdist_location}")
raise Exception(f"No setup.py or setup.cfg found in pypi sdist {sdist_location}")

# Some commonon packages like flask may have some dependencies in setup.cfg
# and some dependencies in setup.py. We are going to check both.
Expand Down
9 changes: 3 additions & 6 deletions src/python_inspector/resolve_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ def print_version(ctx, param, value):
metavar="OS",
show_default=True,
required=True,
help="OS to use for dependency resolution. One of " +
", ".join(utils_pypi.PLATFORMS_BY_OS),
help="OS to use for dependency resolution. One of " + ", ".join(utils_pypi.PLATFORMS_BY_OS),
)
@click.option(
"--index-url",
Expand Down Expand Up @@ -229,8 +228,7 @@ def resolve_dependencies(
from python_inspector.api import resolve_dependencies as resolver_api

if not (json_output or pdt_output):
click.secho(
"No output file specified. Use --json or --json-pdt.", err=True)
click.secho("No output file specified. Use --json or --json-pdt.", err=True)
ctx.exit(1)

if json_output and pdt_output:
Expand Down Expand Up @@ -339,8 +337,7 @@ def get_pretty_options(ctx, generic_paths=False):
value = [value]

for val in value:
val = get_pretty_value(param_type=param.type,
value=val, generic_paths=generic_paths)
val = get_pretty_value(param_type=param.type, value=val, generic_paths=generic_paths)

if isinstance(param, click.Argument):
args.append(val)
Expand Down
732 changes: 383 additions & 349 deletions tests/data/azure-devops.req-310-expected.json

Large diffs are not rendered by default.

732 changes: 383 additions & 349 deletions tests/data/azure-devops.req-312-expected.json

Large diffs are not rendered by default.

726 changes: 381 additions & 345 deletions tests/data/azure-devops.req-38-expected.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/data/default-url-expected.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_homepageurl": "https://github.com/aboutcode-org/python-inspector",
"tool_version": "0.12.0",
"options": [
"--json <file>",
Expand All @@ -10,7 +10,7 @@
"--specifier zipp==3.8.0",
"--use-pypi-json-api"
],
"notice": "Dependency tree generated with python-inspector.\npython-inspector is a free software tool from nexB Inc. and others.\nVisit https://github.com/nexB/python-inspector/ for support and download.",
"notice": "Dependency tree generated with python-inspector.\npython-inspector is a free software tool from nexB Inc. and others.\nVisit https://github.com/aboutcode-org/python-inspector/ for support and download.",
"warnings": [],
"errors": []
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_homepageurl": "https://github.com/aboutcode-org/python-inspector",
"tool_version": "0.12.0",
"options": [
"--json-pdt <file>",
"--operating-system linux",
"--python-version 37",
"--requirement tests/data/environment-marker-test-requirements.txt"
],
"notice": "Dependency tree generated with python-inspector.\npython-inspector is a free software tool from nexB Inc. and others.\nVisit https://github.com/nexB/python-inspector/ for support and download.",
"notice": "Dependency tree generated with python-inspector.\npython-inspector is a free software tool from nexB Inc. and others.\nVisit https://github.com/aboutcode-org/python-inspector/ for support and download.",
"warnings": [],
"errors": []
},
Expand Down
Loading
Loading