Skip to content

Commit f378920

Browse files
committed
Add script to parse dependencies from pyproject.toml
NOTE: this was created in order to facilitate the project setup using Python 2 🐍πŸͺ¦ but is currently UNUSED as this opens Pandora's box πŸͺ€ of versions specified via 🎭 Poetry but incompatible with Python 2 etc.
1 parent 5b53f68 commit f378920

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

β€Ž.github/workflows/pytest-python2.ymlβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ jobs:
2525
- name: πŸ—ƒ Cache πŸ“¦ APT Packages
2626
uses: awalsh128/cache-apt-pkgs-action@v1.4.3
2727
with:
28-
packages: xmlstarlet
28+
packages:
29+
xmlstarlet
30+
# python3-tomli # required only for 'parse-python-deps.py'
2931
version: 1.0
3032

3133
- name: πŸ—ƒ Cache pyenv installation

β€Žscripts/parse-python-deps.pyβ€Ž

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python3
2+
3+
"""Parse project dependencies and format them for usage with `pip install`."""
4+
5+
# NOTE: requires Ubuntu package 'python3-tomli' to be installed!
6+
7+
import tomli
8+
9+
with open("pyproject.toml", "rb") as tomlfile:
10+
pyproject = tomli.load(tomlfile)
11+
12+
deps_pkg = pyproject["tool"]["poetry"]["dependencies"]
13+
deps_dev = pyproject["tool"]["poetry"]["group"]["dev"]["dependencies"]
14+
15+
output = ""
16+
17+
for deps in deps_pkg, deps_dev:
18+
for pkg, ver in deps.items():
19+
if ver[0] == "^":
20+
ver = f">={ver[1:]}"
21+
output = f'{output} {pkg}{ver}'
22+
23+
print(output)

0 commit comments

Comments
Β (0)