Skip to content

Commit

Permalink
upgrade pip (ali5h#34)
Browse files Browse the repository at this point in the history
* Upgrade pip to 20.1.1 and pip_tools to 5.2.1

Co-authored-by: Michael Krasnyk <[email protected]>
  • Loading branch information
ali5h and oxidase authored Jun 30, 2020
1 parent be6c016 commit e321f5f
Show file tree
Hide file tree
Showing 390 changed files with 27,237 additions and 17,999 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ bazel*
*.pyc
__pycache__

third_party/py/bin/
RECORD

user.bazelrc
wheels
10 changes: 10 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[settings]
force_grid_wrap = 0
include_trailing_comma = true
known_first_party = src
line_length = 88
multi_line_output = 3
reverse_relative = true
skip =third_party
skip_glob=bazel-*
use_parentheses = true
39 changes: 20 additions & 19 deletions src/piptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
import re
import sys

from pip._internal.network.session import PipSession
from pip._internal.req.req_file import parse_requirements
from pip._internal.download import PipSession
from pip._vendor.packaging.requirements import Requirement


def clean_name(name):
# Escape any illegal characters with underscore.
return re.sub("[-.+]", "_", name)


def is_pinned_requirement(ireq):
def is_pinned_requirement(req, editable):
"""
Returns whether an InstallRequirement is a "pinned" requirement.
An InstallRequirement is considered pinned if:
Returns whether a Requirement is a "pinned" requirement.
A Requirement is considered pinned if:
- Is not editable
- It has exactly one specifier
- That specifier is "=="
Expand All @@ -26,27 +27,28 @@ def is_pinned_requirement(ireq):
django~=1.8 # NOT pinned
django==1.* # NOT pinned
"""
if ireq.editable:
if editable:
return False

if ireq.req is None or len(ireq.specifier._specs) != 1:
if len(req.specifier._specs) != 1:
return False

op, version = next(iter(ireq.specifier._specs))._spec
op, version = next(iter(req.specifier._specs))._spec
return (op == "==" or op == "===") and not version.endswith(".*")


def as_tuple(ireq):
def as_tuple(preq):
"""
Pulls out the (name: str, version:str, extras:(str)) tuple from
the pinned InstallRequirement.
the pinned ParsedRequirement.
"""
if not is_pinned_requirement(ireq):
raise TypeError("Expected a pinned InstallRequirement, got {}".format(ireq))
req = Requirement(preq.requirement)
if not is_pinned_requirement(req, preq.is_editable):
raise TypeError("Expected a pinned requirement, got {}".format(req))

name = ireq.name
version = next(iter(ireq.specifier._specs))._spec[1]
extras = tuple(sorted(ireq.extras))
name = req.name
version = next(iter(req.specifier._specs))._spec[1]
extras = tuple(sorted(req.extras))
return name, version, extras


Expand Down Expand Up @@ -129,10 +131,7 @@ def main():
required=True,
)
parser.add_argument(
"--timeout",
help=("Timeout used for pip actions."),
type=int,
required=True,
"--timeout", help=("Timeout used for pip actions."), type=int, required=True,
)
args = parser.parse_args()

Expand All @@ -155,7 +154,9 @@ def main():
)
)
whl_libraries.append(
whl_library(name, extras, repo_name, args.name, sys.executable, args.timeout)
whl_library(
name, extras, repo_name, args.name, sys.executable, args.timeout
)
)

with open(args.output, "w") as _f:
Expand Down
1 change: 1 addition & 0 deletions src/pytest_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

import pytest


Expand Down
4 changes: 2 additions & 2 deletions src/requirements.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pkginfo
pip==19.2.3
pip-tools
pip==20.1.1
pip-tools==5.2.1
setuptools
wheel
mock
41 changes: 21 additions & 20 deletions src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
click==7.0 \
--hash=sha256:2335065e6395b9e67ca716de5f7526736bfa6ceead690adf616d925bdc622b13 \
--hash=sha256:5b94b49521f6456670fdb30cd82a4eca9412788a93fa6dd6df72c94d5a8ff2d7
click==7.1.2 \
--hash=sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a \
--hash=sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc
funcsigs==1.0.2 \
--hash=sha256:330cc27ccbf7f1e992e69fef78261dc7c6569012cf397db8d3de0234e6c937ca \
--hash=sha256:a7bb0f2cf3a3fd1ab2732cb49eba4252c2af4240442415b4abce3b87022a8f50
mock==3.0.5 \
--hash=sha256:83657d894c90d5681d62155c82bda9c1187827525880eda8ff5df4ec813437c3 \
--hash=sha256:d157e52d4e5b938c550f39eb2fd15610db062441a9c2747d3dbfa9298211d0f8
pip-tools==4.3.0 \
--hash=sha256:06efa50b7089b2abbfcf4b47684960538af74669e801e69a557cb8a1c6ad6674 \
--hash=sha256:79e8137a2b96906ccaed0151e1df42daf386d51abb80286173d112b5296a5775
pip-tools==5.2.1 \
--hash=sha256:1690bef5f0f714160c3aedacb03520e2359a78f7f9fa17e574cf8659cf2ef614 \
--hash=sha256:5b4b6e7b6e66357685c73e856296b4792b2d159ff6074729e250e291834bfd9d
pkginfo==1.5.0.1 \
--hash=sha256:7424f2c8511c186cd5424bbf31045b77435b37a8d604990b79d4e70d741148bb \
--hash=sha256:a6d9e40ca61ad3ebd0b72fbadd4fba16e4c0e4df0428c041e01e06eb6ee71f32
six==1.13.0 \
--hash=sha256:1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd \
--hash=sha256:30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66
wheel==0.33.6 \
--hash=sha256:10c9da68765315ed98850f8e048347c3eb06dd81822dc2ab1d4fde9dc9702646 \
--hash=sha256:f4da1763d3becf2e2cd92a14a7c920f0f00eca30fdde9ea992c836685b9faf28

# The following packages are considered to be unsafe in a requirements file:
pip==19.2.3 \
--hash=sha256:340a0ba40fdeb16413914c0fcd8e0b4ebb0bf39a900ec80e11c05d836c05103f \
--hash=sha256:e7a31f147974362e6c82d84b91c7f2bdf57e4d3163d3d454e6c3e71944d67135
setuptools==42.0.2 \
--hash=sha256:c5b372090d7c8709ce79a6a66872a91e518f7d65af97fca78135e1cb10d4b940 \
--hash=sha256:c8abd0f3574bc23afd2f6fd2c415ba7d9e097c8a99b845473b0d957ba1e2dac6
six==1.15.0 \
--hash=sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259 \
--hash=sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced
wheel==0.34.2 \
--hash=sha256:8788e9155fe14f54164c1b9eb0a319d98ef02c160725587ad60f14ddc57b6f96 \
--hash=sha256:df277cb51e61359aba502208d680f90c0493adec6f0e848af94948778aed386e
pip==20.1.1 \
--hash=sha256:27f8dc29387dd83249e06e681ce087e6061826582198a425085e0bf4c1cf3a55 \
--hash=sha256:b27c4dedae8c41aa59108f2fa38bf78e0890e590545bc8ece7cdceb4ba60f6e4
setuptools==44.1.1 \
--hash=sha256:27a714c09253134e60a6fa68130f78c7037e5562c4f21f8f318f2ae900d152d5 \
--hash=sha256:c67aa55db532a0dadc4d2e20ba9961cbd3ccc84d544e9029699822542b5a476b
19 changes: 10 additions & 9 deletions src/whl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import shutil
import sys

import pkginfo
from pip._internal.commands import InstallCommand
from pip._internal.commands import create_command
from pip._vendor import pkg_resources

import pkginfo


# https://github.com/dillon-giacoppo/rules_python_external/blob/master/tools/wheel_wrapper.py
def configure_reproducible_wheels():
"""
Expand Down Expand Up @@ -69,8 +71,8 @@ def install_package(pkg, directory, pip_args):
"--ignore-requires-python",
pkg,
] + pip_args
cmd = InstallCommand()
cmd.run(*cmd.parse_args(pip_args))
cmd = create_command("install")
cmd.main(pip_args)

# need dist-info directory for pkg_resources to be able to find the packages
dist_info = glob.glob(os.path.join(directory, "*.dist-info"))[0]
Expand Down Expand Up @@ -112,7 +114,7 @@ def dependencies(pkg, extra=None):
for dist in pkg.requires_dist:
requirement = pkg_resources.Requirement.parse(dist)
# we replace all underscores with dash, to make package names similiar in all cases
name = requirement.name.replace('_', '-')
name = requirement.name.replace("_", "-")
if extra:
# for extras we don't grab dependencies for the main pkg,
# those are already in the main plg rule
Expand All @@ -124,10 +126,9 @@ def dependencies(pkg, extra=None):
continue

if requirement.extras:
ret = ret | set([
"{}[{}]".format(name, dist_extra)
for dist_extra in requirement.extras
])
ret = ret | set(
["{}[{}]".format(name, dist_extra) for dist_extra in requirement.extras]
)
else:
ret.add(name)

Expand Down
39 changes: 18 additions & 21 deletions tests/test_whl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import os
import unittest

from mock import patch
import pkginfo
from mock import patch

from src import whl

Expand Down Expand Up @@ -46,23 +46,23 @@ def test_whl_with_METADATA_file(self):
)
self.assertEqual(set(whl.dependencies(td)), set())

@patch("platform.python_version", return_value="2.7.13")
@patch("platform.python_version_tuple", return_value=("2", "7"))
def test_mock_whl(self, *args):
td = pkginfo.Wheel(TestData("mock_whl/file/mock-2.0.0-py2.py3-none-any.whl"))
self.assertEqual(set(whl.dependencies(td)), set(["funcsigs", "pbr", "six"]))

@patch("platform.python_version", return_value="3.3.0")
@patch("platform.python_version_tuple", return_value=("3", "3"))
def test_mock_whl_3_3(self, *args):
td = pkginfo.Wheel(TestData("mock_whl/file/mock-2.0.0-py2.py3-none-any.whl"))
self.assertEqual(set(whl.dependencies(td)), set(["pbr", "six"]))

@patch("platform.python_version", return_value="2.7.13")
@patch("platform.python_version_tuple", return_value=("2", "7"))
def test_mock_whl_extras(self, *args):
td = pkginfo.Wheel(TestData("mock_whl/file/mock-2.0.0-py2.py3-none-any.whl"))
self.assertEqual(set(whl.dependencies(td, extra="docs")), set(["sphinx"]))
self.assertEqual(set(whl.dependencies(td, extra="test")), set(["unittest2"]))

@patch("platform.python_version", return_value="3.0.0")
@patch("platform.python_version_tuple", return_value=("3", "0"))
def test_mock_whl_extras_3_0(self, *args):
td = pkginfo.Wheel(TestData("mock_whl/file/mock-2.0.0-py2.py3-none-any.whl"))
self.assertEqual(
Expand All @@ -71,12 +71,11 @@ def test_mock_whl_extras_3_0(self, *args):
)
self.assertEqual(set(whl.dependencies(td, extra="test")), set(["unittest2"]))

@patch("platform.python_version", return_value="2.7.13")
@patch("platform.python_version_tuple", return_value=("2", "7"))
def test_google_cloud_language_whl(self, *args):
td = pkginfo.Wheel(
TestData(
"google_cloud_language_whl/file/"
+ "google_cloud_language-0.29.0-py2.py3-none-any.whl"
"google_cloud_language_whl/file/google_cloud_language-0.29.0-py2.py3-none-any.whl"
)
)
expected_deps = [
Expand All @@ -87,12 +86,11 @@ def test_google_cloud_language_whl(self, *args):
]
self.assertEqual(set(whl.dependencies(td)), set(expected_deps))

@patch("platform.python_version", return_value="3.4.0")
@patch("platform.python_version_tuple", return_value=("3", "4"))
def test_google_cloud_language_whl_3_4(self, *args):
td = pkginfo.Wheel(
TestData(
"google_cloud_language_whl/file/"
+ "google_cloud_language-0.29.0-py2.py3-none-any.whl"
"google_cloud_language_whl/file/google_cloud_language-0.29.0-py2.py3-none-any.whl"
)
)
expected_deps = [
Expand All @@ -102,29 +100,28 @@ def test_google_cloud_language_whl_3_4(self, *args):
]
self.assertEqual(set(whl.dependencies(td)), set(expected_deps))

@patch("platform.python_version", return_value="2.7.13")
@patch("platform.python_version_tuple", return_value=("2", "7"))
def test_pytest_flask_whl(self, *args):
td = pkginfo.Wheel(
TestData(
"pytest_flask_0_14_0_whl/file/"
+ "pytest_flask-0.14.0-py2.py3-none-any.whl"
"pytest_flask_0_14_0_whl/file/pytest_flask-0.14.0-py2.py3-none-any.whl"
)
)
expected_deps = [
'pytest',
'Flask',
'Werkzeug',
"pytest",
"Flask",
"Werkzeug",
]
self.assertEqual(len(whl.dependencies(td)), len(expected_deps))
self.assertEqual(set(whl.dependencies(td)), set(expected_deps))

def test_ruamel_yaml_clib_whl(self):
td = pkginfo.Wheel(
TestData("ruamel_yaml_clib_0_2_0_whl/file/ruamel.yaml.clib-0.2.0-cp27-cp27m-manylinux1_x86_64.whl")
)
self.assertEqual(
set(whl.dependencies(td)), set([])
TestData(
"ruamel_yaml_clib_0_2_0_whl/file/ruamel.yaml.clib-0.2.0-cp27-cp27m-manylinux1_x86_64.whl"
)
)
self.assertEqual(set(whl.dependencies(td)), set([]))


if __name__ == "__main__":
Expand Down
39 changes: 0 additions & 39 deletions third_party/py/Click-7.0.dist-info/LICENSE.txt

This file was deleted.

Loading

0 comments on commit e321f5f

Please sign in to comment.