abn / pep621-project-dependencies

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PEP 621 Dependency Specification: TOML Proposal Library

This is a library demonstrating loading proposed TOML dependency specification from and to PEP 508 strings for PEP 621.

The library also implements a sample dataclass based instances with validation for dependency specifications. As an additional example, this also makes use of lark-parser to parse a provided PEP 508 string.

This is not supported code, this is put together for demonstration purposes only.

Example Usage

From PEP 508 to TOML

Versioned Dependencies

$ python -m pep621_project_dependencies -f toml "pycowsay (==0.0.0.1)"
[project.dependencies]
pycowsay = { version = "==0.0.0.1" }

[project.optional-dependencies]


$ python -m pep621_project_dependencies -f toml "requests[security,tests] (>= 2.8.1, == 2.8.*) ; python_version < '2.7'"
[project.dependencies]
requests = { extras = [ "security", "tests",], markers = "python_version < '2.7'", version = ">= 2.8.1, == 2.8.*" }

[project.optional-dependencies]

Direct References (URL)

$ python -m pep621_project_dependencies -f toml "pip @ https://github.com/pypa/pip/archive/1.3.1.zip#sha1=da9234ee9982d4bbb3c72346a6de940a148ea686"
[project.dependencies]
pip = { url = "https://github.com/pypa/pip/archive/1.3.1.zip", hash = "sha1=da9234ee9982d4bbb3c72346a6de940a148ea686" }

[project.optional-dependencies]

Direct References (VCS)

$ python -m pep621_project_dependencies -f toml "sphinx @ git+ssh://git@github.com/sphinx-doc/sphinx.git@master"
[project.dependencies]
[project.dependencies]
sphinx = { url = "ssh://git@github.com/sphinx-doc/sphinx.git", vcs = "git", revision = "master" }

[project.optional-dependencies]

$ python -m pep621_project_dependencies -f toml "sphinx @ git+ssh://git@github.com/sphinx-doc/sphinx.git@master ; extra == 'doc'"
[project.dependencies]

[project.optional-dependencies.doc]
sphinx = { url = "ssh://git@github.com/sphinx-doc/sphinx.git", vcs = "git", revision = "master" }

From TOML to PEP 508

$ python -m pep621_project_dependencies -f pep508 tests/fixtures/complete.toml 
flask
numpy (~=1.18)
pycowsay (==0.0.0.1)
sphinx @ git+ssh://git@github.com/sphinx-doc/sphinx.git@master
pip @ https://github.com/pypa/pip/archive/1.3.1.zip#sha1=da9234ee9982d4bbb3c72346a6de940a148ea686
docker[ssh] (>= 4.2.2, < 5)
requests[security,tests] (>= 2.8.1, == 2.8.*) ; python_version < '2.7'
backports.shutil_get_terminal_size (== 1.0.0) ; python_version < '3.3'
backports.ssl_match_hostname (>= 3.5, < 4) ; python_version < '3.5'
colorama (>= 0.4, < 1) ; sys_platform == 'win32'
enum34 (>= 1.0.4, < 2) ; python_version < '3.4'
keyring (>=18.0.1, <18.1.0) ; python_version ~= '2.7'
keyring (>=20.0.1, <21.0.0) ; python_version ~= '3.5'
keyring (>=21.2.0) ; python_version >= '3.6'
PySocks (>= 1.5.6, != 1.5.7, < 2) ; extra == 'socks'
ddt (>= 1.2.2, < 2) ; extra == 'tests'
pytest (<6) ; python_version < '3.5' and extra == 'tests'
pytest (>=6) ; python_version >= '3.5' and extra == 'tests'
mock (>= 1.0.1, < 4) ; python_version < '3.4' and extra == 'tests'

Validation Error

$ python -m pep621_project_dependencies -f pep508 tests/fixtures/invalid.toml 
ERROR: Invalid direct dependency (pip) specified, only vcs dependencies can request a revision

TODO

  • Enhance PEP 508 URI parsing to decompose revision
  • Add examples with multiple URI fragments?

About


Languages

Language:Python 100.0%