Skip to content

Commit 3587065

Browse files
bonded
1 parent 1bf5747 commit 3587065

File tree

4 files changed

+97
-3
lines changed

4 files changed

+97
-3
lines changed

‎poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pyproject.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import logging
2+
from pathlib import Path
3+
import tomlkit
4+
from tomlkit.toml_document import TOMLDocument
5+
6+
LOGGER = logging.getLogger(__name__)
7+
8+
9+
def convert_dependencies(poetry_deps: dict) -> list[str]:
10+
"""
11+
Converts Poetry-style dependencies to PEP 621-style dependencies.
12+
13+
Args:
14+
poetry_deps (dict): Dependencies in Poetry format.
15+
16+
Returns:
17+
list[str]: Dependencies in PEP 621 format.
18+
"""
19+
pep621_deps = []
20+
for package, version_spec in poetry_deps.items():
21+
if isinstance(version_spec, dict):
22+
extras = version_spec.get("extras", [])
23+
markers = version_spec.get("markers", "")
24+
version = version_spec.get("version", "")
25+
26+
dep = package
27+
if extras:
28+
dep += f"[{','.join(extras)}]"
29+
if version:
30+
dep += f" {version}"
31+
if markers:
32+
dep += f"; {markers}"
33+
pep621_deps.append(dep)
34+
else:
35+
if version_spec == "*":
36+
version_spec = ""
37+
else:
38+
version_spec = f" {version_spec}"
39+
pep621_deps.append(f"{package}{version_spec}")
40+
return pep621_deps
41+
42+
43+
def extract_dependencies(input_path: Path, output_path: Path) -> None:
44+
"""
45+
Extracts dependencies from a pyproject.toml file and writes them to a new file in PEP 621 format.
46+
47+
Args:
48+
input_path (Path): The path to the input pyproject.toml file.
49+
output_path (Path): The path to the output pyproject_621.toml file.
50+
"""
51+
LOGGER.info("Reading pyproject.toml from %s", input_path)
52+
with input_path.open("r", encoding="utf-8") as file:
53+
pyproject_data = tomlkit.parse(file.read())
54+
55+
LOGGER.info("Extracting dependencies")
56+
dependencies_section = TOMLDocument()
57+
dependencies_section["project"] = {"dependencies": [], "optional-dependencies": {}}
58+
59+
# Extract the dependencies sections if they exist
60+
if "tool" in pyproject_data and "poetry" in pyproject_data["tool"]:
61+
poetry_section = pyproject_data["tool"]["poetry"]
62+
if "dependencies" in poetry_section:
63+
dependencies_section["project"]["dependencies"] = convert_dependencies(poetry_section["dependencies"])
64+
if "dev-dependencies" in poetry_section:
65+
dependencies_section["project"]["optional-dependencies"]["dev"] = convert_dependencies(
66+
poetry_section["dev-dependencies"])
67+
68+
LOGGER.info("Writing extracted dependencies to %s", output_path)
69+
with output_path.open("w", encoding="utf-8") as file:
70+
file.write(tomlkit.dumps(dependencies_section))
71+
72+
73+
if __name__ == "__main__":
74+
logging.basicConfig(level=logging.INFO)
75+
input_path = Path("pyproject.toml")
76+
output_path = Path("pyproject_621.toml")
77+
extract_dependencies(input_path, output_path)

‎pyproject.toml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
[project]
2+
dependencies = ["python >=3.8, <4", "docopt-ng >=0.9.0, <1", "jinja2 >=3.1.4, <4", "markdown >=3.5.2, <4", "docutils ==0.20.1", "tomli >=2.0.1, <3", "typing_extensions"]
3+
4+
[project.optional-dependencies]
5+
dev = ["coverage", "pytest >=6.0.1", "pytest-cov >=2.10.1", "pytest-xdist >=2.1.0", "tox", "pylint >=3.0.2", "mypy", "types-docutils", "types-Markdown", "python-dotenv ==0.11.0", "html5lib", "proselint >=0.13.0", "interrogate >=1.5.0", "pydoctest >=0.1.22", "pdoc3 >=0.10.0", "mdformat >=0.7.17", "linkcheckmd >=1.4.0", "codespell >=2.2.6", "pyenchant >=3.2.2", "metametameta", "tomlkit"]
6+
17
[tool.poetry]
28
name = "pydoc_fork"
39
version = "3.3.0"
@@ -30,7 +36,7 @@ license = "MIT"
3036
readme = "README.md"
3137
repository = "https://github.com/matthewdeanmartin/pydoc_fork"
3238
homepage = "https://github.com/matthewdeanmartin/pydoc_fork"
33-
documentation ="https://github.com/matthewdeanmartin/pydoc_fork"
39+
documentation = "https://github.com/matthewdeanmartin/pydoc_fork"
3440

3541
[tool.poetry.urls]
3642
"Bug Tracker" = "https://github.com/matthewdeanmartin/pydoc_fork/issues"
@@ -91,7 +97,8 @@ codespell = ">=2.2.6"
9197
pyenchant = ">=3.2.2"
9298
metametameta = "*"
9399

94-
100+
# scripts
101+
tomlkit = "*"
95102

96103

97104
[tool.black]
@@ -151,3 +158,8 @@ ONLY_NAMED_AND_SUBS = false
151158

152159
[tool.portray]
153160
output_dir = "doc/docs_portray"
161+
162+
[tool.bonded]
163+
search_path = 'pydoc_fork/'
164+
pyproject = 'pyproject.toml'
165+
exclude = ['__pycache__/']

‎pyproject_621.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[project]
2+
dependencies = ["python >=3.8, <4", "docopt-ng >=0.9.0, <1", "jinja2 >=3.1.4, <4", "markdown >=3.5.2, <4", "docutils ==0.20.1", "tomli >=2.0.1, <3", "typing_extensions"]
3+
4+
[project.optional-dependencies]
5+
dev = ["coverage", "pytest >=6.0.1", "pytest-cov >=2.10.1", "pytest-xdist >=2.1.0", "tox", "pylint >=3.0.2", "mypy", "types-docutils", "types-Markdown", "python-dotenv ==0.11.0", "html5lib", "proselint >=0.13.0", "interrogate >=1.5.0", "pydoctest >=0.1.22", "pdoc3 >=0.10.0", "mdformat >=0.7.17", "linkcheckmd >=1.4.0", "codespell >=2.2.6", "pyenchant >=3.2.2", "metametameta", "tomlkit"]

0 commit comments

Comments
 (0)