Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Jul 21, 2021. It is now read-only.

Commit c597bfc

Browse filesBrowse files
author
Doug Greiman
committed
Merge github.com:bazelbuild/rules_python into dgreiman/issue17
2 parents 1c1f5cd + 33da846 commit c597bfc
Copy full SHA for c597bfc

File tree

4 files changed

+38
-6
lines changed
Filter options

4 files changed

+38
-6
lines changed

‎WORKSPACE

Copy file name to clipboardExpand all lines: WORKSPACE
+10-1
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,23 @@ http_file(
6666
)
6767

6868
http_file(
69-
name = "futures_whl",
69+
name = "futures_3_1_1_whl",
7070
sha256 = "c4884a65654a7c45435063e14ae85280eb1f111d94e542396717ba9828c4337f",
7171
# From https://pypi.python.org/pypi/futures
7272
url = ("https://pypi.python.org/packages/a6/1c/" +
7373
"72a18c8c7502ee1b38a604a5c5243aa8c2a64f4bba4e6631b1b8972235dd/" +
7474
"futures-3.1.1-py2-none-any.whl"),
7575
)
7676

77+
http_file(
78+
name = "futures_2_2_0_whl",
79+
sha256 = "9fd22b354a4c4755ad8c7d161d93f5026aca4cfe999bd2e53168f14765c02cd6",
80+
# From https://pypi.python.org/pypi/futures/2.2.0
81+
url = ("https://pypi.python.org/packages/d7/1d/" +
82+
"68874943aa37cf1c483fc61def813188473596043158faa6511c04a038b4/" +
83+
"futures-2.2.0-py2.py3-none-any.whl"),
84+
)
85+
7786
http_file(
7887
name = "mock_whl",
7988
sha256 = "5ce3c71c5545b472da17b72268978914d0252980348636840bd34a00b5cc96c1",

‎rules_python/BUILD

Copy file name to clipboardExpand all lines: rules_python/BUILD
+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ py_test(
2626
name = "whl_test",
2727
srcs = ["whl_test.py"],
2828
data = [
29-
"@futures_whl//file",
29+
"@futures_3_1_1_whl//file",
30+
"@futures_2_2_0_whl//file",
3031
"@grpc_whl//file",
3132
"@mock_whl//file",
3233
],

‎rules_python/whl.py

Copy file name to clipboardExpand all lines: rules_python/whl.py
+16-3
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,15 @@ def metadata(self):
5757
# Extract the structured data from metadata.json in the WHL's dist-info
5858
# directory.
5959
with zipfile.ZipFile(self.path(), 'r') as whl:
60-
with whl.open(os.path.join(self._dist_info(), 'metadata.json')) as f:
61-
return json.loads(f.read().decode("utf-8"))
60+
# first check for metadata.json
61+
try:
62+
with whl.open(os.path.join(self._dist_info(), 'metadata.json')) as f:
63+
return json.loads(f.read().decode("utf-8"))
64+
except KeyError:
65+
pass
66+
# fall back to METADATA file (https://www.python.org/dev/peps/pep-0427/)
67+
with whl.open(os.path.join(self._dist_info(), 'METADATA')) as f:
68+
return self._parse_metadata(f.read().decode("utf-8"))
6269

6370
def name(self):
6471
return self.metadata().get('name')
@@ -86,6 +93,12 @@ def expand(self, directory):
8693
with zipfile.ZipFile(self.path(), 'r') as whl:
8794
whl.extractall(directory)
8895

96+
# _parse_metadata parses METADATA files according to https://www.python.org/dev/peps/pep-0314/
97+
def _parse_metadata(self, content):
98+
# TODO: handle fields other than just name
99+
name_pattern = re.compile('Name: (.*)')
100+
return { 'name': name_pattern.search(content).group(1) }
101+
89102

90103
parser = argparse.ArgumentParser(
91104
description='Unpack a WHL file as a py_library.')
@@ -126,6 +139,6 @@ def main():
126139
'requirement("%s")' % d
127140
for d in whl.dependencies()
128141
])))
129-
142+
130143
if __name__ == '__main__':
131144
main()

‎rules_python/whl_test.py

Copy file name to clipboardExpand all lines: rules_python/whl_test.py
+10-1
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,23 @@ def test_grpc_whl(self):
3535
self.assertEqual('pypi__grpcio_1_6_0', wheel.repository_name())
3636

3737
def test_futures_whl(self):
38-
td = TestData('futures_whl/file/futures-3.1.1-py2-none-any.whl')
38+
td = TestData('futures_3_1_1_whl/file/futures-3.1.1-py2-none-any.whl')
3939
wheel = whl.Wheel(td)
4040
self.assertEqual(wheel.name(), 'futures')
4141
self.assertEqual(wheel.distribution(), 'futures')
4242
self.assertEqual(wheel.version(), '3.1.1')
4343
self.assertEqual(set(wheel.dependencies()), set())
4444
self.assertEqual('pypi__futures_3_1_1', wheel.repository_name())
4545

46+
def test_whl_with_METADATA_file(self):
47+
td = TestData('futures_2_2_0_whl/file/futures-2.2.0-py2.py3-none-any.whl')
48+
wheel = whl.Wheel(td)
49+
self.assertEqual(wheel.name(), 'futures')
50+
self.assertEqual(wheel.distribution(), 'futures')
51+
self.assertEqual(wheel.version(), '2.2.0')
52+
self.assertEqual(set(wheel.dependencies()), set())
53+
self.assertEqual('pypi__futures_2_2_0', wheel.repository_name())
54+
4655
def test_mock_whl(self):
4756
td = TestData('mock_whl/file/mock-2.0.0-py2.py3-none-any.whl')
4857
wheel = whl.Wheel(td)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.