diff --git a/pypi/pip_generate.go b/pypi/pip_generate.go index ada122f..aa7562d 100644 --- a/pypi/pip_generate.go +++ b/pypi/pip_generate.go @@ -30,15 +30,15 @@ const pypiRulesHeader = `# AUTO GENERATED. DO NOT EDIT DIRECTLY. load("%s", "%s") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -_BUILD_FILE_CONTENT=''' +_BUILD_FILE_CONTENT = ''' load("%s", "%s") pyz_library( - name="lib", - srcs=glob(["**/*.py"]), - data = glob(["**/*"], exclude=["**/*.py", "BUILD", "WORKSPACE", "*.whl.zip"]), - pythonroot=".", - visibility=["//visibility:public"], + name = "lib", + srcs = glob(["**/*.py"]), + data = glob(["**/*"], exclude = ["**/*.py", "BUILD", "WORKSPACE", "*.whl.zip"]), + pythonroot = ".", + visibility = ["//visibility:public"], ) ''' ` @@ -100,19 +100,19 @@ func (w *wheelInfo) makeBazelRule(name *string, wheelDir *string) string { output := "" if w.useLocalWheel { output += fmt.Sprintf(" native.filegroup(\n") - output += fmt.Sprintf(" name=\"%s\",\n", *name) - output += fmt.Sprintf(" srcs=[\"%s\"],\n", path.Join(*wheelDir, filepath.Base(w.filePath))) + output += fmt.Sprintf(" name = \"%s\",\n", *name) + output += fmt.Sprintf(" srcs = [\"%s\"],\n", path.Join(*wheelDir, filepath.Base(w.filePath))) // Fixes build error TODO: different type? comment that this is not the right license? - output += fmt.Sprintf(" licenses=[\"notice\"],\n") + output += fmt.Sprintf(" licenses = [\"notice\"],\n") output += fmt.Sprintf(" )\n") } else { output += fmt.Sprintf(" if \"%s\" not in existing_rules:\n", *name) output += fmt.Sprintf(" http_archive(\n") - output += fmt.Sprintf(" name=\"%s\",\n", *name) - output += fmt.Sprintf(" url=\"%s\",\n", w.url) - output += fmt.Sprintf(" sha256=\"%s\",\n", w.sha256) - output += fmt.Sprintf(" build_file_content=_BUILD_FILE_CONTENT,\n") - output += fmt.Sprintf(" type=\"zip\",\n") + output += fmt.Sprintf(" name = \"%s\",\n", *name) + output += fmt.Sprintf(" url = \"%s\",\n", w.url) + output += fmt.Sprintf(" sha256 = \"%s\",\n", w.sha256) + output += fmt.Sprintf(" build_file_content = _BUILD_FILE_CONTENT,\n") + output += fmt.Sprintf(" type = \"zip\",\n") output += fmt.Sprintf(" )\n") } return output @@ -526,12 +526,12 @@ func main() { for _, dependency := range dependencies { fmt.Fprintf(outputBzlFile, " %s(\n", ruleGenerator.libraryRule) - fmt.Fprintf(outputBzlFile, " name=\"%s\",\n", dependency.bazelLibraryName()) + fmt.Fprintf(outputBzlFile, " name = \"%s\",\n", dependency.bazelLibraryName()) if unzipPackages[dependency.name] { - fmt.Fprintf(outputBzlFile, " zip_safe=False,\n") + fmt.Fprintf(outputBzlFile, " zip_safe = False,\n") } - fmt.Fprintf(outputBzlFile, " deps=[\n") + fmt.Fprintf(outputBzlFile, " deps = [\n") for _, dep := range dependency.wheels[0].deps { fmt.Fprintf(outputBzlFile, " \"%s\",\n", pyPIToBazelPackageName(dep)) } @@ -557,8 +557,8 @@ func main() { } // Fixes build error TODO: different type? comment that this is not the right license? - fmt.Fprintf(outputBzlFile, " licenses=[\"notice\"],\n") - fmt.Fprintf(outputBzlFile, " visibility=[\"//visibility:public\"],\n") + fmt.Fprintf(outputBzlFile, " licenses = [\"notice\"],\n") + fmt.Fprintf(outputBzlFile, " visibility = [\"//visibility:public\"],\n") fmt.Fprintf(outputBzlFile, " )\n") // ensure output is reproducible: output extras in the same order @@ -583,16 +583,16 @@ func main() { } fmt.Fprintf(outputBzlFile, " %s(\n", ruleGenerator.libraryRule) - fmt.Fprintf(outputBzlFile, " name=\"%s__%s\",\n", dependency.bazelLibraryName(), extraName) - fmt.Fprintf(outputBzlFile, " deps=[\n") + fmt.Fprintf(outputBzlFile, " name = \"%s__%s\",\n", dependency.bazelLibraryName(), extraName) + fmt.Fprintf(outputBzlFile, " deps = [\n") fmt.Fprintf(outputBzlFile, " \":%s\",\n", dependency.bazelLibraryName()) for _, dep := range extraDeps { fmt.Fprintf(outputBzlFile, " \"%s\",\n", pyPIToBazelPackageName(dep)) } fmt.Fprintf(outputBzlFile, " ],\n") // fmt.Fprintf(outputBzlFile, " # Not the correct license but fixes a build error\n") - fmt.Fprintf(outputBzlFile, " licenses=[\"notice\"],\n") - fmt.Fprintf(outputBzlFile, " visibility=[\"//visibility:public\"],\n") + fmt.Fprintf(outputBzlFile, " licenses = [\"notice\"],\n") + fmt.Fprintf(outputBzlFile, " visibility = [\"//visibility:public\"],\n") fmt.Fprintf(outputBzlFile, " )\n") } } diff --git a/pypi/wheeltool.py b/pypi/wheeltool.py index c04db73..dcc0f7d 100755 --- a/pypi/wheeltool.py +++ b/pypi/wheeltool.py @@ -23,11 +23,10 @@ import pkg_resources from pkg_resources._vendor.packaging import markers import re -import rfc822 +import email import sys import zipfile - def recurse_split_extra(parsed_parts): extra = '' remaining = [] @@ -186,32 +185,31 @@ def expand(self, directory): def _parse_metadata(self, file_object): # the METADATA file is in PKG-INFO format, which is a sequence of RFC822 headers: # https://www.python.org/dev/peps/pep-0241/ - message = rfc822.Message(file_object) + msg = email.message_from_bytes(file_object.read()) # Requires-Dist format: # https://packaging.python.org/specifications/core-metadata/#requires-dist-multiple-use requires_extra = {} extras = set() - for header in message.getallmatchingheaders('Requires-Dist'): - header_parts = header.strip().split(':', 2) - specification = header_parts[1].strip() - - package_and_version = specification - environment_marker = '' - extra = '' - if ';' in specification: - parts = specification.split(';', 2) - package_and_version = parts[0].strip() - environment_marker = parts[1].strip() - - extra, environment_marker = split_extra_from_environment_marker(environment_marker) - - if extra != '': - extras.add(extra) - key = (extra, environment_marker) - requires = requires_extra.get(key, []) - requires.append(package_and_version) - requires_extra[key] = requires + + if msg.get_all('Requires-Dist'): + for specification in msg.get_all('Requires-Dist'): + package_and_version = specification + environment_marker = '' + extra = '' + if ';' in specification: + parts = specification.split(';', 2) + package_and_version = parts[0].strip() + environment_marker = parts[1].strip() + + extra, environment_marker = split_extra_from_environment_marker(environment_marker) + + if extra != '': + extras.add(extra) + key = (extra, environment_marker) + requires = requires_extra.get(key, []) + requires.append(package_and_version) + requires_extra[key] = requires run_requires = [] for (extra, environment_marker), requires in requires_extra.items(): @@ -223,8 +221,8 @@ def _parse_metadata(self, file_object): run_requires.append(value) return { - 'name': message['Name'], - 'version': message['Version'], + 'name': msg['Name'], + 'version': msg['Version'], 'run_requires': run_requires, 'extras': list(extras), } diff --git a/tools/pip_generate-x64-linux b/tools/pip_generate-x64-linux index 9a3859a..2f60ed4 100755 Binary files a/tools/pip_generate-x64-linux and b/tools/pip_generate-x64-linux differ diff --git a/tools/pip_generate-x64-osx b/tools/pip_generate-x64-osx index d86a2ff..2a527a2 100755 Binary files a/tools/pip_generate-x64-osx and b/tools/pip_generate-x64-osx differ