Skip to content

Commit f2a3ea0

Browse files
committed
enhance: use user lockfiles for tools
We create new resolves for each tool instead of using the implicit tool resolve which has been deprecated. Now all of the tool requirements are defined in //BUILD.tools instead of //pants.toml lockfile regen will go in the next commit.
1 parent 4c2bf64 commit f2a3ea0

3 files changed

Lines changed: 113 additions & 40 deletions

File tree

BUILD.tools

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# This BUILD file has requirements for most of the tools resolves
2+
3+
python_requirement(
4+
name="bandit-reqs",
5+
resolve="bandit",
6+
requirements=[
7+
"bandit==1.7.0",
8+
"setuptools",
9+
"GitPython==3.1.18",
10+
# bandit needs stevedore which needs importlib-metadata<5
11+
# see: https://github.com/PyCQA/bandit/pull/952
12+
"importlib-metadata<5;python_version<'3.8'",
13+
],
14+
)
15+
16+
python_requirement(
17+
name="black-reqs",
18+
resolve="black",
19+
requirements=[
20+
"black==22.3.0",
21+
"typing-extensions>=3.10.0.0;python_version<'3.10'",
22+
],
23+
)
24+
25+
python_requirement(
26+
name="flake8-reqs",
27+
resolve="flake8",
28+
requirements=[
29+
"flake8==4.0.1", # st2flake8 does not support flake8 v5
30+
# license check plugin
31+
"st2flake8==0.1.0", # TODO: remove in favor of regex-lint or preamble
32+
],
33+
)
34+
35+
# for pants-plugins, see //pants-plugins/BUILD
36+
# for pylint, see //pylint_plugins/BUILD
37+
38+
python_requirement(
39+
name="pytest-reqs",
40+
resolve="pytest",
41+
requirements=[
42+
"pytest==7.0.1", # copied from https://www.pantsbuild.org/v2.14/docs/reference-pytest#version
43+
"pytest-benchmark[histogram]==3.4.1",
44+
# "pytest-timer[colorama]",
45+
"pytest-icdiff",
46+
"pygments",
47+
# "pytest-timeout",
48+
# "pytest-mock",
49+
"pytest-cov>=2.12,!=2.12.1,<3.1",
50+
"pytest-xdist>=2.5,<3",
51+
],
52+
)
53+
54+
python_requirement(
55+
name="setuptools-reqs",
56+
resolve="setuptools",
57+
requirements=[
58+
# setuptools 59.7 (at least) does not support python 3.6
59+
"setuptools>=50.3.0,<59.0",
60+
"wheel>=0.35.1,<0.38",
61+
],
62+
)
63+
64+
python_requirement(
65+
name="twine-reqs",
66+
resolve="twine",
67+
requirements=[
68+
"twine>=3.7.1,<3.8",
69+
"colorama>=0.4.3",
70+
],
71+
)

pants.toml

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,37 @@ interpreter_constraints = [
110110
# python_distributions needs a single constraint (vs one line per python version).
111111
# officially, we exclude 3.7 support, but that adds unnecessary complexity: "CPython>=3.6,!=3.7.*,<3.9",
112112
"CPython>=3.6,<3.9",
113+
# NB: constraints for tools defined below
113114
]
114115

115116
[python.resolves]
117+
# st2 is the primary resolve
116118
st2 = "lockfiles/st2.lock"
117-
pylint_plugins = "lockfiles/pylint_plugins.lock" # lockfiles/pylint.lock should have same contents
118-
pants-plugins = "lockfiles/pants-plugins.lock"
119+
# tool and misc other resolves (for most, see //BUILD.tools)
120+
bandit = "lockfiles/bandit.lock"
121+
black = "lockfiles/black.lock"
122+
flake8 = "lockfiles/flake8.lock"
123+
pants-plugins = "lockfiles/pants-plugins.lock" # see //pants-plugins/BUILD
124+
pylint = "lockfiles/pylint.lock" # see //pylint_plugins/BUILD
125+
pytest = "lockfiles/pytest.lock"
126+
setuptools = "lockfiles/setuptools.lock"
127+
twine = "lockfiles/twine.lock"
119128

120129
[python.resolves_to_interpreter_constraints]
130+
# for tools, we have to include constraints for st2 and pants-plugins
131+
bandit = ["CPython>=3.6,<3.10"]
132+
black = ["CPython>=3.6.2,<3.10"] # black doesn't support <3.6.2
133+
flake8 = ["CPython>=3.6,<3.10"]
121134
pants-plugins = [
122135
# this should match the pants interpreter_constraints:
123136
# https://github.com/pantsbuild/pants/blob/2.14.x/pants.toml#L125
124137
# See: https://www.pantsbuild.org/docs/prerequisites
125138
"CPython>=3.7,<3.10",
126139
]
140+
pylint = ["CPython>=3.6,<3.10"]
141+
pytest = ["CPython>=3.6,<3.10"]
142+
setuptools = ["CPython>=3.6,<3.10"]
143+
twine = ["CPython>=3.6,<3.10"]
127144

128145
[python.resolves_to_constraints_file]
129146
# Our direct requirements are in requirements-pants.txt;
@@ -158,34 +175,25 @@ ambiguity_resolution = "by_source_root"
158175
generate_setup_default = true # true by default
159176

160177
[bandit]
161-
lockfile = "lockfiles/bandit.lock"
162-
version = "bandit==1.7.0"
163178
args = [
164179
"-lll", # only HIGH severity level
165180
"--exclude",
166181
"build,dist",
167182
"--quiet", # only show output in the case of an error
168183
]
169-
extra_requirements = [
170-
"setuptools",
171-
# bandit needs stevedore which needs importlib-metadata<5
172-
# see: https://github.com/PyCQA/bandit/pull/952
173-
"importlib-metadata<5;python_version<'3.8'",
174-
]
184+
install_from_resolve = "bandit"
185+
requirements = ["bandit", "setuptools", "GitPython"] # versions in BUILD.tools
175186

176187
[black]
177-
lockfile = "lockfiles/black.lock"
178-
version = "black==22.3.0"
179-
interpreter_constraints = [
180-
"CPython>=3.6.2,<3.9",
181-
]
188+
install_from_resolve = "black"
189+
requirements = ["black"] # version in BUILD.tools
182190

183191
[flake8]
184-
lockfile = "lockfiles/flake8.lock"
185-
version = "flake8==4.0.1" # st2flake8 does not support flake8 v5
186-
extra_requirements = [
192+
install_from_resolve = "flake8"
193+
requirements = [ # versions in BUILD.tools
194+
"flake8",
187195
# license check plugin
188-
"st2flake8==0.1.0", # TODO: remove in favor of regex-lint
196+
"st2flake8", # TODO: remove in favor of regex-lint or preamble
189197
]
190198
config = "lint-configs/python/.flake8"
191199

@@ -207,11 +215,8 @@ known_versions = [
207215
]
208216

209217
[pylint]
210-
lockfile = "lockfiles/pylint.lock"
211-
version = "pylint~=2.8.2"
212-
extra_requirements = [
213-
"setuptools", # includes pkg_resources
214-
]
218+
install_from_resolve = "pylint"
219+
requirements = ["pylint", "setuptools"] # versions in pylint_plugins/BUILD
215220
config = "lint-configs/python/.pylintrc"
216221
source_plugins = [
217222
# the /pylint_plugins directory
@@ -227,10 +232,10 @@ args = [
227232
]
228233

229234
[pytest]
230-
lockfile = "lockfiles/pytest.lock"
231-
version = "pytest==7.0.1" # copied from https://www.pantsbuild.org/v2.14/docs/reference-pytest#version
232-
extra_requirements.add = [
233-
"pytest-benchmark[histogram]==3.4.1", # used for st2common/benchmarks
235+
install_from_resolve = "pytest"
236+
requirements = [ # versions in BUILD.tools
237+
"pytest",
238+
"pytest-benchmark[histogram]", # used for st2common/benchmarks
234239
#"pytest-timer[colorama]", # report test timing (--with-timer ala nose-timer)
235240
"pytest-icdiff", # make diff output easier to read
236241
"pygments", # highlight code in tracebacks
@@ -239,9 +244,9 @@ extra_requirements.add = [
239244
#"pytest-timeout", # time limit on tests
240245
#"pytest-mock", # more convenient mocking
241246

242-
# included by default with pants
243-
#"pytest-cov", # coverage
244-
#"pytest-xdist", # parallel test runs (pants uses this if [pytest].xdist_enabled)
247+
# needed by pants
248+
"pytest-cov", # coverage
249+
"pytest-xdist", # parallel test runs (pants uses this if [pytest].xdist_enabled)
245250
]
246251
args = [
247252
"--no-header", # don't print pytest version for every tested file
@@ -252,10 +257,9 @@ execution_slot_var = "ST2TESTS_PARALLEL_SLOT"
252257
config = "@lint-configs/regex-lint.yaml"
253258

254259
[setuptools]
255-
# setuptools 59.7 (at least) does not support python 3.6
256-
version = "setuptools>=50.3.0,<59.0"
257-
lockfile = "lockfiles/setuptools.lock"
260+
install_from_resolve = "setuptools"
261+
requirements = ["setuptools", "wheel"] # versions in BUILD.tools
258262

259263
[twine]
260-
lockfile = "lockfiles/twine.lock"
261-
version = "twine>=3.7.1,<3.8"
264+
install_from_resolve = "twine"
265+
requirements = ["twine", "colorama"] # versions in BUILD.tools

pylint_plugins/BUILD

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__defaults__(
22
all=dict(
3-
resolve="pylint_plugins",
3+
resolve="pylint",
44
)
55
)
66

@@ -17,10 +17,8 @@ python_tests(
1717
python_requirement(
1818
name="pylint",
1919
requirements=[
20-
# This must be the same as [pylint].version in pants.toml
2120
"pylint~=2.8.2",
22-
# other requirements in [pylint].extra_requirements in pants.toml
23-
"setuptools",
21+
"setuptools", # includes pkg_resources
2422
],
2523
)
2624

0 commit comments

Comments
 (0)