File: README.md

package info (click to toggle)
dep-logic 0.5.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 344 kB
  • sloc: python: 4,428; makefile: 3
file content (66 lines) | stat: -rw-r--r-- 2,113 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Dep-Logic

![PyPI - Version](https://img.shields.io/pypi/v/dep-logic)
![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Fpdm-project%2Fdep-logic%2Fmain%2Fpyproject.toml)
![GitHub License](https://img.shields.io/github/license/pdm-project/dep-logic)


Python dependency specifications supporting logical operations

## Installation

```bash
pip install dep-logic
```

This library requires Python 3.8 or later.

Currently, it contains two sub-modules:

- `dep_logic.specifier` - a module for parsing and calculating PEP 440 version specifiers.
- `dep_logic.markers` - a module for parsing and calculating PEP 508 environment markers.

## What does it do?

This library allows logic operations on version specifiers and environment markers.

For example:

```pycon
>>> from dep_logic.specifiers import parse_version_specifier
>>>
>>> a = parse_version_specifier(">=1.0.0")
>>> b = parse_version_specifier("<2.0.0")
>>> print(a & b)
>=1.0.0,<2.0.0
>>> a = parse_version_specifier(">=1.0.0,<2.0.0")
>>> b = parse_version_specifier(">1.5")
>>> print(a | b)
>=1.0.0
```

For markers:

```pycon
>>> from dep_logic.markers import parse_marker
>>> m1 = parse_marker("python_version < '3.8'")
>>> m2 = parse_marker("python_version >= '3.6'")
>>> print(m1 & m2)
python_version < "3.8" and python_version >= "3.6"
```

## About the project

This project is based on @sdispater's [poetry-core](https://github.com/python-poetry/poetry-core) code, but it includes additional packages and a lark parser, which increases the package size and makes it less reusable.

Furthermore, `poetry-core` does not always comply with PEP-508. As a result, this project aims to offer a lightweight utility for dependency specification logic using [PyPA's packaging](https://github.com/pypa/packaging).

Submodules:

- `dep_logic.specifiers` - PEP 440 version specifiers
- `dep_logic.markers` - PEP 508 environment markers
- `dep_logic.tags` - PEP 425 platform tags

## Caveats

Logic operations with `===<string>` specifiers is partially supported.