diff options
| author | Alex Grönholm <alex.gronholm@nextday.fi> | 2021-12-24 01:27:26 +0200 |
|---|---|---|
| committer | Alex Grönholm <alex.gronholm@nextday.fi> | 2021-12-24 01:45:01 +0200 |
| commit | 5eb690c72ea59bc0f8a2fa34d3993ebe3dbe0d38 (patch) | |
| tree | dff2a2103314f0fe6c5cc53b91a120f59edf78d3 /src/wheel/metadata.py | |
| parent | 64d0b8d779b5b41bacea2ef3b59f3e06f0e683ed (diff) | |
| download | wheel-git-5eb690c72ea59bc0f8a2fa34d3993ebe3dbe0d38.tar.gz | |
Adopted black and reformatted the codebase to match
Diffstat (limited to 'src/wheel/metadata.py')
| -rw-r--r-- | src/wheel/metadata.py | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/src/wheel/metadata.py b/src/wheel/metadata.py index 37efa74..ace796d 100644 --- a/src/wheel/metadata.py +++ b/src/wheel/metadata.py @@ -12,15 +12,15 @@ from .pkginfo import read_pkg_info def requires_to_requires_dist(requirement): """Return the version specifier for a requirement in PEP 345/566 fashion.""" - if getattr(requirement, 'url', None): + if getattr(requirement, "url", None): return " @ " + requirement.url requires_dist = [] for op, ver in requirement.specs: requires_dist.append(op + ver) if not requires_dist: - return '' - return " (%s)" % ','.join(sorted(requires_dist)) + return "" + return " (%s)" % ",".join(sorted(requires_dist)) def convert_requirements(requirements): @@ -36,30 +36,30 @@ def convert_requirements(requirements): def generate_requirements(extras_require): """ - Convert requirements from a setup()-style dictionary to ('Requires-Dist', 'requirement') - and ('Provides-Extra', 'extra') tuples. + Convert requirements from a setup()-style dictionary to + ('Requires-Dist', 'requirement') and ('Provides-Extra', 'extra') tuples. extras_require is a dictionary of {extra: [requirements]} as passed to setup(), using the empty extra {'': [requirements]} to hold install_requires. """ for extra, depends in extras_require.items(): - condition = '' - extra = extra or '' - if ':' in extra: # setuptools extra:condition syntax - extra, condition = extra.split(':', 1) + condition = "" + extra = extra or "" + if ":" in extra: # setuptools extra:condition syntax + extra, condition = extra.split(":", 1) extra = pkg_resources.safe_extra(extra) if extra: - yield 'Provides-Extra', extra + yield "Provides-Extra", extra if condition: condition = "(" + condition + ") and " condition += "extra == '%s'" % extra if condition: - condition = ' ; ' + condition + condition = " ; " + condition for new_req in convert_requirements(depends): - yield 'Requires-Dist', new_req + condition + yield "Requires-Dist", new_req + condition def pkginfo_to_metadata(egg_info_path, pkginfo_path): @@ -67,26 +67,27 @@ def pkginfo_to_metadata(egg_info_path, pkginfo_path): Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format """ pkg_info = read_pkg_info(pkginfo_path) - pkg_info.replace_header('Metadata-Version', '2.1') + pkg_info.replace_header("Metadata-Version", "2.1") # Those will be regenerated from `requires.txt`. - del pkg_info['Provides-Extra'] - del pkg_info['Requires-Dist'] - requires_path = os.path.join(egg_info_path, 'requires.txt') + del pkg_info["Provides-Extra"] + del pkg_info["Requires-Dist"] + requires_path = os.path.join(egg_info_path, "requires.txt") if os.path.exists(requires_path): with open(requires_path) as requires_file: requires = requires_file.read() - parsed_requirements = sorted(pkg_resources.split_sections(requires), - key=lambda x: x[0] or '') + parsed_requirements = sorted( + pkg_resources.split_sections(requires), key=lambda x: x[0] or "" + ) for extra, reqs in parsed_requirements: for key, value in generate_requirements({extra: reqs}): if (key, value) not in pkg_info.items(): pkg_info[key] = value - description = pkg_info['Description'] + description = pkg_info["Description"] if description: pkg_info.set_payload(dedent_description(pkg_info)) - del pkg_info['Description'] + del pkg_info["Description"] return pkg_info @@ -98,8 +99,7 @@ def pkginfo_unicode(pkg_info, field): if not isinstance(text, str): for item in pkg_info.raw_items(): if item[0].lower() == field: - text = item[1].encode('ascii', 'surrogateescape') \ - .decode('utf-8') + text = item[1].encode("ascii", "surrogateescape").decode("utf-8") break return text @@ -109,25 +109,28 @@ def dedent_description(pkg_info): """ Dedent and convert pkg_info['Description'] to Unicode. """ - description = pkg_info['Description'] + description = pkg_info["Description"] # Python 3 Unicode handling, sorta. surrogates = False if not isinstance(description, str): surrogates = True - description = pkginfo_unicode(pkg_info, 'Description') + description = pkginfo_unicode(pkg_info, "Description") description_lines = description.splitlines() - description_dedent = '\n'.join( + description_dedent = "\n".join( # if the first line of long_description is blank, # the first line here will be indented. - (description_lines[0].lstrip(), - textwrap.dedent('\n'.join(description_lines[1:])), - '\n')) + ( + description_lines[0].lstrip(), + textwrap.dedent("\n".join(description_lines[1:])), + "\n", + ) + ) if surrogates: - description_dedent = description_dedent \ - .encode("utf8") \ - .decode("ascii", "surrogateescape") + description_dedent = description_dedent.encode("utf8").decode( + "ascii", "surrogateescape" + ) return description_dedent |
