Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
yt-project
GitHub Repository: yt-project/yt
Path: blob/main/tests/unpin_requirements.py
928 views
1
# /// script
2
# requires-python = ">=3.10"
3
# dependencies = [
4
# "tomli ; python_full_version < '3.11'",
5
# "tomli-w",
6
# ]
7
# ///
8
import re
9
import sys
10
11
import tomli_w
12
13
if sys.version_info >= (3, 11):
14
import tomllib
15
else:
16
import tomli as tomllib
17
18
PINNED_VERSION_REGEXP = re.compile(r",?(<|<=|==)([0-9a-z]+\.?)+")
19
20
21
def unpin_requirements(requirements: list[str]) -> list[str]:
22
return [re.sub(PINNED_VERSION_REGEXP, "", _) for _ in requirements]
23
24
25
if __name__ == "__main__":
26
with open("pyproject.toml", "rb") as fr:
27
config = tomllib.load(fr)
28
29
config["project"]["dependencies"] = unpin_requirements(
30
config["project"]["dependencies"]
31
)
32
for key, reqs in config["project"]["optional-dependencies"].items():
33
config["project"]["optional-dependencies"][key] = unpin_requirements(reqs)
34
35
with open("pyproject_out.toml", "wb") as fw:
36
tomli_w.dump(config, fw)
37
38