Skip to content

Commit f16cb00

Browse files
authored
refactor: switch to Poetry for env+dep management (#127)
I've been using Poetry because it takes the hassle out of virtualenv management and has sane defaults that just work for building artifacts and uploading to PyPI. Because I had to redo how tests were run, I went ahead and removed the Tox testing requirement too and so I had to redo the Github Actions for testing too. One thing I didn't anticipate is that Github Actions caching doesn't work for Poetry, only with `requirements.txt` and Pipenv https://github.blog/changelog/2021-11-23-github-actions-setup-python-now-supports-dependency-caching/ ## Verifying the change I compared `python setup.py build` vs `poetry build` and the only difference was some top level meta differences and Poetry added the `tests` directory which is fine. Both have the `.html` templates which is the important thing.
1 parent 28f0ef7 commit f16cb00

File tree

12 files changed

+284
-185
lines changed

12 files changed

+284
-185
lines changed

.github/workflows/ci.yml

Lines changed: 72 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,85 @@ name: CI
33
on:
44
pull_request:
55
push:
6-
6+
branches:
7+
- master
78
jobs:
8-
test:
9+
test-dj20:
910
strategy:
1011
fail-fast: false
1112
matrix:
12-
versions:
13-
- python: "3.6"
14-
toxenv: "django20-py36"
15-
- python: "3.7"
16-
toxenv: "django20-py37"
17-
- python: "3.6"
18-
toxenv: "django21-py36"
19-
- python: "3.7"
20-
toxenv: "django21-py37"
21-
- python: "3.6"
22-
toxenv: "django22-py36"
23-
- python: "3.7"
24-
toxenv: "django22-py37"
25-
- python: "3.8"
26-
toxenv: "django22-py38"
27-
- python: "3.9"
28-
toxenv: "django22-py39"
29-
- python: "3.6"
30-
toxenv: "django30-py36"
31-
- python: "3.7"
32-
toxenv: "django30-py37"
33-
- python: "3.8"
34-
toxenv: "django30-py38"
35-
- python: "3.9"
36-
toxenv: "django30-py39"
37-
- python: "3.6"
38-
toxenv: "django31-py36"
39-
- python: "3.7"
40-
toxenv: "django31-py37"
41-
- python: "3.8"
42-
toxenv: "django31-py38"
43-
- python: "3.9"
44-
toxenv: "django31-py39"
45-
- python: "3.8"
46-
toxenv: "django32-py38"
47-
- python: "3.9"
48-
toxenv: "django32-py39"
49-
- python: "3.10"
50-
toxenv: "django32-py310"
51-
52-
name: "Python ${{ matrix.versions.python }} - ${{ matrix.versions.toxenv }}"
13+
python: ["3.6", "3.7"]
14+
django: ["2.0.*", "2.1.*"]
15+
name: "Django ${{ matrix.django }} + Python ${{ matrix.python }}"
5316
runs-on: ubuntu-latest
17+
env:
18+
POETRY_VIRTUALENVS_CREATE: false
5419
steps:
5520
- uses: actions/checkout@v2
56-
- name: Set up Python
57-
uses: actions/setup-python@v2
21+
- uses: actions/setup-python@v2
22+
with:
23+
python-version: ${{ matrix.python }}
24+
- run: pip install poetry
25+
- run: poetry install
26+
- run: poetry add "Django==${{ matrix.django }}"
27+
- run: make test
28+
test-dj22:
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
python: ["3.6", "3.7", "3.8", "3.9"]
33+
django: ["2.2.*"]
34+
name: "Django ${{ matrix.django }} + Python ${{ matrix.python }}"
35+
runs-on: ubuntu-latest
36+
env:
37+
POETRY_VIRTUALENVS_CREATE: false
38+
steps:
39+
- uses: actions/checkout@v2
40+
- uses: actions/setup-python@v2
41+
with:
42+
python-version: ${{ matrix.python }}
43+
- run: pip install poetry
44+
- run: poetry install
45+
- run: poetry add "Django==${{ matrix.django }}"
46+
- run: make test
47+
test-dj31:
48+
strategy:
49+
fail-fast: false
50+
matrix:
51+
python: ["3.6", "3.7", "3.8", "3.9"]
52+
django: ["3.0.*", "3.1.*"]
53+
name: "Django ${{ matrix.django }} + Python ${{ matrix.python }}"
54+
runs-on: ubuntu-latest
55+
env:
56+
POETRY_VIRTUALENVS_CREATE: false
57+
steps:
58+
- uses: actions/checkout@v2
59+
- uses: actions/setup-python@v2
60+
with:
61+
python-version: ${{ matrix.python }}
62+
- run: pip install poetry
63+
- run: poetry install
64+
- run: poetry add "Django==${{ matrix.django }}"
65+
- run: make test
66+
test-dj32:
67+
strategy:
68+
fail-fast: false
69+
matrix:
70+
python: ["3.8", "3.9", "3.10"]
71+
django: ["3.2.*"]
72+
name: "Django ${{ matrix.django }} + Python ${{ matrix.python }}"
73+
runs-on: ubuntu-latest
74+
env:
75+
POETRY_VIRTUALENVS_CREATE: false
76+
steps:
77+
- uses: actions/checkout@v2
78+
- uses: actions/setup-python@v2
5879
with:
59-
python-version: ${{ matrix.versions.python }}
60-
- name: Install Dependencies
61-
run: pip install tox
62-
- name: Run Tests
63-
run: tox -e ${{ matrix.versions.toxenv }}
80+
python-version: ${{ matrix.python }}
81+
- run: pip install poetry
82+
- run: poetry install
83+
- run: poetry add "Django==${{ matrix.django }}"
84+
- run: make test
6485

6586
lint:
6687
name: "Black"
@@ -74,4 +95,4 @@ jobs:
7495
- name: Install Black
7596
run: pip install black
7697
- name: Run Black
77-
run: black --check .
98+
run: black --check .

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
3+
<!--next-version-placeholder-->
4+
25
### [3.0.2](https://github.com/crccheck/django-object-actions/compare/v3.0.1...v3.0.2) (2021-04-09)
36

47
### Refactors

MANIFEST.in

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

Makefile

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
VERSION = $(shell cat VERSION)
21
PROJECT = ./example_project
32
MANAGE = $(PROJECT)/manage.py
43
IMAGE = crccheck/django-object-actions
@@ -17,41 +16,35 @@ dev: ## Run the example project
1716

1817
clean: ## Remove generated files
1918
rm -rf .coverage
20-
rm -rf .tox
21-
rm -rf MANIFEST
2219
rm -rf build
2320
rm -rf dist
2421
rm -rf *.egg
2522
rm -rf *.egg-info
2623
find . -name ".DS_Store" -delete
27-
find . -name "*.pyc" -delete
2824
find . -type d -name "__pycache__" -exec rm -rf {} \; || true
2925

30-
install: ## Install development requirements
31-
@[ -n "${VIRTUAL_ENV}" ] || (echo "ERROR: This should be run from a virtualenv" && exit 1)
32-
pip install -r requirements.txt
33-
pip install Django tox
34-
35-
.PHONY: requirements.txt
36-
requirements.txt: ## Regenerate requirements.txt
37-
pip-compile requirements.in > $@
26+
install: ## Install development dependencies
27+
poetry install
28+
pip install Django
3829

3930
tdd: ## Run tests with a file watcher
40-
nodemon --ext py -x sh -c "python -W ignore::RuntimeWarning $(MANAGE) test --failfast django_object_actions || true"
31+
PYTHONPATH=. nodemon --ext py -x sh -c "poetry run python -W ignore::RuntimeWarning $(MANAGE) test --failfast django_object_actions || true"
4132

4233
test: ## Run test suite
43-
python -W ignore::RuntimeWarning $(MANAGE) test django_object_actions
34+
PYTHONPATH=. poetry run python -W ignore::RuntimeWarning $(MANAGE) test django_object_actions
4435

4536
coverage: ## Run and then display coverage report
46-
coverage erase
47-
coverage run $(MANAGE) test django_object_actions
48-
coverage report --show-missing
37+
poetry run coverage erase
38+
PYTHONPATH=. poetry run coverage run $(MANAGE) test django_object_actions
39+
poetry run coverage report --show-missing
4940

5041
resetdb: ## Delete and then recreate the dev sqlite database
5142
python $(MANAGE) reset_db --router=default --noinput
5243
python $(MANAGE) migrate --noinput
5344
python $(MANAGE) loaddata sample_data
5445

46+
# DEPRECATED: Docker builds are currently broken and will likely get deleted rather than fixed
47+
5548
docker/build: ## Build a full set of Docker images
5649
docker/build: docker/build/3.1 docker/build/3.0 docker/build/2.2.6 docker/build/2.1.13 docker/build/2.0.13 docker/build/1.11.25 docker/build/1.10.8 docker/build/1.9.13 docker/build/1.8.18
5750

@@ -80,26 +73,3 @@ test/%:
8073

8174
bash:
8275
docker run --rm -it $(IMAGE):3.1 /bin/sh
83-
84-
# TODO figure out how to get Make to insert a \n in --header and actually output Refactor sections
85-
# --skip.commit --skip.tag \
86-
.PHONY: version
87-
version:
88-
@sed -i -r /version/s/[0-9.]+/$(VERSION)/ setup.py
89-
@sed -i -r /version/s/[0-9.]+/$(VERSION)/ django_object_actions/__init__.py
90-
git add . && standard-version \
91-
--commit-all \
92-
--types '[{"type":"feat","section":"Features"},{"type":"fix","section":"Bug Fixes"},{"type":"chore","section":"Chores"},{"type":"docs","section":"Docs"},{"type":"style","hidden":true},{"type":"refactor","section":"Refactors"},{"type":"perf","hidden":true},{"type":"test","hidden":true}]' \
93-
--header "# Changelog"
94-
95-
# Release instructions
96-
# 1. bump VERSION
97-
# 2. `make version`
98-
# 3. `make release`
99-
# 4. `git push --follow-tags origin master`
100-
# 5. `chandler push`
101-
# 6. `make docker/build docker/publish`
102-
release: clean
103-
@-pip install twine wheel > /dev/null
104-
python setup.py sdist bdist_wheel
105-
twine upload dist/*

README.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ Limitations
193193
Python and Django compatibility
194194
-------------------------------
195195

196-
See [`tox.ini`](./tox.ini) for which Python and Django versions this supports.
196+
See [`ci.yml`](./github/workflows/ci.yml) for which Python and Django versions this supports.
197197

198198

199199
Demo Admin & Docker images
@@ -209,29 +209,24 @@ tutorial. `admin.py` demos what you can do with this app.
209209
Development
210210
-----------
211211

212-
Getting started *(with virtualenvwrapper)*:
212+
Getting started:
213213

214214
```shell
215215
# get a copy of the code
216216
git clone [email protected]:crccheck/django-object-actions.git
217217
cd django-object-actions
218-
# set up your virtualenv (with virtualenvwrapper)
219-
mkvirtualenv django-object-actions
220218
# Install requirements
221219
make install
222-
# Hack your path so that we can reference packages starting from the root
223-
add2virtualenv .
224220
make test # run test suite
225221
make quickstart # runs 'make resetdb' and some extra steps
226222
```
227223

228-
This will install whatever the latest stable version of Django is. You
229-
can also install a specific version of Django and
230-
`pip install -r requirements.txt`.
231-
232224
Various helpers are available as make commands. Type `make help` and
233225
view the `Makefile` to see what other things you can do.
234226

227+
Some commands assume you are in the virtualenv. If you see
228+
"ModuleNotFoundError"s, try running `poetry shell` first.
229+
235230

236231
Similar Packages
237232
----------------

VERSION

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

0 commit comments

Comments
 (0)