Skip to content

Commit 5cc1163

Browse files
authored
⬆️ Maintenance/upgrade pip (ITISFoundation#2887)
1 parent ea66196 commit 5cc1163

File tree

25 files changed

+198
-75
lines changed

25 files changed

+198
-75
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ push-version: tag-version
359359
@python3 --version
360360
python3 -m venv $@
361361
$@/bin/pip3 --quiet install --upgrade \
362-
pip~=21.3 \
362+
pip~=22.0 \
363363
wheel \
364364
setuptools
365365
@$@/bin/pip3 list --verbose

ci/github/unit-testing/director.bash

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@ set -o pipefail # don't hide errors within pipes
66
IFS=$'\n\t'
77

88
install() {
9-
bash ci/helpers/ensure_python_pip.bash
9+
# Replaces 'bash ci/helpers/ensure_python_pip.bash'
10+
11+
echo "INFO:" "$(python --version)" "@" "$(command -v python)"
12+
13+
# installs pip if not in place
14+
python -m ensurepip
15+
16+
echo "INFO:" "$(pip --version)" "@" "$(command -v pip)"
17+
18+
# NOTE: pip<22.0 for python 3.6
19+
pip3 install --upgrade \
20+
pip~=21.0 \
21+
wheel \
22+
setuptools
1023
pushd services/director
1124
pip3 install -r requirements/ci.txt
1225
popd

ci/helpers/ensure_python_pip.bash

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
# SEE https://docs.python.org/3/library/ensurepip.html
66
#
77
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
8-
set -o errexit # abort on nonzero exitstatus
9-
set -o nounset # abort on unbound variable
10-
set -o pipefail # don't hide errors within pipes
8+
set -o errexit # abort on nonzero exitstatus
9+
set -o nounset # abort on unbound variable
10+
set -o pipefail # don't hide errors within pipes
1111
IFS=$'\n\t'
1212

1313
# Pin pip version to a compatible release https://www.python.org/dev/peps/pep-0440/#compatible-release
14-
PIP_VERSION=21.3
14+
PIP_VERSION=22.0
1515

1616
echo "INFO:" "$(python --version)" "@" "$(command -v python)"
1717

packages/postgres-database/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ RUN apt-get update \
2626
RUN python -m venv "${VIRTUAL_ENV}"
2727

2828
RUN pip --no-cache-dir install --upgrade \
29-
pip~=21.3 \
29+
pip~=22.0 \
3030
wheel \
3131
setuptools
3232

packages/postgres-database/scripts/erd/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ RUN apt-get update \
1515

1616

1717
RUN pip --no-cache-dir install --upgrade \
18-
pip~=21.3 \
18+
pip~=22.0 \
1919
wheel \
2020
setuptools
2121

packages/service-integration/requirements/_tools.txt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ anyio==3.4.0
88
# via httpcore
99
argcomplete==1.12.3
1010
# via datamodel-code-generator
11-
attrs==21.2.0
11+
attrs==21.4.0
1212
# via
1313
# -c requirements/_base.txt
1414
# -c requirements/_test.txt
1515
# jsonschema
16-
backports.entry-points-selectable==1.1.1
16+
backports-entry-points-selectable==1.1.1
1717
# via virtualenv
1818
black==21.12b0
1919
# via
@@ -32,7 +32,7 @@ cfgv==3.3.1
3232
# via pre-commit
3333
chardet==4.0.0
3434
# via prance
35-
charset-normalizer==2.0.8
35+
charset-normalizer==2.0.11
3636
# via
3737
# -c requirements/_base.txt
3838
# -c requirements/_test.txt
@@ -47,7 +47,7 @@ datamodel-code-generator==0.11.14
4747
# via -r requirements/_tools.in
4848
distlib==0.3.3
4949
# via virtualenv
50-
dnspython==2.1.0
50+
dnspython==2.2.0
5151
# via
5252
# -c requirements/_base.txt
5353
# email-validator
@@ -93,7 +93,7 @@ jinja2==3.0.3
9393
# via
9494
# -c requirements/../../../requirements/constraints.txt
9595
# datamodel-code-generator
96-
jsonschema==4.2.1
96+
jsonschema==4.4.0
9797
# via
9898
# -c requirements/_base.txt
9999
# openapi-schema-validator
@@ -112,9 +112,9 @@ pathspec==0.9.0
112112
# via black
113113
pep517==0.12.0
114114
# via pip-tools
115-
pip-tools==6.4.0
115+
pip-tools==6.5.1
116116
# via -r requirements/../../../requirements/devenv.txt
117-
platformdirs==2.4.0
117+
platformdirs==2.5.0
118118
# via
119119
# -c requirements/_test.txt
120120
# black
@@ -128,7 +128,7 @@ pydantic==1.9.0
128128
# -c requirements/../../../requirements/constraints.txt
129129
# -c requirements/_base.txt
130130
# datamodel-code-generator
131-
pyrsistent==0.18.0
131+
pyrsistent==0.18.1
132132
# via
133133
# -c requirements/_base.txt
134134
# jsonschema
@@ -142,17 +142,17 @@ pyyaml==6.0
142142
# pre-commit
143143
regex==2021.11.10
144144
# via datamodel-code-generator
145-
requests==2.26.0
145+
requests==2.27.1
146146
# via
147147
# -c requirements/_base.txt
148148
# -c requirements/_test.txt
149149
# prance
150150
rfc3986==1.5.0
151151
# via httpx
152-
ruamel.yaml==0.17.17
152+
ruamel-yaml==0.17.17
153153
# via prance
154-
ruamel.yaml.clib==0.2.6
155-
# via ruamel.yaml
154+
ruamel-yaml-clib==0.2.6
155+
# via ruamel-yaml
156156
semver==2.13.0
157157
# via prance
158158
six==1.16.0
@@ -169,22 +169,23 @@ sniffio==1.2.0
169169
# httpx
170170
toml==0.10.2
171171
# via
172-
# -c requirements/_base.txt
173172
# -c requirements/_test.txt
174173
# datamodel-code-generator
175174
# pre-commit
176-
tomli==1.2.2
175+
tomli==1.2.3
177176
# via
177+
# -c requirements/../../../requirements/constraints.txt
178+
# -c requirements/_base.txt
178179
# -c requirements/_test.txt
179180
# black
180181
# pep517
181-
typing-extensions==4.0.0
182+
typing-extensions==4.0.1
182183
# via
183184
# -c requirements/_base.txt
184185
# -c requirements/_test.txt
185186
# black
186187
# pydantic
187-
urllib3==1.26.7
188+
urllib3==1.26.8
188189
# via
189190
# -c requirements/../../../requirements/constraints.txt
190191
# -c requirements/_base.txt
@@ -194,7 +195,7 @@ virtualenv==20.10.0
194195
# via pre-commit
195196
wheel==0.37.0
196197
# via pip-tools
197-
zipp==3.6.0
198+
zipp==3.7.0
198199
# via
199200
# -c requirements/_base.txt
200201
# importlib-resources

requirements/tools/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ RUN apt-get update \
2121

2222

2323
RUN pip --no-cache-dir install --upgrade \
24-
pip~=21.3 \
24+
pip~=22.0 \
2525
wheel \
2626
setuptools
2727

Lines changed: 134 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1+
import fnmatch
2+
import os
13
import re
24
import subprocess
35
from collections import Counter, defaultdict
6+
from contextlib import contextmanager
47
from pathlib import Path
8+
from typing import Dict, List, Literal, NamedTuple, Optional, Set
59

610
from packaging.version import Version
711

12+
13+
@contextmanager
14+
def printing_table(columns: List[str]):
15+
print("|" + "|".join(columns) + "|")
16+
print("|" + "|".join(["-" * len(c) for c in columns]) + "|")
17+
18+
yield
19+
20+
# print("|" + "|".join(["-" * len(c) for c in columns]) + "|")
21+
22+
823
BEFORE_PATTERN = re.compile(r"^-([\w-]+)==([0-9\.post]+)")
924
AFTER_PATTERN = re.compile(r"^\+([\w-]+)==([0-9\.post]+)")
1025

@@ -38,7 +53,7 @@ def parse_changes(filename: Path):
3853
return before, after, Counter(changes)
3954

4055

41-
def main():
56+
def main_changes_stats():
4257

4358
filepath = Path("changes.ignore.keep.log")
4459
if not filepath.exists():
@@ -47,41 +62,131 @@ def main():
4762
before, after, counts = parse_changes(filepath)
4863

4964
# format
50-
print("Stats")
65+
print("Overview of changes in dependencies")
5166
print("- #packages before:", len(before))
5267
print("- #packages after :", len(after))
5368
print()
5469

5570
COLUMNS = ["#", "name", "before", "after", "upgrade", " count"]
5671

57-
print("|" + "|".join(COLUMNS) + "|")
58-
print("|" + "|".join(["-" * len(c) for c in COLUMNS]) + "|")
59-
for i, name in enumerate(sorted(before.keys()), start=1):
60-
# TODO: where are these libraries?
61-
# TODO: are they first dependencies?
62-
# TODO: if major, get link to release notes
63-
from_versions = set(str(v) for v in before[name])
64-
to_versions = set(str(v) for v in after[name])
65-
66-
print(
67-
"|",
68-
f"{i:2d}",
69-
"|",
70-
f"{name:25s}",
71-
"|",
72-
f'{", ".join(from_versions):15s}',
73-
"|",
74-
f'{",".join(to_versions) if to_versions else "removed":10s}',
75-
"|",
76-
# how big the version change is
77-
f"{tag_upgrade(sorted(set(before[name]))[-1], sorted(set(after[name]))[-1]):10s}"
78-
if to_versions
79-
else "",
80-
"|",
81-
counts[name],
82-
"|",
72+
with printing_table(COLUMNS):
73+
74+
for i, name in enumerate(sorted(before.keys()), start=1):
75+
# TODO: where are these libraries?
76+
# TODO: are they first dependencies?
77+
# TODO: if major, get link to release notes
78+
from_versions = set(str(v) for v in before[name])
79+
to_versions = set(str(v) for v in after[name])
80+
81+
print(
82+
"|",
83+
f"{i:3d}",
84+
"|",
85+
f"{name:25s}",
86+
"|",
87+
f'{", ".join(from_versions):15s}',
88+
"|",
89+
f'{",".join(to_versions) if to_versions else "removed":10s}',
90+
"|",
91+
# how big the version change is
92+
f"{tag_upgrade(sorted(set(before[name]))[-1], sorted(set(after[name]))[-1]):10s}"
93+
if to_versions
94+
else "",
95+
"|",
96+
counts[name],
97+
"|",
98+
)
99+
100+
101+
## Stats on installed packages (i.e. defined in txt files)
102+
DEPENDENCY = re.compile(r"([\w_-]+)==([0-9\.-]+)")
103+
104+
105+
def parse_dependencies_in_reqfile(reqfile: Path) -> Dict[str, Version]:
106+
name2version = {}
107+
for name, version in DEPENDENCY.findall(reqfile.read_text()):
108+
# TODO: typing-extensions==4.0.1 ; python_version < "3.9" might intro multiple versions
109+
assert name not in name2version, f"{name} more than once in {reqfile}"
110+
name2version[name] = Version(version)
111+
return name2version
112+
113+
114+
class ReqFile(NamedTuple):
115+
path: Path
116+
target: Literal["base", "test", "tool", "other"]
117+
dependencies: Dict[str, Version]
118+
119+
120+
def parse_dependencies(
121+
repodir: Path, *, exclude: Optional[Set] = None
122+
) -> List[ReqFile]:
123+
reqs = []
124+
exclude = exclude or set()
125+
for reqfile in repodir.rglob("**/requirements/_*.txt"):
126+
if any(fnmatch.fnmatch(reqfile, x) for x in exclude):
127+
continue
128+
try:
129+
t = {"_base.txt": "base", "_test.txt": "test", "_tools.txt": "tool"}[
130+
reqfile.name
131+
]
132+
except KeyError:
133+
if "test" in f"{reqfile.parent}":
134+
t = "test"
135+
else:
136+
t = "other"
137+
138+
reqs.append(
139+
ReqFile(
140+
path=reqfile,
141+
target=t,
142+
dependencies=parse_dependencies_in_reqfile(reqfile),
143+
)
83144
)
145+
return reqs
146+
147+
148+
def main_dep_stats(exclude: Optional[Set] = None):
149+
repodir = Path(os.environ.get("REPODIR", "."))
150+
reqs = parse_dependencies(repodir, exclude=exclude)
151+
152+
# format
153+
print("Overview of libraries used repo-wide")
154+
print("- #reqs files parsed:", len(reqs))
155+
print()
156+
157+
deps = defaultdict(lambda: defaultdict(list))
158+
for r in reqs:
159+
for name, version in r.dependencies.items():
160+
deps[name]["name"] = name
161+
deps[name][r.target].append(version)
162+
163+
with printing_table(
164+
columns=["#", "name", "versions-base", "versions-test", "versons-tool"]
165+
):
166+
for i, name in enumerate(sorted(deps.keys()), start=1):
167+
168+
def _norm(thing):
169+
return [f"{v}" for v in sorted(list(set(thing)))]
170+
171+
bases = _norm(deps[name]["base"])
172+
tests = _norm(deps[name]["test"])
173+
tools = _norm(deps[name]["tool"])
174+
175+
print(
176+
"|",
177+
f"{i:3d}",
178+
"|",
179+
f"{name:25s}",
180+
"|",
181+
f'{", ".join(bases):25s}',
182+
"|",
183+
f'{", ".join(tests):25s}',
184+
"|",
185+
f'{", ".join(tools):25s}',
186+
"|",
187+
)
84188

85189

86190
if __name__ == "__main__":
87-
main()
191+
# main_changes_stats()
192+
main_dep_stats(exclude={"*/director/*"})

0 commit comments

Comments
 (0)