Created
November 29, 2021 12:01
-
-
Save truetug/7d2f38b49820d2d6795b57acd5785ed5 to your computer and use it in GitHub Desktop.
Simple script to convert raw poetry dependencies to requirements.txt format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import toml | |
def convert(): | |
data = toml.load("pyproject.toml") | |
result = [] | |
for package_name, params in data["tool"]["poetry"]["dependencies"].items(): | |
if package_name == "python": | |
continue | |
if not isinstance(params, dict): | |
params = {"version": params} | |
extras = ",".join(params.get("extras", [])) | |
if extras: | |
package_name = f"{package_name}[{extras}]" | |
version = params["version"] | |
tmp = re.search(r"(.*?)([\d\.]+)", version) | |
op, version = tmp.groups() | |
op = "==" if not op or op == "^" else "" | |
msg = f"{package_name}{op}{version}" | |
result.append(msg) | |
result = sorted(result) | |
print("\n".join(result)) | |
if __name__ == "__main__": | |
convert() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment