Skip to content

Commit 957ee25

Browse files
authored
Poetry for dependency management (#436)
* Replace setup.py/requirements.txt/version.py with pyproject.toml/poetry.lock * add dateutil to core dependencies * convert dependency groups to extras * Makefile/CI: Change to poetry * poetry run * replace make dev with make full * poetry: include guardrails console script * release_version: Set pypi token in poetry
1 parent c7cb998 commit 957ee25

11 files changed

+4830
-410
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,19 @@ jobs:
2828
with:
2929
python-version: ${{ matrix.python-version }}
3030

31-
- uses: actions/cache@v2
31+
- name: Poetry cache
32+
uses: actions/cache@v3
3233
with:
33-
path: ~/.cache/pip
34-
key: ${{ runner.os }}-pip
34+
path: ~/.cache/pypoetry
35+
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
36+
37+
- name: Install Poetry
38+
uses: snok/install-poetry@v1
3539

3640
- name: Install Dependencies
41+
# TODO: fix errors so that we can run `make dev` instead
3742
run: |
38-
python -m pip install --upgrade pip
39-
make dev
43+
make full
4044
4145
- name: Lint with isort, black, docformatter, flake8
4246
run: |
@@ -55,15 +59,19 @@ jobs:
5559
with:
5660
python-version: ${{ matrix.python-version }}
5761

58-
- uses: actions/cache@v2
62+
- name: Poetry cache
63+
uses: actions/cache@v3
5964
with:
60-
path: ~/.cache/pip
61-
key: ${{ runner.os }}-pip
65+
path: ~/.cache/pypoetry
66+
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
67+
68+
- name: Install Poetry
69+
uses: snok/install-poetry@v1
6270

6371
- name: Install Dependencies
72+
# TODO: fix errors so that we can run `make dev` instead
6473
run: |
65-
python -m pip install --upgrade pip
66-
make dev
74+
make full
6775
6876
- name: Static analysis with pyright
6977
run: |
@@ -74,7 +82,9 @@ jobs:
7482
strategy:
7583
matrix:
7684
python-version: ['3.8', '3.9', '3.10', '3.11']
77-
dependencies: ['dev', 'full']
85+
# TODO: fix errors so that we can run both `make dev` and `make full`
86+
# dependencies: ['dev', 'full']
87+
dependencies: ['full']
7888

7989
steps:
8090
- uses: actions/checkout@v2
@@ -83,10 +93,14 @@ jobs:
8393
with:
8494
python-version: ${{ matrix.python-version }}
8595

86-
- uses: actions/cache@v2
96+
- name: Poetry cache
97+
uses: actions/cache@v3
8798
with:
88-
path: ~/.cache/pip
89-
key: ${{ runner.os }}-pip
99+
path: ~/.cache/pypoetry
100+
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
101+
102+
- name: Install Poetry
103+
uses: snok/install-poetry@v1
90104

91105
- name: Install Dependencies
92106
run: |

.github/workflows/deploy_docs.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ jobs:
2929
uses: actions/checkout@v3
3030
- name: Setup Pages
3131
uses: actions/configure-pages@v3
32-
- name: Install
33-
run: |
34-
python -m pip install --upgrade pip
35-
pip install -r docs/requirements.txt
32+
- name: Poetry cache
33+
uses: actions/cache@v3
34+
with:
35+
path: ~/.cache/pypoetry
36+
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }
37+
- name: Install Poetry
38+
uses: snok/install-poetry@v1
39+
- name: Install dependencies
40+
run: poetry install --with docs
3641
- name: Build
3742
run: mkdocs build
3843
- name: Upload artifact

.github/workflows/examples_check.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ jobs:
2323
with:
2424
python-version: 3.11.x
2525

26+
- name: Poetry cache
27+
uses: actions/cache@v3
28+
with:
29+
path: ~/.cache/pypoetry
30+
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
31+
32+
- name: Install Poetry
33+
uses: snok/install-poetry@v1
34+
2635
- name: Install dependencies
27-
run: |
28-
make full; pip install jupyter nbconvert; pip install .
36+
run: make full; pip install jupyter nbconvert; pip install .
2937

3038
- name: Execute notebooks and check for errors
3139
run: |

.github/workflows/release_version.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ jobs:
77
release:
88
runs-on: ubuntu-latest
99

10-
env:
11-
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
12-
1310
steps:
1411
- name: Checkout Repository
1512
uses: actions/checkout@v2
@@ -19,11 +16,22 @@ jobs:
1916
with:
2017
python-version: 3.11.x
2118

22-
- name: Install twine and wheel
23-
run: pip install twine wheel
19+
- name: Poetry cache
20+
uses: actions/cache@v3
21+
with:
22+
path: ~/.cache/pypoetry
23+
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
24+
25+
- name: Install Poetry
26+
uses: snok/install-poetry@v1
2427

25-
- name: Make Full
28+
- name: Install dependencies
2629
run: make full
2730

31+
- name: Set PyPI credentials
32+
env:
33+
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
34+
run: poetry config pypi-token.pypi "$PYPI_PASSWORD"
35+
2836
- name: Upload to PyPI
29-
run: python3 setup.py upload
37+
run: poetry publish

Makefile

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
MKDOCS_SERVE_ADDR ?= localhost:8000 # Default address for mkdocs serve, format: <host>:<port>, override with `make docs-serve MKDOCS_SERVE_ADDR=<host>:<port>`
22

33
autoformat:
4-
black guardrails/ tests/
5-
isort --atomic guardrails/ tests/
6-
docformatter --in-place --recursive guardrails tests
4+
poetry run black guardrails/ tests/
5+
poetry run isort --atomic guardrails/ tests/
6+
poetry run docformatter --in-place --recursive guardrails tests
77

88
type:
9-
pyright guardrails/
9+
poetry run pyright guardrails/
1010

1111
lint:
12-
isort -c guardrails/ tests/
13-
black guardrails/ tests/ --check
14-
flake8 guardrails/ tests/
12+
poetry run isort -c guardrails/ tests/
13+
poetry run black guardrails/ tests/ --check
14+
poetry run flake8 guardrails/ tests/
1515

1616
test:
17-
pytest tests/
17+
poetry run pytest tests/
1818

1919
test-basic:
2020
set -e
2121
python -c "import guardrails as gd"
2222
python -c "import guardrails.version as mversion"
2323

2424
test-cov:
25-
pytest tests/ --cov=./guardrails/ --cov-report=xml
25+
poetry run pytest tests/ --cov=./guardrails/ --cov-report=xml
2626

2727
view-test-cov:
28-
pytest tests/ --cov=./guardrails/ --cov-report html && open htmlcov/index.html
28+
poetry run pytest tests/ --cov=./guardrails/ --cov-report html && open htmlcov/index.html
2929

3030
docs-serve:
31-
mkdocs serve -a $(MKDOCS_SERVE_ADDR)
31+
poetry run mkdocs serve -a $(MKDOCS_SERVE_ADDR)
3232

3333
docs-deploy:
34-
mkdocs gh-deploy
34+
poetry run mkdocs gh-deploy
3535

3636
dev:
37-
pip install -e ".[dev]"
37+
poetry install
3838

3939
full:
40-
pip install -e ".[all]"
40+
poetry install --all-extras
4141

4242
all: autoformat type lint docs test
4343

docs/requirements.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

guardrails/version.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)