utils/scanpypi: workaround for pypi project names
v2 cover utils/scanpypi: workaround for pypi project names
I want to propuse this patch and hope others find it useful. While using scanpypi I noticed that for smmap2 package the modified .mk .hash files where not correct, since smmap2 pypi project is just a mirror of smmap and has different revision and hashes. I realized why the problem exist just by reading the commit history of smmap2 and saw Thomas Petazzoni's remark in commit: 8bc8f4c4161ddfd255615ce0962b570da20c4148. The same is valid for gitdb2 package. To avoid this issue in the future for this packages and others (as I'm sure there are similar cases), get the pypi name from the .mk file if it exist for buildroot packages that have a different name compared to the pypi project name (e.g. smmap2 -> smmap). Since there is no intention to change the buildroot package name, this is a solution in order to use the scanpypi utility for this packages and still get correct generated files.
Other packages can be added in the dictionary as needed.
This solution implementation was suggested by Arnout Vandecappelle in his reply to my initial workaround proposal.
Changes in v2:
- Implement solution suggested by Arnout Vandecappelle.
- Link to v1: https://lore.kernel.org/all/[email protected]/
Flaviu Nistor (1):
utils/scanpypi: workaround for pypi project names
utils/scanpypi | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
Signature · 6 lines
2.34.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH v2 1/1 utils/scanpypi: workaround for pypi project names
Get the pypi name from the .mk file if it exist. This solves an issue in cases when there is a different buildroot package name compared to the pypi project name (e.g. smmap2 -> smmap). Since it is not intended to change the buildroot package name, this is a workaround in order to use the scanpypi utility for this packages and still get correct generated files.
--- utils/scanpypi | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
utils/scanpypi +20 -3
@@ -216,8 +216,25 @@ class BuildrootPackage(): """ Fetch a package's metadata from the python package index """ + # If a .mk file already exists for this package, try to extract the + # upstream PyPI name from the _SOURCE variable. This handles cases + # where the Buildroot package name differs from the PyPI project name + # (e.g. smmap2 buildroot package is smmap on PyPI). + buildroot_package_folder = os.path.join('package', self.buildroot_name) + pypi_name = self.real_name + mk_file = os.path.join(buildroot_package_folder, self.buildroot_name + '.mk') + if os.path.isfile(mk_file): + source_re = re.compile(r'^' + self.mk_name + r'_SOURCE\s*=\s*(.+)$') + with open(mk_file) as mk_fh: + for line in mk_fh: + match = source_re.match(line) + if match: + value = match.group(1).strip() + if '-$(' in value: + pypi_name = value.split('-$(')[0] + break self.metadata_url = 'https://pypi.org/pypi/{pkg}/json'.format( - pkg=self.real_name) + pkg=pypi_name) try: pkg_json = urllib.request.urlopen(self.metadata_url).read().decode() except urllib.error.HTTPError as error:
@@ -225,13 +242,13 @@ class BuildrootPackage(): print('ERROR: Could not find package {pkg}.\n' 'Check syntax inside the python package index:\n' 'https://pypi.python.org/pypi/ ' - .format(pkg=self.real_name)) + .format(pkg=pypi_name)) raise except urllib.error.URLError: print('ERROR: Could not find package {pkg}.\n' 'Check syntax inside the python package index:\n' 'https://pypi.python.org/pypi/ ' - .format(pkg=self.real_name)) + .format(pkg=pypi_name)) raise self.metadata = json.loads(pkg_json) self.version = self.metadata['info']['version']
Signature · 6 lines
2.34.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot