From 25facef9b8b251258d27feace075904435fcb4d4 Mon Sep 17 00:00:00 2001 From: Tushar Goel Date: Wed, 18 Nov 2026 21:12:51 +0530 Subject: [PATCH 1/3] Add support for pyproject.toml Signed-off-by: Tushar Goel --- CHANGELOG.rst | 4 + README.rst | 4 +- src/python_inspector/api.py | 27 +++- src/python_inspector/pylock_toml.py | 144 ++++++++++++++++++++++ src/python_inspector/resolve_cli.py | 17 ++- tests/data/pylock-requires-python.toml | 7 ++ tests/data/pylock.toml | 25 ++++ tests/data/pylock.toml-expected.json | 101 +++++++++++++++ tests/data/test-api-with-pylock-file.json | 86 +++++++++++++ tests/test_api.py | 14 +++ tests/test_cli.py | 38 ++++++ tests/test_pylock.py | 82 ++++++++++++ 12 files changed, 543 insertions(+), 6 deletions(-) create mode 100644 src/python_inspector/pylock_toml.py create mode 100644 tests/data/pylock-requires-python.toml create mode 100644 tests/data/pylock.toml create mode 100644 tests/data/pylock.toml-expected.json create mode 100644 tests/data/test-api-with-pylock-file.json create mode 100644 tests/test_pylock.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 65588d99..aec6b0d6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,10 @@ Changelog ========= +v0.15.3 +----------- +- Add support for PEP 751 pylock.toml lock files as input. + v0.15.2 ----------- - Correct the version number in the CLI and setup.cfg. diff --git a/README.rst b/README.rst index f0efd8eb..0e45f1e4 100644 --- a/README.rst +++ b/README.rst @@ -7,8 +7,8 @@ python-inspector - inspect Python package dependencies and metadata - resolve PyPI packages dependencies -- parse various requirements.txt files and setup.py files as input - for resolving dependencies. +- parse various requirements.txt files, setup.py files and PEP 751 + pylock.toml lock files as input for resolving dependencies. - parse various manifests and packages files such as Pipfile, pyproject.toml, poetry.lock and setup.cfg and legacy and diff --git a/src/python_inspector/api.py b/src/python_inspector/api.py index b843a53e..c3c28a4f 100644 --- a/src/python_inspector/api.py +++ b/src/python_inspector/api.py @@ -30,6 +30,7 @@ from _packagedcode.pypi import get_resolved_purl from python_inspector import dependencies from python_inspector import pyinspector_settings +from python_inspector import pylock_toml from python_inspector import utils from python_inspector import utils_pypi from python_inspector.package_data import get_pypi_data_from_purl @@ -78,6 +79,7 @@ def to_dict(self, generic_paths=False): def resolve_dependencies( requirement_files=tuple(), + pylock_files=tuple(), setup_py_file=None, specifiers=tuple(), python_version=None, @@ -97,8 +99,8 @@ def resolve_dependencies( ): """ Resolve the dependencies for the package requirements listed in one or - more ``requirement_files``, one or more ``specifiers`` and one setuptools - ``setup_py_file`` file. + more ``requirement_files``, one or more PEP 751 ``pylock_files``, one or + more ``specifiers`` and one setuptools ``setup_py_file`` file. Resolve the dependencies for the requested ``python_version`` PYVER and ``operating_system`` OS combination defaulting Python version 3.8 and @@ -171,6 +173,27 @@ def resolve_dependencies( ) ) + # pylock.toml + for pylock_file in pylock_files: + package_data = pylock_toml.parse_pylock_toml(location=pylock_file) + pylock_toml.validate_pylock_for_environment( + extra_data=package_data.extra_data, + python_version=python_version, + operating_system=operating_system, + ) + index_urls = get_index_urls(index_urls, package_data.extra_data) + direct_dependencies.extend(package_data.dependencies) + pylock_path = pylock_file + if generic_paths: + pylock_path = utils.remove_test_data_dir_variable_prefix(path=pylock_file) + files.append( + dict( + type="file", + path=pylock_path, + package_data=[package_data.to_dict()], + ) + ) + # specs for specifier in specifiers: dep = dependencies.get_dependency(specifier=specifier) diff --git a/src/python_inspector/pylock_toml.py b/src/python_inspector/pylock_toml.py new file mode 100644 index 00000000..e3f1c48d --- /dev/null +++ b/src/python_inspector/pylock_toml.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) nexB Inc. and others. All rights reserved. +# 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://github.com/aboutcode-org/python-inspector for support or download. +# See https://aboutcode.org for more information about nexB OSS projects. +# + +from typing import Iterable +from typing import Mapping + +from packvers.markers import Marker + +from _packagedcode import models +from python_inspector.dependencies import get_dependency +from python_inspector.resolution import get_environment_marker_from_environment +from python_inspector.resolution import get_python_version_from_env_tag +from python_inspector.utils_pypi import Environment +from python_inspector.utils_pypi import valid_python_version + +SUPPORTED_LOCK_VERSION_MAJOR = 1 + + +def load_toml(location: str) -> dict: + """ + Return a mapping parsed from the TOML file at ``location``. + """ + try: + import tomllib + + with open(location, "rb") as f: + return tomllib.load(f) + except ImportError: + import toml + + return toml.load(location) + + +def parse_pylock_toml(location: str) -> models.PackageData: + """ + Return PackageData parsed from a PEP 751 pylock.toml file at ``location``. + """ + data = load_toml(location) + lock_version = str(data.get("lock-version") or "") + if lock_version: + major = lock_version.split(".", 1)[0] + if major != str(SUPPORTED_LOCK_VERSION_MAJOR): + raise ValueError( + f"Unsupported pylock.toml lock-version {lock_version!r}. " + f"Only {SUPPORTED_LOCK_VERSION_MAJOR}.x is supported." + ) + + extra_index_urls = [] + dependent_packages = [] + for package in data.get("packages") or []: + name = package.get("name") + if not name: + continue + version = package.get("version") + if not version: + continue + specifier = f"{name}=={version}" + marker = package.get("marker") + if marker: + specifier = f"{specifier}; {marker}" + dependent_packages.append(get_dependency(specifier=specifier)) + index_url = package.get("index") + if index_url and index_url not in extra_index_urls: + extra_index_urls.append(index_url) + + extra_data = {} + for key in ( + "lock-version", + "created-by", + "requires-python", + "environments", + "extras", + "dependency-groups", + "default-groups", + ): + value = data.get(key) + if value: + extra_data[key] = value + if extra_index_urls: + extra_data["extra_index_urls"] = extra_index_urls + + return models.PackageData( + datasource_id="pypi_pylock_toml", + type="pypi", + primary_language="Python", + dependencies=dependent_packages, + extra_data=extra_data, + ) + + +def get_dependencies_from_pylock(pylock_file: str) -> Iterable[models.DependentPackage]: + """ + Yield DependentPackage for each locked package in a pylock.toml file. + """ + yield from parse_pylock_toml(location=pylock_file).dependencies + + +def get_extra_data_from_pylock(pylock_file: str) -> Iterable[Mapping]: + """ + Yield extra_data parsed from a pylock.toml file. + """ + yield parse_pylock_toml(location=pylock_file).extra_data + + +def validate_pylock_for_environment(extra_data, python_version, operating_system): + """ + Raise ValueError if the pylock metadata does not apply to ``python_version`` + and ``operating_system``. + """ + extra_data = extra_data or {} + python_dot_version = get_python_version_from_env_tag(python_version=python_version) + requires_python = extra_data.get("requires-python") + if requires_python and not valid_python_version(python_dot_version, requires_python): + raise ValueError( + f"Python version {python_dot_version} is not compatible with " + f"pylock.toml requires-python {requires_python}" + ) + + environments = extra_data.get("environments") or [] + if not environments: + return + + environment = Environment.from_pyver_and_os( + python_version=python_version, operating_system=operating_system + ) + environment_marker = get_environment_marker_from_environment(environment) + for expression in environments: + try: + if Marker(expression).evaluate(environment_marker): + return + except Exception: + continue + raise ValueError( + f"No pylock.toml environments marker matches python {python_dot_version} " + f"on {operating_system}: {environments}" + ) diff --git a/src/python_inspector/resolve_cli.py b/src/python_inspector/resolve_cli.py index 9b21626e..5729567b 100644 --- a/src/python_inspector/resolve_cli.py +++ b/src/python_inspector/resolve_cli.py @@ -48,6 +48,16 @@ def print_version(ctx, param, value): help="Path to pip requirements file listing thirdparty packages. " "This option can be used multiple times.", ) +@click.option( + "--pylock", + "pylock_files", + type=click.Path(exists=True, readable=True, path_type=str, dir_okay=False), + metavar="PYLOCK-FILE", + multiple=True, + required=False, + help="Path to a PEP 751 pylock.toml lock file listing locked thirdparty packages. " + "This option can be used multiple times.", +) @click.option( "-s", "--setup-py", @@ -190,6 +200,7 @@ def print_version(ctx, param, value): def resolve_dependencies( ctx, requirement_files, + pylock_files, setup_py_file, specifiers, python_version, @@ -209,8 +220,9 @@ def resolve_dependencies( ): """ Resolve the dependencies for the package requirements listed in one or - more REQUIREMENT-FILE file, one or more SPECIFIER and one setuptools - SETUP-PY-FILE file and save the results as JSON to FILE. + more REQUIREMENT-FILE file, one or more PYLOCK-FILE file, one or more + SPECIFIER and one setuptools SETUP-PY-FILE file and save the results as + JSON to FILE. Resolve the dependencies for the requested ``--python-version`` PYVER and ``--operating_system`` OS combination. @@ -259,6 +271,7 @@ def resolve_dependencies( try: resolution_result: Dict = resolver_api( requirement_files=requirement_files, + pylock_files=pylock_files, setup_py_file=setup_py_file, specifiers=specifiers, python_version=python_version, diff --git a/tests/data/pylock-requires-python.toml b/tests/data/pylock-requires-python.toml new file mode 100644 index 00000000..fc3bd556 --- /dev/null +++ b/tests/data/pylock-requires-python.toml @@ -0,0 +1,7 @@ +lock-version = "1.0" +created-by = "python-inspector-tests" +requires-python = ">=3.12" + +[[packages]] +name = "zipp" +version = "3.8.0" diff --git a/tests/data/pylock.toml b/tests/data/pylock.toml new file mode 100644 index 00000000..7c3b93f5 --- /dev/null +++ b/tests/data/pylock.toml @@ -0,0 +1,25 @@ +lock-version = "1.0" +created-by = "python-inspector-tests" +requires-python = ">=3.8" +environments = [ + "sys_platform == 'linux'", + "sys_platform == 'windows'", + "sys_platform == 'macos'", +] + +[[packages]] +name = "zipp" +version = "3.8.0" +index = "https://pypi.org/simple" +wheels = [ + {name = "zipp-3.8.0-py3-none-any.whl", url = "https://files.pythonhosted.org/packages/3b/39/874eea436a67c793ee70723cf5bb80b0dd36610c21748316ece6e885edc0/zipp-3.8.0-py3-none-any.whl", hashes = {sha256 = "56c5515d303a88fe4615cfe1e30145c483f9dc5a79747d59e28348d63902e795"}}, +] + +[[packages]] +name = "windows-only" +version = "1.0.0" +marker = "sys_platform == 'win32'" + +[[packages]] +name = "local-src" +directory = {path = "./vendor/local-src"} diff --git a/tests/data/pylock.toml-expected.json b/tests/data/pylock.toml-expected.json new file mode 100644 index 00000000..fd4f881d --- /dev/null +++ b/tests/data/pylock.toml-expected.json @@ -0,0 +1,101 @@ +{ + "headers": { + "tool_name": "python-inspector", + "tool_homepageurl": "https://github.com/aboutcode-org/python-inspector", + "options": [ + "--index-url https://pypi.org/simple", + "--json ", + "--operating-system linux", + "--pylock tests/data/pylock.toml", + "--python-version 38", + "--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/aboutcode-org/python-inspector/ for support and download.", + "warnings": [], + "errors": [] + }, + "files": [ + { + "type": "file", + "path": "tests/data/pylock.toml", + "package_data": [ + { + "type": "pypi", + "namespace": null, + "name": null, + "version": null, + "qualifiers": {}, + "subpath": null, + "primary_language": "Python", + "description": null, + "release_date": null, + "parties": [], + "keywords": [], + "homepage_url": null, + "download_url": null, + "size": null, + "sha1": null, + "md5": null, + "sha256": null, + "sha512": null, + "bug_tracking_url": null, + "code_view_url": null, + "vcs_url": null, + "copyright": null, + "license_expression": null, + "declared_license": null, + "notice_text": null, + "source_packages": [], + "file_references": [], + "extra_data": { + "lock-version": "1.0", + "created-by": "python-inspector-tests", + "requires-python": ">=3.8", + "environments": [ + "sys_platform == 'linux'", + "sys_platform == 'windows'", + "sys_platform == 'macos'" + ], + "extra_index_urls": [ + "https://pypi.org/simple" + ] + }, + "dependencies": [ + { + "purl": "pkg:pypi/zipp@3.8.0", + "extracted_requirement": "zipp==3.8.0", + "scope": "install", + "is_runtime": true, + "is_optional": false, + "is_resolved": true, + "resolved_package": {}, + "extra_data": {} + }, + { + "purl": "pkg:pypi/windows-only@1.0.0", + "extracted_requirement": "windows-only==1.0.0;sys_platform=='win32'", + "scope": "install", + "is_runtime": true, + "is_optional": false, + "is_resolved": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "pypi_pylock_toml", + "purl": null + } + ] + } + ], + "packages": [], + "resolved_dependencies_graph": [ + { + "package": "pkg:pypi/zipp@3.8.0", + "dependencies": [] + } + ] +} \ No newline at end of file diff --git a/tests/data/test-api-with-pylock-file.json b/tests/data/test-api-with-pylock-file.json new file mode 100644 index 00000000..d0bc0572 --- /dev/null +++ b/tests/data/test-api-with-pylock-file.json @@ -0,0 +1,86 @@ +{ + "files": [ + { + "type": "file", + "path": "tests/data/pylock.toml", + "package_data": [ + { + "type": "pypi", + "namespace": null, + "name": null, + "version": null, + "qualifiers": {}, + "subpath": null, + "primary_language": "Python", + "description": null, + "release_date": null, + "parties": [], + "keywords": [], + "homepage_url": null, + "download_url": null, + "size": null, + "sha1": null, + "md5": null, + "sha256": null, + "sha512": null, + "bug_tracking_url": null, + "code_view_url": null, + "vcs_url": null, + "copyright": null, + "license_expression": null, + "declared_license": null, + "notice_text": null, + "source_packages": [], + "file_references": [], + "extra_data": { + "lock-version": "1.0", + "created-by": "python-inspector-tests", + "requires-python": ">=3.8", + "environments": [ + "sys_platform == 'linux'", + "sys_platform == 'windows'", + "sys_platform == 'macos'" + ], + "extra_index_urls": [ + "https://pypi.org/simple" + ] + }, + "dependencies": [ + { + "purl": "pkg:pypi/zipp@3.8.0", + "extracted_requirement": "zipp==3.8.0", + "scope": "install", + "is_runtime": true, + "is_optional": false, + "is_resolved": true, + "resolved_package": {}, + "extra_data": {} + }, + { + "purl": "pkg:pypi/windows-only@1.0.0", + "extracted_requirement": "windows-only==1.0.0;sys_platform=='win32'", + "scope": "install", + "is_runtime": true, + "is_optional": false, + "is_resolved": true, + "resolved_package": {}, + "extra_data": {} + } + ], + "repository_homepage_url": null, + "repository_download_url": null, + "api_data_url": null, + "datasource_id": "pypi_pylock_toml", + "purl": null + } + ] + } + ], + "packages": [], + "resolution": [ + { + "package": "pkg:pypi/zipp@3.8.0", + "dependencies": [] + } + ] +} \ No newline at end of file diff --git a/tests/test_api.py b/tests/test_api.py index b0eb7b74..4f225cc4 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -51,6 +51,20 @@ def test_api_with_specifier_pdt(regen=REGEN_TEST_FIXTURES): ) +@pytest.mark.online +def test_api_with_pylock_file(regen=REGEN_TEST_FIXTURES): + expected_file = test_env.get_test_loc("test-api-with-pylock-file.json", must_exist=False) + results = resolver_api( + python_version="38", + operating_system="linux", + pylock_files=[test_env.get_test_loc("pylock.toml")], + use_pypi_json_api=True, + ) + check_data_results( + results=results.to_dict(generic_paths=True), expected_file=expected_file, regen=regen + ) + + @pytest.mark.online def test_api_with_requirement_file(regen=REGEN_TEST_FIXTURES): expected_file = test_env.get_test_loc("test-api-with-requirement-file.json", must_exist=False) diff --git a/tests/test_cli.py b/tests/test_cli.py index 95782e89..02a21cc8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -633,6 +633,31 @@ def test_passing_of_unsupported_os(): assert message in stderr +def test_passing_of_missing_pylock_file(): + options = ["--pylock", "missing-pylock.toml", "--json", "-"] + rc, stdout, stderr = run_cli(options=options, expected_rc=2, get_env=False) + assert "Invalid value for '--pylock'" in stderr + + +@pytest.mark.online +def test_cli_with_pylock_toml(regen=REGEN_TEST_FIXTURES): + pylock_file = test_env.get_test_loc("pylock.toml") + expected_file = test_env.get_test_loc("pylock.toml-expected.json", must_exist=False) + extra_options = [ + "--use-pypi-json-api", + "--operating-system", + "linux", + "--python-version", + "38", + ] + check_pylock_resolution( + pylock_file=pylock_file, + expected_file=expected_file, + extra_options=extra_options, + regen=regen, + ) + + def check_requirements_resolution( requirements_file, expected_file, @@ -650,6 +675,19 @@ def check_requirements_resolution( check_json_file_results(result_file=result_file, expected_file=expected_file, regen=regen) +def check_pylock_resolution( + pylock_file, + expected_file, + extra_options=tuple(), + regen=REGEN_TEST_FIXTURES, +): + result_file = test_env.get_temp_file("json") + options = ["--pylock", pylock_file, "--json", result_file] + options.extend(extra_options) + run_cli(options=options) + check_json_file_results(result_file=result_file, expected_file=expected_file, regen=regen) + + def check_setup_py_resolution( setup_py, expected_file, diff --git a/tests/test_pylock.py b/tests/test_pylock.py new file mode 100644 index 00000000..400d3daa --- /dev/null +++ b/tests/test_pylock.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Copyright (c) nexB Inc. and others. All rights reserved. +# 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://github.com/nexB/python-inspector for support or download. +# See https://aboutcode.org for more information about nexB OSS projects. +# + +import os + +import pytest +from commoncode.testcase import FileDrivenTesting + +from python_inspector.api import resolver_api +from python_inspector.pylock_toml import get_dependencies_from_pylock +from python_inspector.pylock_toml import parse_pylock_toml +from python_inspector.pylock_toml import validate_pylock_for_environment + +test_env = FileDrivenTesting() +test_env.test_data_dir = os.path.join(os.path.dirname(__file__), "data") + + +def test_parse_pylock_toml(): + location = test_env.get_test_loc("pylock.toml") + package_data = parse_pylock_toml(location=location) + assert package_data.datasource_id == "pypi_pylock_toml" + assert package_data.extra_data["lock-version"] == "1.0" + assert package_data.extra_data["created-by"] == "python-inspector-tests" + assert package_data.extra_data["requires-python"] == ">=3.8" + assert package_data.extra_data["extra_index_urls"] == ["https://pypi.org/simple"] + purls = [dep.purl for dep in package_data.dependencies] + assert purls == ["pkg:pypi/zipp@3.8.0", "pkg:pypi/windows-only@1.0.0"] + windows_only = package_data.dependencies[1] + assert "sys_platform" in windows_only.extracted_requirement + assert windows_only.is_resolved is True + + +def test_get_dependencies_from_pylock_skips_packages_without_version(): + location = test_env.get_test_loc("pylock.toml") + deps = list(get_dependencies_from_pylock(pylock_file=location)) + assert all(dep.is_resolved for dep in deps) + assert "local-src" not in " ".join(dep.purl for dep in deps) + + +def test_parse_pylock_toml_rejects_unsupported_lock_version(tmpdir): + lock_file = tmpdir.join("pylock.toml") + lock_file.write('lock-version = "2.0"\n[[packages]]\nname = "zipp"\nversion = "3.8.0"\n') + with pytest.raises(ValueError, match="Unsupported pylock.toml lock-version"): + parse_pylock_toml(location=str(lock_file)) + + +def test_validate_pylock_for_environment_rejects_incompatible_python(): + extra_data = {"requires-python": ">=3.12"} + with pytest.raises(ValueError, match="requires-python"): + validate_pylock_for_environment( + extra_data=extra_data, + python_version="38", + operating_system="linux", + ) + + +def test_validate_pylock_for_environment_rejects_unmatched_environments(): + extra_data = {"environments": ["sys_platform == 'does-not-exist'"]} + with pytest.raises(ValueError, match="environments marker"): + validate_pylock_for_environment( + extra_data=extra_data, + python_version="38", + operating_system="linux", + ) + + +def test_api_with_incompatible_pylock_requires_python(): + location = test_env.get_test_loc("pylock-requires-python.toml") + with pytest.raises(ValueError, match="requires-python"): + resolver_api( + pylock_files=[location], + python_version="38", + operating_system="linux", + ) From 98d39b2d01aeea6d69becb309bf4176f0a4d502f Mon Sep 17 00:00:00 2001 From: Tushar Goel Date: Wed, 18 Nov 2026 21:18:05 +0530 Subject: [PATCH 2/3] Regen tests Signed-off-by: Tushar Goel --- tests/data/test-api-with-partial-setup-py.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/data/test-api-with-partial-setup-py.json b/tests/data/test-api-with-partial-setup-py.json index d96ae10f..c3f6196d 100644 --- a/tests/data/test-api-with-partial-setup-py.json +++ b/tests/data/test-api-with-partial-setup-py.json @@ -59,12 +59,12 @@ "type": "pypi", "namespace": null, "name": "semver", - "version": "3.1.1", + "version": "3.1.2", "qualifiers": {}, "subpath": null, "primary_language": "Python", "description": "Python helper for Semantic Versioning (https://semver.org)\nQuickstart\n==========\n\n.. teaser-begin\n\nA Python module to simplify `semantic versioning`_.\n\n|GHAction| |python-support| |downloads| |license| |docs| |black|\n|openissues| |GHDiscussion|\n\n.. teaser-end\n\nThe module follows the ``MAJOR.MINOR.PATCH`` style:\n\n* ``MAJOR`` version when you make incompatible API changes,\n* ``MINOR`` version when you add functionality in a backwards compatible manner, and\n* ``PATCH`` version when you make backwards compatible bug fixes.\n\nAdditional labels for pre-release and build metadata are supported.\n\nTo import this library, use:\n\n.. code-block:: python\n\n >>> import semver\n\nWorking with the library is quite straightforward. To turn a version string into the\ndifferent parts, use the ``semver.Version.parse`` function:\n\n.. code-block:: python\n\n >>> ver = semver.Version.parse('1.2.3-pre.2+build.4')\n >>> ver.major\n 1\n >>> ver.minor\n 2\n >>> ver.patch\n 3\n >>> ver.prerelease\n 'pre.2'\n >>> ver.build\n 'build.4'\n\nTo raise parts of a version, there are a couple of functions available for\nyou. The function ``semver.Version.bump_major`` leaves the original object untouched, but\nreturns a new ``semver.Version`` instance with the raised major part:\n\n.. code-block:: python\n\n >>> ver = semver.Version.parse(\"3.4.5\")\n >>> ver.bump_major()\n Version(major=4, minor=0, patch=0, prerelease=None, build=None)\n\nIt is allowed to concatenate different \"bump functions\":\n\n.. code-block:: python\n\n >>> ver.bump_major().bump_minor()\n Version(major=4, minor=1, patch=0, prerelease=None, build=None)\n\nTo compare two versions, semver provides the ``semver.compare`` function.\nThe return value indicates the relationship between the first and second\nversion:\n\n.. code-block:: python\n\n >>> semver.compare(\"1.0.0\", \"2.0.0\")\n -1\n >>> semver.compare(\"2.0.0\", \"1.0.0\")\n 1\n >>> semver.compare(\"2.0.0\", \"2.0.0\")\n 0\n\n\nThere are other functions to discover. Read on!\n\n\n.. |latest-version| image:: https://img.shields.io/pypi/v/semver.svg\n :alt: Latest version on PyPI\n :target: https://pypi.org/project/semver\n.. |python-support| image:: https://img.shields.io/pypi/pyversions/semver.svg\n :target: https://pypi.org/project/semver\n :alt: Python versions\n.. |downloads| image:: https://img.shields.io/pypi/dm/semver.svg\n :alt: Monthly downloads from PyPI\n :target: https://pypi.org/project/semver\n.. |license| image:: https://img.shields.io/pypi/l/semver.svg\n :alt: Software license\n :target: https://github.com/python-semver/python-semver/blob/master/LICENSE.txt\n.. |docs| image:: https://readthedocs.org/projects/python-semver/badge/?version=latest\n :target: http://python-semver.readthedocs.io/en/latest/?badge=latest\n :alt: Documentation Status\n.. _semantic versioning: https://semver.org/\n.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg\n :target: https://github.com/psf/black\n :alt: Black Formatter\n.. |Gitter| image:: https://badges.gitter.im/python-semver/community.svg\n :target: https://gitter.im/python-semver/community\n :alt: Gitter\n.. |openissues| image:: http://isitmaintained.com/badge/open/python-semver/python-semver.svg\n :target: http://isitmaintained.com/project/python-semver/python-semver\n :alt: Percentage of open issues\n.. |GHAction| image:: https://github.com/python-semver/python-semver/workflows/Python/badge.svg\n :alt: Python\n.. |GHDiscussion| image:: https://shields.io/badge/GitHub-%20Discussions-green?logo=github\n :target: https://github.com/python-semver/python-semver/discussions\n :alt: GitHub Discussion", - "release_date": "2026-11-09T11:38:46", + "release_date": "2026-11-15T17:01:42", "parties": [ { "type": "person", @@ -96,11 +96,11 @@ "Topic :: Software Development :: Libraries :: Python Modules" ], "homepage_url": null, - "download_url": "https://files.pythonhosted.org/packages/0e/50/2932d6434608c7d954d0d4f4b71b697260e3b40c802425fc84c1eed12440/semver-3.1.1.tar.gz", - "size": 292174, + "download_url": "https://files.pythonhosted.org/packages/ec/a0/3d3f51a1304c0e8c93e06a23308f566f2d52d62f92dac903b85ef79dea6f/semver-3.1.2.tar.gz", + "size": 293659, "sha1": null, - "md5": "68d79f1d7ff87813474adee877a07367", - "sha256": "149b26cabada6f63212f97e94505d21578cb1d280cf714827f328d5e70765fea", + "md5": "24cbe6a00e0c1273fe36e6334957dbe1", + "sha256": "bea193552413194252d33ff26ce0962b76669bd1c6fb17e8e203ac37f072feaf", "sha512": null, "bug_tracking_url": "https://github.com/python-semver/python-semver/issues", "code_view_url": null, @@ -115,14 +115,14 @@ "dependencies": [], "repository_homepage_url": null, "repository_download_url": null, - "api_data_url": "https://pypi.org/pypi/semver/3.1.1/json", + "api_data_url": "https://pypi.org/pypi/semver/3.1.2/json", "datasource_id": null, - "purl": "pkg:pypi/semver@3.1.1" + "purl": "pkg:pypi/semver@3.1.2" } ], "resolution": [ { - "package": "pkg:pypi/semver@3.1.1", + "package": "pkg:pypi/semver@3.1.2", "dependencies": [] } ] From 70d6eb55468df6a9010909d54df9eb2b2e89fd77 Mon Sep 17 00:00:00 2001 From: Tushar Goel Date: Wed, 18 Nov 2026 21:22:13 +0530 Subject: [PATCH 3/3] Add comments Signed-off-by: Tushar Goel --- src/python_inspector/pylock_toml.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/python_inspector/pylock_toml.py b/src/python_inspector/pylock_toml.py index e3f1c48d..3ded7839 100644 --- a/src/python_inspector/pylock_toml.py +++ b/src/python_inspector/pylock_toml.py @@ -21,6 +21,8 @@ from python_inspector.utils_pypi import Environment from python_inspector.utils_pypi import valid_python_version +# PEP 751 pylock.toml major version this parser implements. +# 1.x files are accepted; a higher major version is a breaking format change. SUPPORTED_LOCK_VERSION_MAJOR = 1