mirror of
https://github.com/onionshare/onionshare.git
synced 2025-12-18 09:42:31 -05:00
Make pyproject.toml PEP 621 compliant
- converted tool.poetry to PEP 621 (default behavior for poetry) - converted setup.py to PEP 621 (recommended by setuptools) - use pyproject.toml instead of version.txt - use importlib instead of version.txt - use PEP 621 dependency format in flatpak build scripts - added tomli as a dev dependency (used in build scripts) - removed version.txt (no longer used) - cleaned up dependencies - version is still in desktop/setup.py (unclear on how snapcraft uses it) - poetry lockfiles need to be rebuilt
This commit is contained in:
parent
2cee0508d1
commit
5e89cdcbc4
12 changed files with 197 additions and 175 deletions
78
flatpak/pyproject-to-requirements.py
Normal file
78
flatpak/pyproject-to-requirements.py
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import click
|
||||
|
||||
if sys.version_info >= (3, 11):
|
||||
import tomllib
|
||||
else:
|
||||
import tomli as tomllib
|
||||
|
||||
|
||||
def format_version(dep, version):
|
||||
if version == "*":
|
||||
return dep
|
||||
# If it's a dictionary, assume it's in the format {extras = ["socks"], version = "*"}
|
||||
elif isinstance(version, dict) and "version" in version:
|
||||
version = version["version"]
|
||||
if version == "*":
|
||||
return dep
|
||||
elif version.startswith("^"):
|
||||
return f"{dep}>={version[1:]}.0"
|
||||
elif version.startswith((">=", "<=", "!=", "==", "<", ">")):
|
||||
return f"{dep}{version}"
|
||||
else:
|
||||
return f"{dep}=={version}"
|
||||
elif version.startswith("^"):
|
||||
return f"{dep}>={version[1:]}.0"
|
||||
elif version.startswith((">=", "<=", "!=", "==", "<", ">")):
|
||||
return f"{dep}{version}"
|
||||
else:
|
||||
return f"{dep}=={version}"
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument("pyproject_filename")
|
||||
def poetry_to_requirements(pyproject_filename):
|
||||
"""Convert poetry dependencies in a pyproject.toml to requirements format."""
|
||||
with open(pyproject_filename, "r") as f:
|
||||
data = tomllib.load(f)
|
||||
|
||||
dependencies = data.get("tool", {}).get("poetry", {}).get("dependencies", {})
|
||||
|
||||
requirements = []
|
||||
|
||||
for dep, version in dependencies.items():
|
||||
if dep == "python" or dep == "onionshare_cli":
|
||||
continue
|
||||
|
||||
formatted = format_version(dep, version)
|
||||
if formatted:
|
||||
requirements.append(formatted)
|
||||
|
||||
for req in requirements:
|
||||
print(req)
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument("pyproject_filename")
|
||||
def pyproject_to_requirements(pyproject_filename):
|
||||
"""Convert PEP 631 dependencies in a pyproject.toml to requirements format."""
|
||||
with open(pyproject_filename, "r") as f:
|
||||
data = tomllib.load(f)
|
||||
|
||||
dependencies = data.get("project", {}).get("dependencies", [])
|
||||
|
||||
requirements = []
|
||||
|
||||
for dep in dependencies:
|
||||
if dep == "onionshare_cli":
|
||||
continue
|
||||
|
||||
requirements.append(dependencies)
|
||||
|
||||
for req in requirements:
|
||||
print(req)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pyproject_to_requirements()
|
||||
Loading…
Add table
Add a link
Reference in a new issue