Skip to content
This repository has been archived by the owner on Apr 18, 2019. It is now read-only.

Python3 upgrade #49

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions pypi/pip_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
'''
`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
}
Expand All @@ -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
Expand All @@ -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")
}
}
Expand Down
48 changes: 23 additions & 25 deletions pypi/wheeltool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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():
Expand All @@ -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),
}
Expand Down
Binary file modified tools/pip_generate-x64-linux
Binary file not shown.
Binary file modified tools/pip_generate-x64-osx
Binary file not shown.