Skip to content

Commit faa9286

Browse files
committed
Report metadata from setup.cfg #2912 #2929
* Yield dependencies properly Signed-off-by: Jono Yang <[email protected]>
1 parent 24458c5 commit faa9286

File tree

42 files changed

+1206
-540
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1206
-540
lines changed

src/packagedcode/npm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ def assemble(cls, package_data, resource, codebase):
106106

107107
for sibling in package_resource.siblings(codebase):
108108
if sibling.name in datafile_name_patterns:
109-
yield_dependencies_from_package_resource(sibling, package_uid)
109+
yield from yield_dependencies_from_package_resource(sibling, package_uid)
110110

111111
if package_uid not in sibling.for_packages:
112112
sibling.for_packages.append(package_uid)
113113
sibling.save(codebase)
114114
yield sibling
115115
else:
116116
# we do not have a package.json
117-
yield_dependencies_from_package_resource(resource)
117+
yield from yield_dependencies_from_package_resource(resource)
118118

119119
@classmethod
120120
def walk_npm(cls, resource, codebase, depth=0):
@@ -134,7 +134,7 @@ def walk_npm(cls, resource, codebase, depth=0):
134134

135135
if child.is_dir:
136136
depth += 1
137-
for subchild in cls.walk_skip(child, codebase, depth=depth):
137+
for subchild in cls.walk_npm(child, codebase, depth=depth):
138138
yield subchild
139139

140140

src/packagedcode/pypi.py

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import re
1717
import sys
1818
import zipfile
19+
from configparser import ConfigParser
20+
from io import StringIO
1921
from pathlib import Path
2022

2123
import dparse2
@@ -178,13 +180,14 @@ def assemble(cls, package_data, resource, codebase):
178180

179181
for sibling in package_resource.siblings(codebase):
180182
if sibling.name in datafile_name_patterns:
181-
yield_dependencies_from_package_resource(sibling, package_uid)
183+
yield from yield_dependencies_from_package_resource(sibling, package_uid)
184+
182185
if package_uid not in sibling.for_packages:
183186
sibling.for_packages.append(package_uid)
184187
sibling.save(codebase)
185188
yield sibling
186189
else:
187-
yield_dependencies_from_package_resource(resource)
190+
yield from yield_dependencies_from_package_resource(resource)
188191

189192
@classmethod
190193
def assign_package_to_resources(cls, package, resource, codebase):
@@ -591,6 +594,63 @@ class SetupCfgHandler(BaseExtractedPythonLayout):
591594
description = 'Python setup.cfg'
592595
documentation_url = 'https://peps.python.org/pep-0390/'
593596

597+
@classmethod
598+
def parse(cls, location):
599+
file_name = fileutils.file_name(location)
600+
601+
with open(location) as f:
602+
content = f.read()
603+
604+
metadata = {}
605+
parser = ConfigParser()
606+
parser.readfp(StringIO(content))
607+
for section in parser.values():
608+
if section.name == 'metadata':
609+
options = (
610+
'name',
611+
'version',
612+
'license',
613+
'url',
614+
'author',
615+
'author_email',
616+
)
617+
for name in options:
618+
content = section.get(name)
619+
if not content:
620+
continue
621+
metadata[name] = content
622+
623+
parties = []
624+
author = metadata.get('author')
625+
if author:
626+
parties = [
627+
models.Party(
628+
type=models.party_person,
629+
name=author,
630+
role='author',
631+
email=metadata.get('author_email'),
632+
)
633+
]
634+
635+
dependency_type = get_dparse2_supported_file_name(file_name)
636+
if not dependency_type:
637+
return
638+
639+
dependencies = parse_with_dparse2(
640+
location=location,
641+
file_name=dependency_type,
642+
)
643+
yield models.PackageData(
644+
datasource_id=cls.datasource_id,
645+
type=cls.default_package_type,
646+
name=metadata.get('name'),
647+
version=metadata.get('version'),
648+
parties=parties,
649+
homepage_url=metadata.get('url'),
650+
primary_language=cls.default_primary_language,
651+
dependencies=dependencies,
652+
)
653+
594654

595655
class PipfileHandler(BaseDependencyFileHandler):
596656
datasource_id = 'pipfile'

src/packagedcode/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,4 @@ def yield_dependencies_from_package_resource(resource, package_uid=None):
206206
from packagedcode import models
207207
for pkg_data in resource.package_data:
208208
pkg_data = models.PackageData.from_dict(pkg_data)
209-
yield_dependencies_from_package_data(pkg_data, resource.location, package_uid)
209+
yield from yield_dependencies_from_package_data(pkg_data, resource.path, package_uid)

tests/packagedcode/data/instance/pypi/LICENSE.rst

Lines changed: 0 additions & 28 deletions
This file was deleted.

tests/packagedcode/data/instance/pypi/METADATA

Lines changed: 0 additions & 110 deletions
This file was deleted.

tests/packagedcode/data/instance/pypi/README.rst

Lines changed: 0 additions & 80 deletions
This file was deleted.

tests/packagedcode/data/instance/pypi/tox.ini

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)