Skip to content

support-python-private-classifier #4075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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
29 changes: 25 additions & 4 deletions src/packagedcode/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from packagedcode.utils import yield_dependencies_from_package_data
from packagedcode.utils import yield_dependencies_from_package_resource
from packagedcode.utils import get_base_purl
from packagedcode.utils import is_private_package

try:
from zipfile import Path as ZipPath
Expand Down Expand Up @@ -473,7 +474,8 @@ def parse(cls, location, package_only=False):
description = project_data.get('description') or ''
description = description.strip()

urls, extra_data = get_urls(metainfo=project_data, name=name, version=version)
is_private = is_private_package(project_data.get('classifiers', []))
urls, extra_data = get_urls(metainfo=project_data, name=name, version=version,is_private=is_private)

extracted_license_statement, license_file = get_declared_license(project_data)
if license_file:
Expand Down Expand Up @@ -504,12 +506,13 @@ def parse(cls, location, package_only=False):
keywords=get_keywords(project_data),
parties=get_pyproject_toml_parties(project_data),
dependencies=dependencies,
is_private=is_private,
extra_data=extra_data,
**urls,
download_url=urls.get('download'),
)
yield models.PackageData.from_data(package_data, package_only)


def is_poetry_pyproject_toml(location):
with open(location, 'r') as file:
data = file.read()
Expand Down Expand Up @@ -698,6 +701,8 @@ def parse(cls, location, package_only=False):
)
dependencies.append(dependency.to_dict())

is_private = is_private_package(poetry_data.get('classifiers', []))

package_data = dict(
datasource_id=cls.datasource_id,
type=cls.default_package_type,
Expand All @@ -709,6 +714,7 @@ def parse(cls, location, package_only=False):
keywords=get_keywords(poetry_data),
parties=get_pyproject_toml_parties(poetry_data),
extra_data=extra_data,
is_private=is_private,
dependencies=dependencies,
**urls,
)
Expand Down Expand Up @@ -976,6 +982,9 @@ def parse_metadata(location, datasource_id, package_type, package_only=False):
if license_file:
extra_data['license_file'] = license_file

classifiers = get_attribute(meta, 'Classifier', multiple=True)
is_private = is_private_package(classifiers)

# FIXME: We are getting dependencies from other sibling files, this is duplicated
# data at the package_data level, is this necessary? We also have the entire dependency
# relationships here at requires.txt present in ``.egg-info`` should we store these
Expand All @@ -996,6 +1005,7 @@ def parse_metadata(location, datasource_id, package_type, package_only=False):
dependencies=dependencies,
file_references=file_references,
extra_data=extra_data,
is_private=is_private,
**urls,
)
return models.PackageData.from_data(package_data, package_only)
Expand Down Expand Up @@ -1161,7 +1171,9 @@ def parse(cls, location, package_only=False):
# search for possible dunder versions here and elsewhere
version = detect_version_attribute(location)

urls, extra_data = get_urls(metainfo=setup_args, name=name, version=version)
is_private = is_private_package(setup_args.get('classifiers', []))

urls, extra_data = get_urls(metainfo=setup_args, name=name, version=version,is_private=is_private)

dependencies = get_setup_py_dependencies(setup_args)
python_requires = get_setup_py_python_requires(setup_args)
Expand All @@ -1171,6 +1183,7 @@ def parse(cls, location, package_only=False):
if license_file:
extra_data['license_file'] = license_file


package_data = dict(
datasource_id=cls.datasource_id,
type=cls.default_package_type,
Expand All @@ -1182,6 +1195,7 @@ def parse(cls, location, package_only=False):
extracted_license_statement=extracted_license_statement,
dependencies=dependencies,
keywords=get_keywords(setup_args),
is_private=is_private,
extra_data=extra_data,
**urls,
)
Expand Down Expand Up @@ -1300,6 +1314,9 @@ def parse(cls, location, package_only=False):
extracted_license_statement = ''
extracted_license_statement += f" license_files: {license_file_references}"

classifiers = parser.get('metadata', 'classifiers', fallback='').splitlines()
is_private = is_private_package(classifiers)

package_data = dict(
datasource_id=cls.datasource_id,
type=cls.default_package_type,
Expand All @@ -1309,6 +1326,7 @@ def parse(cls, location, package_only=False):
homepage_url=metadata.get('url'),
primary_language=cls.default_primary_language,
dependencies=dependent_packages,
is_private=is_private,
extracted_license_statement=extracted_license_statement,
)
yield models.PackageData.from_data(package_data, package_only)
Expand Down Expand Up @@ -2243,7 +2261,7 @@ def get_pypi_urls(name, version, **kwargs):
)


def get_urls(metainfo, name, version, poetry=False):
def get_urls(metainfo, name, version, is_private=False, poetry=False):
"""
Return a mapping of standard URLs and a mapping of extra-data URls for URLs
of this package:
Expand Down Expand Up @@ -2285,6 +2303,9 @@ def get_urls(metainfo, name, version, poetry=False):
# Project-URL: Say Thanks!

extra_data = {}
if is_private:
return {}, {}

urls = get_pypi_urls(name, version)

def add_url(_url, _utype=None, _attribute=None):
Expand Down
3 changes: 3 additions & 0 deletions src/packagedcode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,6 @@ def is_simple_path(path):

def is_simple_path_pattern(path):
return path.endswith('*') and path.count('*') == 1

def is_private_package(classifiers):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be in utils, but in the pypi.py

return any('Private ::' in classifier for classifier in classifiers if classifier)
5 changes: 5 additions & 0 deletions tests/packagedcode/data/pypi/develop/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Metadata-Version: 2.1
Name: example_egg
Version: 1.0.0
Classifier: Development Status :: 5 - Production/Stable
Classifier: Private :: Do Not Upload
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[
{
"type": "pypi",
"namespace": null,
"name": "example_egg",
"version": "1.0.0",
"qualifiers": {},
"subpath": null,
"primary_language": "Python",
"description": "",
"release_date": null,
"parties": [],
"keywords": [
"Development Status :: 5 - Production/Stable",
"Private :: Do Not Upload"
],
"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,
"holder": null,
"declared_license_expression": null,
"declared_license_expression_spdx": null,
"license_detections": [],
"other_license_expression": null,
"other_license_expression_spdx": null,
"other_license_detections": [],
"extracted_license_statement": null,
"notice_text": null,
"source_packages": [],
"file_references": [],
"is_private": true,
"is_virtual": false,
"extra_data": {},
"dependencies": [],
"repository_homepage_url": "https://pypi.org/project/example_egg",
"repository_download_url": "https://pypi.org/packages/source/e/example_egg/example_egg-1.0.0.tar.gz",
"api_data_url": "https://pypi.org/pypi/example_egg/1.0.0/json",
"datasource_id": "pypi_egg_info",
"purl": "pkg:pypi/example-egg@1.0.0"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
[
{
"type": "pypi",
"namespace": null,
"name": "titanic_ml",
"version": "0.1.0",
"qualifiers": {},
"subpath": null,
"primary_language": "Python",
"description": "titanic_ml example package",
"release_date": null,
"parties": [
{
"type": "person",
"role": "author",
"name": "Niels Zeilemaker",
"email": "nielszeilemaker@xebia.com",
"url": null
}
],
"keywords": [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Private :: Do Not Upload"
],
"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,
"holder": null,
"declared_license_expression": null,
"declared_license_expression_spdx": null,
"license_detections": [],
"other_license_expression": null,
"other_license_expression_spdx": null,
"other_license_detections": [],
"extracted_license_statement": null,
"notice_text": null,
"source_packages": [],
"file_references": [],
"is_private": true,
"is_virtual": false,
"extra_data": {},
"dependencies": [
{
"purl": "pkg:pypi/pyspark",
"extracted_requirement": null,
"scope": "install",
"is_runtime": true,
"is_optional": false,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {}
},
{
"purl": "pkg:pypi/sklearn",
"extracted_requirement": null,
"scope": "install",
"is_runtime": true,
"is_optional": false,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {}
},
{
"purl": "pkg:pypi/tox",
"extracted_requirement": null,
"scope": "dev",
"is_runtime": true,
"is_optional": true,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {}
},
{
"purl": "pkg:pypi/pre-commit",
"extracted_requirement": null,
"scope": "dev",
"is_runtime": true,
"is_optional": true,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {}
},
{
"purl": "pkg:pypi/bump2version",
"extracted_requirement": null,
"scope": "dev",
"is_runtime": true,
"is_optional": true,
"is_pinned": false,
"is_direct": true,
"resolved_package": {},
"extra_data": {}
}
],
"repository_homepage_url": null,
"repository_download_url": null,
"api_data_url": null,
"datasource_id": "pypi_pyproject_toml",
"purl": "pkg:pypi/titanic-ml@0.1.0"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#Taken from : https://xebia.com/blog/minimal-pyproject-toml-example/

[project]
name = "titanic_ml"
description = "titanic_ml example package"
version = "0.1.0"
authors = [
{ name = "Niels Zeilemaker", email = "nielszeilemaker@xebia.com" }
]
dependencies = [
"pyspark[ml]",
"sklearn"
]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"Private :: Do Not Upload"
]

[project.optional-dependencies]
dev = [
"tox",
"pre-commit",
"bump2version"
]

[build-system]
build-backend = "flit_core.buildapi"
requires = ["flit_core >=3.2,<4"]
10 changes: 10 additions & 0 deletions tests/packagedcode/data/pypi/setup.py/private-classifier-setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from setuptools import setup

setup(
name="example_setup",
version="1.0.0",
classifiers=[
"Development Status :: 5 - Production/Stable",
"Private :: Do Not Upload",
],
)
Loading
Loading