10000 feat: add lower bound checker (#8) · googleapis/python-test-utils@5ebac9f · GitHub
[go: up one dir, main page]

Skip to content

Commit 5ebac9f

Browse files
authored
feat: add lower bound checker (#8)
Add a lower bound checker to be invoked on the command line by client libraries. This accomplishes two things: - Makes it easier to mass update/create constraints files. - Adds another layer of checks to the lower bounds in setup.py / constraints files. See googleapis/synthtool#869 for additional context on the lower bounds work. `lower-bound-checker` is intentionally restrictive on the types of pins it permits in `setup.py` and `constraints.txt`. The tool doesn't try to `pip install` the package. It is assumed that other checks (e.g., setup.py lint, unit tests) will pick up on things like misspelled package names or a version range that cannot be fulfilled. ``` busunkim@busunkim:~/github/python-test-utils$ lower-bound-checker check --help Usage: lower-bound-checker check [OPTIONS] Check that the constraints-file pins to the lower bound specified in package-name's setup.py for each requirement. Requirements: 1. The setup.py pins every requirement in one of the following formats: * foo==1.2.0 * foo>=1.2.0 * foo>=1.2.0, <2.0.0dev * foo<2.0.0dev, >=1.2.0 2. The constraints file pins every requirement to a single version: * foo==1.2.0 3. package-name is already be installed in the environment. Options: --package-name TEXT Name of the package. [required] --constraints-file TEXT Path to constraints file. [required] --help Show this message and exit. ``` **Example Usage:** (for reviewers) - Install this repo from source: `pip install /path/to/repo` - Install another package from source: `pip install /path/to/google-cloud-foo` 1. Check an existing package and constraints file: ``` lower-bound-checker check --package-name google-cloud-foo --constraints-file testing/constraints-3.6.txt ``` 2. Create/update a constraints file: ``` lower-bound-checker update --package-name google-cloud-foo --constraints-file testing/constraints-3.6.txt ```
1 parent 8a3e156 commit 5ebac9f

File tree

11 files changed

+681
-8
lines changed

11 files changed

+681
-8
lines changed

noxfile.py

Lines changed: 63 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,28 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# Generated by synthtool. DO NOT EDIT!
1817

1918
from __future__ import absolute_import
2019
import os
20+
import pathlib
2121
import shutil
2222

2323
import nox
2424

25+
# 'update_lower_bounds' is excluded
26+
nox.options.sessions = [
27+
"lint",
28+
"blacken",
29+
"lint_setup_py",
30+
"unit",
31+
"check_lower_bounds"
32+
]
33+
2534

2635
BLACK_VERSION = "black==19.3b0"
2736
BLACK_PATHS = ["test_utils", "setup.py"]
37+
CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute()
38+
2839

2940
@nox.session(python="3.7")
3041
def lint(session):
@@ -35,9 +46,7 @@ def lint(session):
3546
"""
3647
session.install("flake8", BLACK_VERSION)
3748
session.run(
38-
"black",
39-
"--check",
40-
*BLACK_PATHS,
49+
"black", "--check", *BLACK_PATHS,
4150
)
4251
session.run("flake8", *BLACK_PATHS)
4352

@@ -54,13 +63,60 @@ def blacken(session):
5463
"""
5564
session.install(BLACK_VERSION)
5665
session.run(
57-
"black",
58-
*BLACK_PATHS,
66+
"black", *BLACK_PATHS,
5967
)
6068

6169

6270
@nox.session(python="3.7")
6371
def lint_setup_py(session):
6472
"""Verify that setup.py is valid (including RST check)."""
6573
session.install("docutils", "pygments")
66-
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
74+
session.run("python", "setup.py", "check", "--restructuredtext", "--strict")
75+
76+
77+
@nox.session(python=["3.6", "3.7", "3.8", "3.9"])
78+
def unit(session):
79+
constraints_path = str(
80+
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
81+
)
82+
83+
# Install two fake packages for the lower-bound-checker tests
84+
session.install("-e", "tests/unit/resources/good_package", "tests/unit/resources/bad_package")
85+
86+
session.install("pytest")
87+
session.install("-e", ".", "-c", constraints_path)
88+
89+
# Run py.test against the unit tests.
90+
session.run(
91+
"py.test",
92+
"--quiet",
93+
os.path.join("tests", "unit"),
94+
*session.posargs,
95+
)
96+
97+
@nox.session(python="3.8")
98+
def check_lower_bounds(session):
99+
"""Check lower bounds in setup.py are reflected in constraints file"""
100+
session.install(".")
101+
session.run(
102+
"lower-bound-checker",
103+
"check",
104+
"--package-name",
105+
"google-cloud-testutils",
106+
"--constraints-file",
107+
"testing/constraints-3.6.txt",
108+
)
109+
110+
111+
@nox.session(python="3.8")
112+
def update_lower_bounds(session):
113+
"""Update lower bounds in constraints.txt to match setup.py"""
114+
session.install(".")
115+
session.run(
116+
"lower-bound-checker",
117+
"update",
118+
"--package-name",
119+
"google-cloud-testutils",
120+
"--constraints-file",
121+
"testing/constraints-3.6.txt",
122+
)

setup.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
with io.open(readme_filename, encoding="utf-8") as readme_file:
2525
readme = readme_file.read()
2626

27+
scripts = (
28+
["lower-bound-checker=test_utils.lower_bound_checker.lower_bound_checker:main"],
29+
)
30+
2731
setuptools.setup(
2832
name="google-cloud-testutils",
2933
version=version,
@@ -33,9 +37,15 @@
3337
license="Apache 2.0",
3438
url="https://github.com/googleapis/python-test-utils",
3539
packages=setuptools.PEP420PackageFinder.find(),
40+
entry_points={"console_scripts": scripts},
3641
platforms="Posix; MacOS X; Windows",
3742
include_package_data=True,
38-
install_requires=("google-auth >= 0.4.0", "six"),
43+
install_requires=(
44+
"google-auth >= 0.4.0",
45+
"six>=1.9.0",
46+
"click>=7.0.0",
47+
"packaging>=19.0",
48+
),
3949
python_requires=">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*",
4050
classifiers=[
4151
"Development Status :: 4 - Beta",

test_utils/lower_bound_checker/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)
0