diff --git a/src/packagedcode/pypi.py b/src/packagedcode/pypi.py index 271e98a69e..24d4f2e330 100644 --- a/src/packagedcode/pypi.py +++ b/src/packagedcode/pypi.py @@ -517,6 +517,12 @@ def parse(cls, location, package_only=False): if license_file: extra_data['license_file'] = license_file + 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( requires=project_data.get("dependencies", []), 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/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/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 37bd204327..5d856cefdb 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_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/standard/python_private_package-pyproject.toml-expected.json') + self.check_packages_data(package, expected_loc, regen=REGEN_TEST_FIXTURES) + class TestPoetryHandler(PackageTester):