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
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ Changelog
=========


v0.8.2
------

- For a package that doesn't have a single stable release use the latest pre-release version.


v0.8.1
------

Expand Down
25 changes: 17 additions & 8 deletions src/python_inspector/resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,11 @@ def is_valid_version(
"""
Return True if the parsed_version is valid for the given identifier.
"""
if (
any(parsed_version not in r.specifier for r in requirements[identifier])
or parsed_version in bad_versions
):
if parsed_version in bad_versions:
return False
if any(parsed_version not in r.specifier for r in requirements[identifier]):
if all(not r.specifier for r in requirements[identifier]):
return True
return False
return True

Expand Down Expand Up @@ -453,16 +454,20 @@ def get_candidates(
"""
Generate candidates for the given identifier. Overridden.
"""
valid_versions = []
for version in all_versions:
parsed_version = parse_version(version)
if not is_valid_version(
if is_valid_version(
parsed_version=parsed_version,
requirements=requirements,
identifier=identifier,
bad_versions=bad_versions,
):
continue
yield Candidate(name=name, version=parsed_version, extras=extras)
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]
for version in valid_versions:
yield Candidate(name=name, version=version, extras=extras)

def _iter_matches(
self,
Expand Down Expand Up @@ -504,7 +509,11 @@ def find_matches(

def is_satisfied_by(self, requirement: Requirement, candidate: Candidate) -> bool:
"""Whether the given requirement can be satisfied by a candidate. Overridden."""
return candidate.version in requirement.specifier
if candidate.version in requirement.specifier:
return True
elif not requirement.specifier:
return True
return False

def _iter_dependencies(self, candidate: Candidate) -> Generator[Requirement, None, None]:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/python_inspector/resolve_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

TRACE = False

__version__ = "0.8.1"
__version__ = "0.8.2"

DEFAULT_PYTHON_VERSION = "38"
PYPI_SIMPLE_URL = "https://pypi.org/simple"
Expand Down
2,015 changes: 2,015 additions & 0 deletions tests/data/azure-devops.req-310-expected.json

Large diffs are not rendered by default.

2,015 changes: 2,015 additions & 0 deletions tests/data/azure-devops.req-38-expected.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tests/data/azure-devops.req.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
azure-devops
azure-storage-blob
click
2 changes: 1 addition & 1 deletion tests/data/default-url-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_version": "0.8.1",
"tool_version": "0.8.2",
"options": [
"--specifier zipp==3.8.0",
"--index-url https://pypi.org/simple",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_version": "0.8.1",
"tool_version": "0.8.2",
"options": [
"--requirement /home/tg1999/Desktop/python-inspector-1/tests/data/environment-marker-test-requirements.txt",
"--index-url https://pypi.org/simple",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/frozen-requirements.txt-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_version": "0.8.1",
"tool_version": "0.8.2",
"options": [
"--requirement /home/tg1999/Desktop/python-inspector-1/tests/data/frozen-requirements.txt",
"--index-url https://pypi.org/simple",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/insecure-setup-2/setup.py-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_version": "0.8.1",
"tool_version": "0.8.2",
"options": [
"--index-url https://pypi.org/simple",
"--python-version 27",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/insecure-setup/setup.py-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_version": "0.8.1",
"tool_version": "0.8.2",
"options": [
"--index-url https://pypi.org/simple",
"--python-version 27",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/pdt-requirements.txt-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_version": "0.8.1",
"tool_version": "0.8.2",
"options": [
"--requirement /home/tg1999/Desktop/python-inspector-1/tests/data/pdt-requirements.txt",
"--index-url https://pypi.org/simple",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/pinned-pdt-requirements.txt-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_version": "0.8.1",
"tool_version": "0.8.2",
"options": [
"--requirement /home/tg1999/Desktop/python-inspector-1/tests/data/pinned-pdt-requirements.txt",
"--index-url https://pypi.org/simple",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/pinned-requirements.txt-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_version": "0.8.1",
"tool_version": "0.8.2",
"options": [
"--requirement /home/tg1999/Desktop/python-inspector-1/tests/data/pinned-requirements.txt",
"--index-url https://pypi.org/simple",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/setup/simple-setup.py-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_version": "0.8.1",
"tool_version": "0.8.2",
"options": [
"--index-url https://pypi.org/simple",
"--python-version 27",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/setup/spdx-setup.py-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_version": "0.8.1",
"tool_version": "0.8.2",
"options": [
"--index-url https://pypi.org/simple",
"--python-version 27",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/single-url-except-simple-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_version": "0.8.1",
"tool_version": "0.8.2",
"options": [
"--specifier flask",
"--index-url https://pypi.org/simple",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/single-url-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_version": "0.8.1",
"tool_version": "0.8.2",
"options": [
"--specifier zipp==3.8.0",
"--index-url https://pypi.org/simple",
Expand Down
2 changes: 1 addition & 1 deletion tests/data/tilde_req-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"headers": {
"tool_name": "python-inspector",
"tool_homepageurl": "https://github.com/nexB/python-inspector",
"tool_version": "0.8.1",
"tool_version": "0.8.2",
"options": [
"--specifier zipp~=3.8.0",
"--index-url https://pypi.org/simple",
Expand Down
38 changes: 37 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,42 @@ def test_cli_with_environment_marker_and_complex_ranges():
)


@pytest.mark.online
def test_cli_with_azure_devops_with_python_310():
requirements_file = test_env.get_test_loc("azure-devops.req.txt")
expected_file = test_env.get_test_loc("azure-devops.req-310-expected.json", must_exist=False)
extra_options = [
"--operating-system",
"linux",
"--python-version",
"310",
]
check_requirements_resolution(
requirements_file=requirements_file,
expected_file=expected_file,
extra_options=extra_options,
regen=REGEN_TEST_FIXTURES,
)


@pytest.mark.online
def test_cli_with_azure_devops_with_python_38():
requirements_file = test_env.get_test_loc("azure-devops.req.txt")
expected_file = test_env.get_test_loc("azure-devops.req-38-expected.json", must_exist=False)
extra_options = [
"--operating-system",
"linux",
"--python-version",
"38",
]
check_requirements_resolution(
requirements_file=requirements_file,
expected_file=expected_file,
extra_options=extra_options,
regen=REGEN_TEST_FIXTURES,
)


@pytest.mark.online
def test_cli_with_multiple_index_url_and_tilde_req_with_max_rounds():
expected_file = test_env.get_test_loc("tilde_req-expected.json", must_exist=False)
Expand Down Expand Up @@ -304,7 +340,7 @@ def test_passing_of_json_pdt_and_json_flags():
def test_version_option():
options = ["--version"]
result = run_cli(options=options)
assert "0.8.1" in result.output
assert "0.8.2" in result.output


def test_passing_of_netrc_file_that_does_not_exist():
Expand Down
16 changes: 16 additions & 0 deletions tests/test_resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ def test_is_valid_version():
assert is_valid_version(parsed_version, requirements, identifier, bad_versions)


def test_is_valid_version_with_no_specifier():
parsed_version = packaging.version.parse("2.1.2")
requirements = {"flask": [Requirement("flask")]}
bad_versions = []
identifier = "flask"
assert is_valid_version(parsed_version, requirements, identifier, bad_versions)


def test_is_valid_version_with_no_specifier_and_pre_release():
parsed_version = packaging.version.parse("1.0.0b4")
requirements = {"flask": [Requirement("flask")]}
bad_versions = []
identifier = "flask"
assert is_valid_version(parsed_version, requirements, identifier, bad_versions)


def test_get_requirements_from_dependencies():
dependencies = [
models.DependentPackage(
Expand Down