Skip to content

Commit 3d7ed95

Browse files
committed
Refactor cog scripts to avoid regular expression hacks.
1 parent cda15ef commit 3d7ed95

7 files changed

+258
-173
lines changed

constraints.txt

+44-38
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,38 @@
77
aenum==3.1.15 # via dace
88
alabaster==0.7.13 # via sphinx
99
asttokens==2.4.1 # via devtools, stack-data
10-
astunparse==1.6.3 ; python_version < "3.9" # via dace, gt4py (pyproject.toml)
11-
attrs==23.2.0 # via flake8-bugbear, flake8-eradicate, gt4py (pyproject.toml), hypothesis, jsonschema, referencing
10+
astunparse==1.6.3 ; python_version < "3.9" # via dace, gt4py, gt4py (pyproject.toml)
11+
attrs==23.2.0 # via flake8-bugbear, flake8-eradicate, gt4py, gt4py (pyproject.toml), hypothesis, jsonschema, referencing
1212
babel==2.14.0 # via sphinx
1313
backcall==0.2.0 # via ipython
14-
black==24.1.1 # via gt4py (pyproject.toml)
14+
black==24.1.1 # via gt4py, gt4py (pyproject.toml)
1515
blinker==1.7.0 # via flask
16-
boltons==23.1.1 # via gt4py (pyproject.toml)
16+
boltons==23.1.1 # via gt4py, gt4py (pyproject.toml)
1717
build==1.0.3 # via pip-tools
18-
cached-property==1.5.2 # via gt4py (pyproject.toml)
18+
cached-property==1.5.2 # via gt4py, gt4py (pyproject.toml)
1919
cachetools==5.3.2 # via tox
2020
certifi==2024.2.2 # via requests
2121
cffi==1.16.0 # via cryptography
2222
cfgv==3.4.0 # via pre-commit
2323
chardet==5.2.0 # via tox
2424
charset-normalizer==3.3.2 # via requests
25-
clang-format==17.0.6 # via -r requirements-dev.in, gt4py (pyproject.toml)
26-
click==8.1.7 # via black, flask, gt4py (pyproject.toml), pip-tools
27-
cmake==3.28.1 # via gt4py (pyproject.toml)
25+
clang-format==17.0.6 # via -r requirements-dev.in, gt4py
26+
click==8.1.7 # via black, flask, gt4py, gt4py (pyproject.toml), pip-tools
27+
cmake==3.28.1 # via gt4py, gt4py (pyproject.toml)
2828
cogapp==3.3.0 # via -r requirements-dev.in
2929
colorama==0.4.6 # via tox
3030
comm==0.2.1 # via ipykernel
3131
contourpy==1.1.1 # via matplotlib
3232
coverage==7.4.1 # via -r requirements-dev.in, pytest-cov
3333
cryptography==42.0.2 # via types-paramiko, types-pyopenssl, types-redis
3434
cycler==0.12.1 # via matplotlib
35-
cytoolz==0.12.3 # via gt4py (pyproject.toml)
36-
dace==0.15.1 # via gt4py (pyproject.toml)
35+
cytoolz==0.12.3 # via gt4py, gt4py (pyproject.toml)
36+
dace==0.15.1 # via gt4py
3737
darglint==1.8.1 # via -r requirements-dev.in
3838
debugpy==1.8.0 # via ipykernel
3939
decorator==5.1.1 # via ipython
40-
deepdiff==6.7.1 # via gt4py (pyproject.toml)
41-
devtools==0.12.2 # via gt4py (pyproject.toml)
40+
deepdiff==6.7.1 # via gt4py, gt4py (pyproject.toml)
41+
devtools==0.12.2 # via gt4py, gt4py (pyproject.toml)
4242
dill==0.3.8 # via dace
4343
distlib==0.3.8 # via virtualenv
4444
docutils==0.20.1 # via restructuredtext-lint, sphinx, sphinx-rtd-theme
@@ -59,54 +59,59 @@ flake8-eradicate==1.5.0 # via -r requirements-dev.in
5959
flake8-mutable==1.2.0 # via -r requirements-dev.in
6060
flake8-pyproject==1.2.3 # via -r requirements-dev.in
6161
flake8-rst-docstrings==0.3.0 # via -r requirements-dev.in
62-
flask==3.0.1 # via dace
62+
flask==3.0.2 # via dace
6363
fonttools==4.47.2 # via matplotlib
6464
fparser==0.1.4 # via dace
65-
frozendict==2.4.0 # via gt4py (pyproject.toml)
66-
gridtools-cpp==2.3.2 # via gt4py (pyproject.toml)
67-
hypothesis==6.97.4 # via -r requirements-dev.in, gt4py (pyproject.toml)
65+
frozendict==2.4.0 # via gt4py, gt4py (pyproject.toml)
66+
gridtools-cpp==2.3.2 # via gt4py, gt4py (pyproject.toml)
67+
gt4py @ file:///home/enriqueg/Projects/GT/gt4py/wip-settings # via gt4py (pyproject.toml)
68+
hypothesis==6.98.1 # via -r requirements-dev.in, gt4py
6869
identify==2.5.33 # via pre-commit
6970
idna==3.6 # via requests
7071
imagesize==1.4.1 # via sphinx
71-
importlib-metadata==7.0.1 # via build, flask, jupyter-client, sphinx
72-
importlib-resources==6.1.1 ; python_version < "3.9" # via gt4py (pyproject.toml), jsonschema, jsonschema-specifications, matplotlib
72+
importlib-metadata==7.0.1 # via build, flask, jax, jupyter-client, sphinx
73+
importlib-resources==6.1.1 ; python_version < "3.9" # via gt4py, gt4py (pyproject.toml), jsonschema, jsonschema-specifications, matplotlib
7374
inflection==0.5.1 # via pytest-factoryboy
7475
iniconfig==2.0.0 # via pytest
7576
ipykernel==6.29.0 # via nbmake
7677
ipython==8.12.3 # via ipykernel
7778
isort==5.13.2 # via -r requirements-dev.in
7879
itsdangerous==2.1.2 # via flask
80+
jax==0.4.13 # via gt4py
81+
jaxlib==0.4.13 # via jax
7982
jedi==0.19.1 # via ipython
80-
jinja2==3.1.3 # via flask, gt4py (pyproject.toml), sphinx
83+
jinja2==3.1.3 # via flask, gt4py, gt4py (pyproject.toml), sphinx
8184
jsonschema==4.21.1 # via nbformat
8285
jsonschema-specifications==2023.12.1 # via jsonschema
8386
jupyter-client==8.6.0 # via ipykernel, nbclient
8487
jupyter-core==5.7.1 # via ipykernel, jupyter-client, nbformat
8588
jupytext==1.16.1 # via -r requirements-dev.in
8689
kiwisolver==1.4.5 # via matplotlib
87-
lark==1.1.9 # via gt4py (pyproject.toml)
88-
mako==1.3.2 # via gt4py (pyproject.toml)
90+
lark==1.1.9 # via gt4py, gt4py (pyproject.toml)
91+
mako==1.3.2 # via gt4py, gt4py (pyproject.toml)
8992
markdown-it-py==3.0.0 # via jupytext, mdit-py-plugins
90-
markupsafe==2.1.4 # via jinja2, mako, werkzeug
93+
markupsafe==2.1.5 # via jinja2, mako, werkzeug
9194
matplotlib==3.7.4 # via -r requirements-dev.in
9295
matplotlib-inline==0.1.6 # via ipykernel, ipython
9396
mccabe==0.7.0 # via flake8
9497
mdit-py-plugins==0.4.0 # via jupytext
9598
mdurl==0.1.2 # via markdown-it-py
99+
ml-dtypes==0.2.0 # via jax, jaxlib
96100
mpmath==1.3.0 # via sympy
97101
mypy==1.8.0 # via -r requirements-dev.in
98102
mypy-extensions==1.0.0 # via black, mypy
99-
nanobind==1.8.0 # via gt4py (pyproject.toml)
103+
nanobind==1.8.0 # via gt4py, gt4py (pyproject.toml)
100104
nbclient==0.6.8 # via nbmake
101105
nbformat==5.9.2 # via jupytext, nbclient, nbmake
102106
nbmake==1.5.0 # via -r requirements-dev.in
103107
nest-asyncio==1.6.0 # via ipykernel, nbclient
104108
networkx==3.1 # via dace
105-
ninja==1.11.1.1 # via gt4py (pyproject.toml)
109+
ninja==1.11.1.1 # via gt4py, gt4py (pyproject.toml)
106110
nodeenv==1.8.0 # via pre-commit
107-
numpy==1.24.4 # via contourpy, dace, gt4py (pyproject.toml), matplotlib, types-jack-client
111+
numpy==1.24.4 # via contourpy, dace, gt4py, gt4py (pyproject.toml), jax, jaxlib, matplotlib, ml-dtypes, opt-einsum, scipy, types-jack-client
112+
opt-einsum==3.3.0 # via jax
108113
ordered-set==4.1.0 # via deepdiff
109-
packaging==23.2 # via black, build, gt4py (pyproject.toml), ipykernel, jupytext, matplotlib, pyproject-api, pytest, setuptools-scm, sphinx, tox
114+
packaging==23.2 # via black, build, gt4py, gt4py (pyproject.toml), ipykernel, jupytext, matplotlib, pyproject-api, pytest, setuptools-scm, sphinx, tox
110115
parso==0.8.3 # via jedi
111116
pathspec==0.12.1 # via black
112117
pexpect==4.9.0 # via ipython
@@ -123,7 +128,7 @@ prompt-toolkit==3.0.43 # via ipython
123128
psutil==5.9.8 # via -r requirements-dev.in, ipykernel, pytest-xdist
124129
ptyprocess==0.7.0 # via pexpect
125130
pure-eval==0.2.2 # via stack-data
126-
pybind11==2.11.1 # via gt4py (pyproject.toml)
131+
pybind11==2.11.1 # via gt4py, gt4py (pyproject.toml)
127132
pycodestyle==2.11.1 # via flake8, flake8-debugger
128133
pycparser==2.21 # via cffi
129134
pydocstyle==6.3.0 # via flake8-docstrings
@@ -132,7 +137,7 @@ pygments==2.17.2 # via -r requirements-dev.in, devtools, flake8-rst-doc
132137
pyparsing==3.1.1 # via matplotlib
133138
pyproject-api==1.6.1 # via tox
134139
pyproject-hooks==1.0.0 # via build
135-
pytest==8.0.0 # via -r requirements-dev.in, gt4py (pyproject.toml), nbmake, pytest-cache, pytest-cov, pytest-factoryboy, pytest-xdist
140+
pytest==8.0.0 # via -r requirements-dev.in, gt4py, nbmake, pytest-cache, pytest-cov, pytest-factoryboy, pytest-xdist
136141
pytest-cache==1.0 # via -r requirements-dev.in
137142
pytest-cov==4.1.0 # via -r requirements-dev.in
138143
pytest-factoryboy==2.6.0 # via -r requirements-dev.in
@@ -146,6 +151,7 @@ requests==2.31.0 # via dace, sphinx
146151
restructuredtext-lint==1.4.0 # via flake8-rst-docstrings
147152
rpds-py==0.17.1 # via jsonschema, referencing
148153
ruff==0.2.0 # via -r requirements-dev.in
154+
scipy==1.10.1 # via gt4py, jax, jaxlib
149155
setuptools-scm==8.0.4 # via fparser
150156
six==1.16.0 # via asttokens, astunparse, python-dateutil
151157
snowballstemmer==2.2.0 # via pydocstyle, sphinx
@@ -160,8 +166,8 @@ sphinxcontrib-jsmath==1.0.1 # via sphinx
160166
sphinxcontrib-qthelp==1.0.3 # via sphinx
161167
sphinxcontrib-serializinghtml==1.1.5 # via sphinx
162168
stack-data==0.6.3 # via ipython
163-
sympy==1.9 # via dace, gt4py (pyproject.toml)
164-
tabulate==0.9.0 # via gt4py (pyproject.toml)
169+
sympy==1.9 # via dace, gt4py
170+
tabulate==0.9.0 # via gt4py, gt4py (pyproject.toml)
165171
toml==0.10.2 # via jupytext
166172
tomli==2.0.1 ; python_version < "3.11" # via -r requirements-dev.in, black, build, coverage, flake8-pyproject, mypy, pip-tools, pyproject-api, pyproject-hooks, pytest, setuptools-scm, tox
167173
toolz==0.12.1 # via cytoolz
@@ -175,15 +181,15 @@ types-atomicwrites==1.4.5.1 # via types-all
175181
types-backports==0.1.3 # via types-all
176182
types-backports-abc==0.5.2 # via types-all
177183
types-bleach==6.1.0.1 # via types-all
178-
types-boto==2.49.18.9 # via types-all
184+
types-boto==2.49.18.20240205 # via types-all
179185
types-cachetools==5.3.0.7 # via types-all
180186
types-certifi==2021.10.8.3 # via types-all
181187
types-cffi==1.16.0.20240106 # via types-jack-client
182188
types-characteristic==14.3.7 # via types-all
183189
types-chardet==5.0.4.6 # via types-all
184190
types-click==7.1.8 # via types-all, types-flask
185191
types-click-spinner==0.1.13.20240106 # via types-all
186-
types-colorama==0.4.15.20240106 # via types-all
192+
types-colorama==0.4.15.20240205 # via types-all
187193
types-contextvars==2.4.7.3 # via types-all
188194
types-croniter==2.0.0.20240106 # via types-all
189195
types-cryptography==3.3.23.2 # via types-all, types-openssl-python, types-pyjwt
@@ -217,7 +223,7 @@ types-mypy-extensions==1.0.0.5 # via types-all
217223
types-nmap==0.1.6 # via types-all
218224
types-openssl-python==0.1.3 # via types-all
219225
types-orjson==3.6.2 # via types-all
220-
types-paramiko==3.4.0.20240120 # via types-all, types-pysftp
226+
types-paramiko==3.4.0.20240205 # via types-all, types-pysftp
221227
types-pathlib2==2.3.0 # via types-all
222228
types-pillow==10.2.0.20240125 # via types-all
223229
types-pkg-resources==0.1.3 # via types-all
@@ -235,7 +241,7 @@ types-pysftp==0.2.17.20240106 # via types-all
235241
types-python-dateutil==2.8.19.20240106 # via types-all, types-datetimerange
236242
types-python-gflags==3.1.7.3 # via types-all
237243
types-python-slugify==8.0.2.20240127 # via types-all
238-
types-pytz==2023.4.0.20240130 # via types-all, types-tzlocal
244+
types-pytz==2024.1.0.20240203 # via types-all, types-tzlocal
239245
types-pyvmomi==8.0.0.6 # via types-all
240246
types-pyyaml==6.0.12.12 # via types-all
241247
types-redis==4.6.0.20240106 # via types-all
@@ -257,16 +263,16 @@ types-ujson==5.9.0.0 # via types-all
257263
types-waitress==2.1.4.20240106 # via types-all
258264
types-werkzeug==1.0.9 # via types-all, types-flask
259265
types-xxhash==3.0.5.2 # via types-all
260-
typing-extensions==4.5.0 # via black, faker, gt4py (pyproject.toml), ipython, mypy, pytest-factoryboy, setuptools-scm
266+
typing-extensions==4.5.0 # via black, faker, gt4py, gt4py (pyproject.toml), ipython, mypy, pytest-factoryboy, setuptools-scm
261267
urllib3==2.2.0 # via requests, types-requests
262268
virtualenv==20.25.0 # via pre-commit, tox
263269
wcwidth==0.2.13 # via prompt-toolkit
264270
websockets==12.0 # via dace
265271
werkzeug==3.0.1 # via flask
266272
wheel==0.42.0 # via astunparse, pip-tools
267-
xxhash==3.0.0 # via gt4py (pyproject.toml)
273+
xxhash==3.0.0 # via gt4py, gt4py (pyproject.toml)
268274
zipp==3.17.0 # via importlib-metadata, importlib-resources
269275

270276
# The following packages are considered to be unsafe in a requirements file:
271-
pip==23.3.2 # via pip-tools
272-
setuptools==69.0.3 # via gt4py (pyproject.toml), nodeenv, pip-tools, setuptools-scm
277+
pip==24.0 # via pip-tools
278+
setuptools==69.0.3 # via gt4py, gt4py (pyproject.toml), nodeenv, pip-tools, setuptools-scm

min-extra-requirements-test.txt

+49-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,55 @@
1+
#
2+
# Generated automatically by cog from pyproject.toml and requirements-dev.in
3+
# Run:
4+
# tox r -e requirements-common
5+
#
6+
17
##[[[cog
2-
## import re, sys
8+
## import copy, sys
9+
## from packaging import requirements as reqs, specifiers as specs
310
## if sys.version_info >= (3, 11):
4-
## import tomllib
11+
## import tomllib
512
## else:
6-
## import tomli as tomllib
13+
## import tomli as tomllib
14+
##
15+
## def make_min_req(r: reqs.Requirement) -> reqs.Requirement:
16+
## for s in r.specifier:
17+
## if (ss := str(s)).startswith(">"):
18+
## min_spec = f"=={ss[1:]}" if ss[1] != "=" else f"=={ss[2:]}"
19+
## spec = specs.SpecifierSet(min_spec)
20+
## break
21+
## min_r = copy.deepcopy(r)
22+
## min_r.specifier = spec
23+
## return min_r
24+
##
725
## project = tomllib.loads(open("pyproject.toml").read())
8-
## requirements = set(
9-
## rr
10-
## for r in (
11-
## project["project"]["dependencies"]
12-
## + project["project"]["optional-dependencies"]["full"]
13-
## + open("requirements-dev.in").readlines()
14-
## )
15-
## if (rr := r.strip()) and not rr.startswith('#')
16-
## )
17-
## for r in sorted(requirements):
18-
## m = re.match("^([\w-][\w\d\[\]-]*)[=>~][=]([^,]+)", r)
19-
## print(f"{m[1]}=={m[2].strip()}")
26+
## all_cpu_extra = project["project"]["optional-dependencies"]["all-cpu"]
27+
## assert len(all_cpu_extra) == 1 and all_cpu_extra[0].startswith("gt4py[")
28+
## opt_req_versions = {
29+
## reqs.Requirement(r).name: reqs.Requirement(r)
30+
## for e in reqs.Requirement(all_cpu_extra[0]).extras
31+
## for r in project["project"]["optional-dependencies"][e]
32+
## }
33+
## requirements = [
34+
## reqs.Requirement(rr)
35+
## for r in (project["project"]["dependencies"] + open("requirements-dev.in").readlines())
36+
## if (rr := (r[: r.find("#")] if "#" in r else r))
37+
## ]
38+
## processed = set()
39+
## result = []
40+
## for r in requirements:
41+
## assert r.name not in processed
42+
## processed.add(r.name)
43+
## if not r.specifier:
44+
## assert r.name in opt_req_versions, f"Missing contraints for '{r.name}'"
45+
## r = opt_req_versions[r.name]
46+
## result.append(str(make_min_req(r)))
47+
## for r_name, r in opt_req_versions.items():
48+
## if r_name not in processed:
49+
## result.append(str(make_min_req(r)))
50+
## print("\n".join(sorted(result)))
2051
##]]]
21-
astunparse==1.6.3;python_version<'3.9'
52+
astunparse==1.6.3; python_version < "3.9"
2253
attrs==21.3
2354
black==22.3
2455
boltons==20.1
@@ -46,7 +77,7 @@ flake8==5.0.4
4677
frozendict==2.3
4778
gridtools-cpp==2.3.2
4879
hypothesis==6.0.0
49-
importlib-resources==5.0;python_version<'3.9'
80+
importlib-resources==5.0; python_version < "3.9"
5081
isort==5.10
5182
jax[cpu]==0.4.13
5283
jinja2==3.0.0
@@ -78,7 +109,7 @@ sphinx==4.4
78109
sphinx_rtd_theme==1.0
79110
sympy==1.9
80111
tabulate==0.8.10
81-
tomli==2.0.1;python_version<'3.11'
112+
tomli==2.0.1; python_version < "3.11"
82113
tox==3.2.0
83114
types-all==1.0.0
84115
typing-extensions==4.2

min-requirements-test.txt

+46-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,52 @@
1+
#
2+
# Generated automatically by cog from pyproject.toml and requirements-dev.in
3+
# Run:
4+
# tox r -e requirements-common
5+
#
6+
17
##[[[cog
2-
## import re, sys
8+
## import copy, sys
9+
## from packaging import requirements as reqs, specifiers as specs
310
## if sys.version_info >= (3, 11):
4-
## import tomllib
11+
## import tomllib
512
## else:
6-
## import tomli as tomllib
13+
## import tomli as tomllib
14+
##
15+
## def make_min_req(r: reqs.Requirement) -> reqs.Requirement:
16+
## for s in r.specifier:
17+
## if (ss := str(s)).startswith(">"):
18+
## min_spec = f"=={ss[1:]}" if ss[1] != "=" else f"=={ss[2:]}"
19+
## spec = specs.SpecifierSet(min_spec)
20+
## break
21+
## min_r = copy.deepcopy(r)
22+
## min_r.specifier = spec
23+
## return min_r
24+
##
725
## project = tomllib.loads(open("pyproject.toml").read())
8-
## requirements = set(
9-
## rr
10-
## for r in (
11-
## project["project"]["dependencies"]
12-
## + open("requirements-dev.in").readlines()
13-
## )
14-
## if (rr := r.strip()) and not rr.startswith('#')
15-
## )
16-
## for r in sorted(requirements):
17-
## m = re.match("^([\w-][\w\d\[\]-]*)[=>~][=]([^,]+)", r)
18-
## print(f"{m[1]}=={m[2].strip()}")
26+
## all_cpu_extra = project["project"]["optional-dependencies"]["all-cpu"]
27+
## assert len(all_cpu_extra) == 1 and all_cpu_extra[0].startswith("gt4py[")
28+
## opt_req_versions = {
29+
## reqs.Requirement(r).name: reqs.Requirement(r)
30+
## for e in reqs.Requirement(all_cpu_extra[0]).extras
31+
## for r in project["project"]["optional-dependencies"][e]
32+
## }
33+
## requirements = [
34+
## reqs.Requirement(rr)
35+
## for r in (project["project"]["dependencies"] + open("requirements-dev.in").readlines())
36+
## if (rr := (r[: r.find("#")] if "#" in r else r))
37+
## ]
38+
## processed = set()
39+
## result = []
40+
## for r in requirements:
41+
## assert r.name not in processed
42+
## processed.add(r.name)
43+
## if not r.specifier:
44+
## assert r.name in opt_req_versions, f"Missing contraints for '{r.name}'"
45+
## r = opt_req_versions[r.name]
46+
## result.append(str(make_min_req(r)))
47+
## print("\n".join(sorted(result)))
1948
##]]]
20-
astunparse==1.6.3;python_version<'3.9'
49+
astunparse==1.6.3; python_version < "3.9"
2150
attrs==21.3
2251
black==22.3
2352
boltons==20.1
@@ -44,7 +73,7 @@ flake8==5.0.4
4473
frozendict==2.3
4574
gridtools-cpp==2.3.2
4675
hypothesis==6.0.0
47-
importlib-resources==5.0;python_version<'3.9'
76+
importlib-resources==5.0; python_version < "3.9"
4877
isort==5.10
4978
jinja2==3.0.0
5079
jupytext==1.14
@@ -73,7 +102,7 @@ setuptools==65.5.0
73102
sphinx==4.4
74103
sphinx_rtd_theme==1.0
75104
tabulate==0.8.10
76-
tomli==2.0.1;python_version<'3.11'
105+
tomli==2.0.1; python_version < "3.11"
77106
tox==3.2.0
78107
types-all==1.0.0
79108
typing-extensions==4.2

0 commit comments

Comments
 (0)