-
-
Notifications
You must be signed in to change notification settings - Fork 28
Add sdist support #31
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
Changes from 6 commits
0a489ec
291a6a0
1cbebd5
e7ec8f7
a6cb7d4
a04a634
03b7b1c
6e7391e
2b8134a
065bdce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
| from pathlib import Path | ||
|
|
||
| import dparse2 | ||
| import packaging | ||
| import pip_requirements_parser | ||
| import pkginfo2 | ||
| from commoncode import fileutils | ||
|
|
@@ -452,8 +453,9 @@ def parse_metadata(location, datasource_id, package_type): | |
| type=package_type, | ||
| primary_language='Python', | ||
| name=name, | ||
| version=version, | ||
| description=get_description(meta, location), | ||
| version=version, #TODO: https://github.com/nexB/scancode-toolkit/issues/3014 | ||
| # description=get_description(meta, location), | ||
| description = "", | ||
| declared_license=get_declared_license(meta), | ||
| keywords=get_keywords(meta), | ||
| parties=get_parties(meta), | ||
|
|
@@ -684,10 +686,17 @@ def parse(cls, location): | |
|
|
||
| metadata = {} | ||
| parser = ConfigParser() | ||
| dependent_packages = [] | ||
| with open(location) as f: | ||
| parser.read_file(f) | ||
|
|
||
| for section in parser.values(): | ||
| if section.name == 'options': | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You likely want to add also the legacy "setup_requires" and "test_requires" as well as the "python_requires"
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pombredanne can you provide me some sample setup.cfg file with legacy "setup_requires", "test_requires", "python_requires"
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See https://github.com/search?l=INI&q="setup_requires"&type=Code and https://github.com/karpierz/QQt/blob/930e22d9612f814fa242b1547ad037037ef6b5c7/setup.cfg Other notes:
|
||
| reqs = list(get_requirement_from_section(section=section, sub_section="install_requires")) | ||
| dependent_packages.extend(cls.parse_reqs(reqs, "install")) | ||
| if section.name == "options.extras_require": | ||
| for sub_section in section: | ||
| reqs = list(get_requirement_from_section(section=section, sub_section=sub_section)) | ||
| dependent_packages.extend(cls.parse_reqs(reqs, sub_section)) | ||
| if section.name == 'metadata': | ||
| options = ( | ||
| 'name', | ||
|
|
@@ -719,10 +728,6 @@ def parse(cls, location): | |
| if not dependency_type: | ||
| return | ||
|
|
||
| dependencies = parse_with_dparse2( | ||
|
TG1999 marked this conversation as resolved.
|
||
| location=location, | ||
| file_name=dependency_type, | ||
| ) | ||
| yield models.PackageData( | ||
| datasource_id=cls.datasource_id, | ||
| type=cls.default_package_type, | ||
|
|
@@ -731,9 +736,37 @@ def parse(cls, location): | |
| parties=parties, | ||
| homepage_url=metadata.get('url'), | ||
| primary_language=cls.default_primary_language, | ||
| dependencies=dependencies, | ||
| dependencies=dependent_packages, | ||
| ) | ||
|
|
||
| @classmethod | ||
| def parse_reqs(cls, reqs, scope): | ||
| """ | ||
| Parse a list of requirements and return a list of dependencies | ||
| """ | ||
| dependent_packages = [] | ||
|
TG1999 marked this conversation as resolved.
|
||
| for req in reqs: | ||
| is_resolved = False | ||
| req_parsed = packaging.requirements.Requirement(str(req)) | ||
| name = canonicalize_name(req_parsed.name) | ||
| purl = PackageURL(type="pypi", name=name) | ||
| specifiers = req_parsed.specifier._specs | ||
| if len(specifiers) == 1: | ||
| specifier = list(specifiers)[0] | ||
| if specifier.operator in ('==', '==='): | ||
| is_resolved = True | ||
| purl = purl._replace(version=specifier.version) | ||
| dependent_packages.append( | ||
| models.DependentPackage( | ||
| purl=str(purl), | ||
| scope=scope, | ||
| is_runtime=True, | ||
| is_optional=False, | ||
| is_resolved=is_resolved, | ||
| extracted_requirement=req | ||
| ) | ||
| ) | ||
| return dependent_packages | ||
|
|
||
| class PipfileHandler(BaseDependencyFileHandler): | ||
| datasource_id = 'pipfile' | ||
|
|
@@ -1017,10 +1050,11 @@ def get_classifiers(metainfo): | |
| license_classifiers = [] | ||
| other_classifiers = [] | ||
| for classifier in classifiers: | ||
| if classifier.startswith('License'): | ||
| license_classifiers.append(classifier) | ||
| else: | ||
| other_classifiers.append(classifier) | ||
| if classifier: | ||
| if classifier.startswith('License'): | ||
| license_classifiers.append(classifier) | ||
| else: | ||
| other_classifiers.append(classifier) | ||
| return license_classifiers, other_classifiers | ||
|
|
||
|
|
||
|
|
@@ -1897,3 +1931,28 @@ def compute_normalized_license(declared_license): | |
|
|
||
| if detected_licenses: | ||
| return combine_expressions(detected_licenses) | ||
|
|
||
|
|
||
| def get_requirement_from_section(section, sub_section): | ||
|
TG1999 marked this conversation as resolved.
|
||
| """ | ||
| Generate requirements from the `sub_section` | ||
|
TG1999 marked this conversation as resolved.
Outdated
|
||
| """ | ||
| content = section.get(sub_section) or "" | ||
| for req in content.splitlines(): | ||
|
TG1999 marked this conversation as resolved.
Outdated
|
||
| if req: | ||
| #pytest-mypy >= 0.9.1; \ | ||
| req = req.replace("; \\", "") | ||
| # pip>=19.1 # For proper file:// URLs support. | ||
| if "#" in req: | ||
| req , _ = req.rsplit("#") | ||
| #pure-eval; black; tox | ||
|
TG1999 marked this conversation as resolved.
Outdated
|
||
| req_split_by_semi_colon = req.split(";") | ||
|
TG1999 marked this conversation as resolved.
Outdated
|
||
| req_split_by_semi_colon = [req.strip() for req in req_split_by_semi_colon if req] | ||
| if len(req_split_by_semi_colon) >= 2 and not(req_split_by_semi_colon[1].startswith("python_version") # pip>=19.1 ;python_version > 3.7 | ||
| or req_split_by_semi_colon[1].startswith("sys_platform") # pip>=19.1 ;sys_platform = "Windows" | ||
| or req_split_by_semi_colon[1].startswith("platform_system") # pip>=19.1 ;platform_system = "Windows" | ||
| or req_split_by_semi_colon[1].startswith("platform_python_implementation")):#pytest-black>=0.3.7; platform_python_implementation != "PyPy" | ||
| for temp_req in req_split_by_semi_colon: | ||
| yield temp_req | ||
| else: | ||
| yield req | ||
Uh oh!
There was an error while loading. Please reload this page.