-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add support for converting pyproject.toml-based Python3 packages. #1982
Open
amdei
wants to merge
14
commits into
jordansissel:main
Choose a base branch
from
amdei:python2deb-great-again
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
4f440c8
Add support for converting pyproject.toml-based Python3 packages.
amdei f916189
Obtain package architecture via hackily hack.
amdei cf5df8b
Fix 'ERROR: The --python option must be placed before the pip subcomm…
amdei c5af917
Handle local package creation via specifying path to setup.py or .tom…
ObjatieGroba bf131b2
Some code beautification's.
amdei 9d7991e
Preserve package author as 'Vendor'.
amdei 1d1a1ab
Fix crash on absence of package author.
amdei d1d442b
Code deduplication.
amdei 0f40b69
Redo input() to prefer Wheel.
amdei 3851171
Proper code reformat.
amdei 02f6e6c
Fix Unknown author apperance.
amdei 908224a
Strip NYI, make messages better.
amdei daf93a9
Del extra loggind.
amdei c86f43e
Some adjustments for pip wheel build
amdei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__all__ = [ "get_metadata_wheel" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import os | ||
import sys | ||
import pkg_resources | ||
import zipfile | ||
from pkginfo import Wheel | ||
import traceback | ||
|
||
import json | ||
|
||
# If you have fixes, let me know. | ||
|
||
class get_metadata_wheel: | ||
wheel_path = None | ||
|
||
def __init__(self, wheel_path): | ||
fqn = os.path.abspath(os.path.normpath(wheel_path)) | ||
if not fqn.endswith('.whl'): | ||
raise ValueError('Wheel file must have .whl extension!') | ||
self.wheel_path = fqn | ||
|
||
@staticmethod | ||
def process_dep(dep): | ||
deps = [] | ||
if hasattr(dep, 'marker') and dep.marker: | ||
# PEP0508 marker present | ||
if not dep.marker.evaluate(): | ||
return deps | ||
|
||
if dep.specs: | ||
for operator, version in dep.specs: | ||
deps.append("%s %s %s" % (dep.project_name, | ||
operator, version)) | ||
else: | ||
deps.append(dep.project_name) | ||
|
||
return deps | ||
|
||
@staticmethod | ||
def get_home_url(project_urls): | ||
res = dict([i.strip() for i in x.split(',')] for x in project_urls) | ||
amdei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if 'Home' in res: | ||
return res.get('Home', None) | ||
return res.get('Homepage', None) | ||
|
||
|
||
def __wheel_root_is_pure(self): | ||
with zipfile.ZipFile(self.wheel_path, mode="r") as archive: | ||
names = archive.namelist() | ||
for name in names: | ||
if name.endswith('.dist-info/WHEEL'): | ||
for line in archive.read(name).split(b"\n"): | ||
line_lower = str(line.decode()).lower().strip() | ||
if line_lower.startswith('root-is-purelib') and line_lower.endswith('true'): | ||
return True | ||
|
||
return False | ||
|
||
|
||
def run(self, output_path): | ||
|
||
fpm_wheel = Wheel(self.wheel_path) | ||
data = { | ||
"name": fpm_wheel.name, | ||
"version": fpm_wheel.version, | ||
"description": fpm_wheel.summary, | ||
"license": fpm_wheel.license, | ||
} | ||
|
||
if fpm_wheel.author: | ||
data["author"] = "%s" % fpm_wheel.author | ||
else: | ||
data["author"] = "Unknown" | ||
|
||
if fpm_wheel.author_email: | ||
data["author"] = data["author"] + " <%s>" % fpm_wheel.author_email | ||
else: | ||
data["author"] = data["author"] + " <unknown@unknown.unknown>" | ||
|
||
|
||
if fpm_wheel.home_page: | ||
data["url"] = fpm_wheel.home_page | ||
else: | ||
data["url"] = self.get_home_url(fpm_wheel.project_urls) | ||
|
||
# @todo Can anyone provide a python package, where fpm_wheel.requires_external would result in 'true'? | ||
if self.__wheel_root_is_pure() and not fpm_wheel.requires_external: | ||
data["architecture"] = "all" | ||
else: | ||
data["architecture"] = "native" | ||
|
||
final_deps = [] | ||
|
||
try: | ||
if fpm_wheel.requires_dist: | ||
for dep in pkg_resources.parse_requirements(fpm_wheel.requires_dist): | ||
final_deps.extend(self.process_dep(dep)) | ||
except Exception as e: | ||
raise | ||
|
||
data["dependencies"] = final_deps | ||
|
||
with open(output_path, "w") as output: | ||
def default_to_str(obj): | ||
""" Fall back to using __str__ if possible """ | ||
# This checks if the class of obj defines __str__ itself, | ||
# so we don't fall back to an inherited __str__ method. | ||
if "__str__" in type(obj).__dict__: | ||
return str(obj) | ||
return json.JSONEncoder.default(json.JSONEncoder(), obj) | ||
|
||
output.write(json.dumps(data, indent=2, sort_keys=True, default=default_to_str)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of pkg_resources is DEPRECATED:
https://setuptools.pypa.io/en/latest/pkg_resources.html