From 768d64ce463d300dea1ca5f9a4211677829a5b98 Mon Sep 17 00:00:00 2001 From: Varsha U N Date: Sun, 17 Nov 2024 20:48:40 +0530 Subject: [PATCH 1/3] Added support for parsing private classifier Signed-off-by: Varsha U N Signed-off-by: Varsha U N --- src/packagedcode/pypi.py | 4 ++++ tests/packagedcode/test_pypi.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/src/packagedcode/pypi.py b/src/packagedcode/pypi.py index 271e98a69e..c074106a6a 100644 --- a/src/packagedcode/pypi.py +++ b/src/packagedcode/pypi.py @@ -517,6 +517,10 @@ def parse(cls, location, package_only=False): if license_file: extra_data['license_file'] = license_file + classifiers = project_data.get('classifiers', []) + is_private = any('Private ::' in classifier for classifier in classifiers) + extra_data['is_private'] = is_private + dependencies = [] parsed_dependencies = get_requires_dependencies( requires=project_data.get("dependencies", []), diff --git a/tests/packagedcode/test_pypi.py b/tests/packagedcode/test_pypi.py index 37bd204327..7d94032c6c 100644 --- a/tests/packagedcode/test_pypi.py +++ b/tests/packagedcode/test_pypi.py @@ -339,6 +339,12 @@ def test_parse_pyproject_toml_standard_lc0(self): expected_loc = self.get_test_loc('pypi/pyproject-toml/standard/lc0-pyproject.toml-expected.json') self.check_packages_data(package, expected_loc, regen=REGEN_TEST_FIXTURES) + def test_parse_pyproject_toml_private_package(self): + test_file = self.get_test_loc('pypi/pyproject-toml/private/private_package/pyproject.toml') + package = pypi.PyprojectTomlHandler.parse(test_file) + expected_loc = self.get_test_loc('pypi/pyproject-toml/private/private_package-pyproject.toml-expected.json') + self.check_packages_data(package, expected_loc, regen=REGEN_TEST_FIXTURES) + class TestPoetryHandler(PackageTester): From 56fe8b4497b6d962b732d9f3543e3650541146e6 Mon Sep 17 00:00:00 2001 From: Varsha U N Date: Sun, 1 Dec 2024 15:31:05 +0530 Subject: [PATCH 2/3] added test files Signed-off-by: Varsha U N --- src/packagedcode/pypi.py | 8 ++++--- ...ivate-package-pyproject.toml-expected.json | 16 ++++++++++++++ .../python-private-package/pyproject.toml | 22 +++++++++++++++++++ .../packagedcode/test_parse_pyproject_toml.py | 20 +++++++++++++++++ tests/packagedcode/test_pypi.py | 6 ++--- 5 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 tests/packagedcode/data/pypi/pyproject-toml/standard/python-private-package-pyproject.toml-expected.json create mode 100644 tests/packagedcode/data/pypi/pyproject-toml/standard/python-private-package/pyproject.toml create mode 100644 tests/packagedcode/test_parse_pyproject_toml.py diff --git a/src/packagedcode/pypi.py b/src/packagedcode/pypi.py index c074106a6a..24d4f2e330 100644 --- a/src/packagedcode/pypi.py +++ b/src/packagedcode/pypi.py @@ -517,9 +517,11 @@ def parse(cls, location, package_only=False): if license_file: extra_data['license_file'] = license_file - classifiers = project_data.get('classifiers', []) - is_private = any('Private ::' in classifier for classifier in classifiers) - extra_data['is_private'] = is_private + classifiers = project_data.get('classifiers', []) + is_private = False + is_private = any('Private ::' in classifier for classifier in classifiers) + is_private = True + self.is_private = is_private dependencies = [] parsed_dependencies = get_requires_dependencies( diff --git a/tests/packagedcode/data/pypi/pyproject-toml/standard/python-private-package-pyproject.toml-expected.json b/tests/packagedcode/data/pypi/pyproject-toml/standard/python-private-package-pyproject.toml-expected.json new file mode 100644 index 0000000000..cdf4ca3029 --- /dev/null +++ b/tests/packagedcode/data/pypi/pyproject-toml/standard/python-private-package-pyproject.toml-expected.json @@ -0,0 +1,16 @@ +{ + "name": "PrivatePackage", + "version": "0.1.0", + "description": "A private package for testing the 'Private :: Do Not Upload' classifier.", + "license": "LICENSE.txt", + "classifiers": [ + "Development Status :: 1 - Planning", + "Programming Language :: Python :: 3", + "Private :: Do Not Upload" + ], + "requires-python": ">=3.7", + "dependencies": [ + "requests>=2.25.1" + ] + +} diff --git a/tests/packagedcode/data/pypi/pyproject-toml/standard/python-private-package/pyproject.toml b/tests/packagedcode/data/pypi/pyproject-toml/standard/python-private-package/pyproject.toml new file mode 100644 index 0000000000..af935f2639 --- /dev/null +++ b/tests/packagedcode/data/pypi/pyproject-toml/standard/python-private-package/pyproject.toml @@ -0,0 +1,22 @@ +[build-system] +requires = ["setuptools", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "PrivatePackage" +version = "0.1.0" +description = "A private package for testing the 'Private :: Do Not Upload' classifier." +readme = "README.md" +license = {file = "LICENSE.txt"} +classifiers = [ + "Development Status :: 1 - Planning", + "Programming Language :: Python :: 3", + "Private :: Do Not Upload" +] +requires-python = ">=3.7" +dependencies = [ + "requests>=2.25.1", +] + + + diff --git a/tests/packagedcode/test_parse_pyproject_toml.py b/tests/packagedcode/test_parse_pyproject_toml.py new file mode 100644 index 0000000000..5b1df3592a --- /dev/null +++ b/tests/packagedcode/test_parse_pyproject_toml.py @@ -0,0 +1,20 @@ +import json +import toml +import os + +def test_parse_pyproject_toml(): + + toml_path = "tests/packagedcode/data/pypi/pyproject-toml/standard/python_private_package/pyproject.toml" + + expected_json_path = "tests/packagedcode/data/pypi/pyproject-toml/standard/python_private_package/pyproject.toml-expected.json" + + + with open(toml_path, 'r') as file: + toml_data = toml.load(file) + + + with open(expected_json_path, 'r') as file: + expected_data = json.load(file) + + + assert toml_data == expected_data, f"Parsed data does not match the expected data.\nParsed: {toml_data}\nExpected: {expected_data}" diff --git a/tests/packagedcode/test_pypi.py b/tests/packagedcode/test_pypi.py index 7d94032c6c..5d856cefdb 100644 --- a/tests/packagedcode/test_pypi.py +++ b/tests/packagedcode/test_pypi.py @@ -339,10 +339,10 @@ def test_parse_pyproject_toml_standard_lc0(self): expected_loc = self.get_test_loc('pypi/pyproject-toml/standard/lc0-pyproject.toml-expected.json') self.check_packages_data(package, expected_loc, regen=REGEN_TEST_FIXTURES) - def test_parse_pyproject_toml_private_package(self): - test_file = self.get_test_loc('pypi/pyproject-toml/private/private_package/pyproject.toml') + def test_parse_pyproject_toml_standard_python_private_package(self): + test_file = self.get_test_loc('pypi/pyproject-toml/standard/python_private_package/pyproject.toml') package = pypi.PyprojectTomlHandler.parse(test_file) - expected_loc = self.get_test_loc('pypi/pyproject-toml/private/private_package-pyproject.toml-expected.json') + expected_loc = self.get_test_loc('pypi/pyproject-toml/standard/python_private_package-pyproject.toml-expected.json') self.check_packages_data(package, expected_loc, regen=REGEN_TEST_FIXTURES) From 25f5adbfa410181f58aca8a8924014a521e8f2df Mon Sep 17 00:00:00 2001 From: Varsha U N Date: Mon, 23 Dec 2024 22:12:46 +0530 Subject: [PATCH 3/3] added required filepath Signed-off-by: Varsha U N --- .../pyproject.toml-expected.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/packagedcode/data/pypi/pyproject-toml/standard/{python-private-package-pyproject.toml-expected.json => python-private-package/pyproject.toml-expected.json} (100%) diff --git a/tests/packagedcode/data/pypi/pyproject-toml/standard/python-private-package-pyproject.toml-expected.json b/tests/packagedcode/data/pypi/pyproject-toml/standard/python-private-package/pyproject.toml-expected.json similarity index 100% rename from tests/packagedcode/data/pypi/pyproject-toml/standard/python-private-package-pyproject.toml-expected.json rename to tests/packagedcode/data/pypi/pyproject-toml/standard/python-private-package/pyproject.toml-expected.json