Skip to content

Commit

Permalink
refactor: switch to Poetry for env+dep management (#127)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crccheck authored Dec 12, 2021
1 parent 28f0ef7 commit f16cb00
Show file tree
Hide file tree
Showing 12 changed files with 284 additions and 185 deletions.
123 changes: 72 additions & 51 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,85 @@ name: CI
on:
pull_request:
push:

branches:
- master
jobs:
test:
test-dj20:
strategy:
fail-fast: false
matrix:
versions:
- python: "3.6"
toxenv: "django20-py36"
- python: "3.7"
toxenv: "django20-py37"
- python: "3.6"
toxenv: "django21-py36"
- python: "3.7"
toxenv: "django21-py37"
- python: "3.6"
toxenv: "django22-py36"
- python: "3.7"
toxenv: "django22-py37"
- python: "3.8"
toxenv: "django22-py38"
- python: "3.9"
toxenv: "django22-py39"
- python: "3.6"
toxenv: "django30-py36"
- python: "3.7"
toxenv: "django30-py37"
- python: "3.8"
toxenv: "django30-py38"
- python: "3.9"
toxenv: "django30-py39"
- python: "3.6"
toxenv: "django31-py36"
- python: "3.7"
toxenv: "django31-py37"
- python: "3.8"
toxenv: "django31-py38"
- python: "3.9"
toxenv: "django31-py39"
- python: "3.8"
toxenv: "django32-py38"
- python: "3.9"
toxenv: "django32-py39"
- python: "3.10"
toxenv: "django32-py310"

name: "Python ${{ matrix.versions.python }} - ${{ matrix.versions.toxenv }}"
python: ["3.6", "3.7"]
django: ["2.0.*", "2.1.*"]
name: "Django ${{ matrix.django }} + Python ${{ matrix.python }}"
runs-on: ubuntu-latest
env:
POETRY_VIRTUALENVS_CREATE: false
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- run: pip install poetry
- run: poetry install
- run: poetry add "Django==${{ matrix.django }}"
- run: make test
test-dj22:
strategy:
fail-fast: false
matrix:
python: ["3.6", "3.7", "3.8", "3.9"]
django: ["2.2.*"]
name: "Django ${{ matrix.django }} + Python ${{ matrix.python }}"
runs-on: ubuntu-latest
env:
POETRY_VIRTUALENVS_CREATE: false
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- run: pip install poetry
- run: poetry install
- run: poetry add "Django==${{ matrix.django }}"
- run: make test
test-dj31:
strategy:
fail-fast: false
matrix:
python: ["3.6", "3.7", "3.8", "3.9"]
django: ["3.0.*", "3.1.*"]
name: "Django ${{ matrix.django }} + Python ${{ matrix.python }}"
runs-on: ubuntu-latest
env:
POETRY_VIRTUALENVS_CREATE: false
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- run: pip install poetry
- run: poetry install
- run: poetry add "Django==${{ matrix.django }}"
- run: make test
test-dj32:
strategy:
fail-fast: false
matrix:
python: ["3.8", "3.9", "3.10"]
django: ["3.2.*"]
name: "Django ${{ matrix.django }} + Python ${{ matrix.python }}"
runs-on: ubuntu-latest
env:
POETRY_VIRTUALENVS_CREATE: false
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.versions.python }}
- name: Install Dependencies
run: pip install tox
- name: Run Tests
run: tox -e ${{ matrix.versions.toxenv }}
python-version: ${{ matrix.python }}
- run: pip install poetry
- run: poetry install
- run: poetry add "Django==${{ matrix.django }}"
- run: make test

lint:
name: "Black"
Expand All @@ -74,4 +95,4 @@ jobs:
- name: Install Black
run: pip install black
- name: Run Black
run: black --check .
run: black --check .
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog

<!--next-version-placeholder-->

### [3.0.2](https://github.com/crccheck/django-object-actions/compare/v3.0.1...v3.0.2) (2021-04-09)

### Refactors
Expand Down
3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

50 changes: 10 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
VERSION = $(shell cat VERSION)
PROJECT = ./example_project
MANAGE = $(PROJECT)/manage.py
IMAGE = crccheck/django-object-actions
Expand All @@ -17,41 +16,35 @@ dev: ## Run the example project

clean: ## Remove generated files
rm -rf .coverage
rm -rf .tox
rm -rf MANIFEST
rm -rf build
rm -rf dist
rm -rf *.egg
rm -rf *.egg-info
find . -name ".DS_Store" -delete
find . -name "*.pyc" -delete
find . -type d -name "__pycache__" -exec rm -rf {} \; || true

install: ## Install development requirements
@[ -n "${VIRTUAL_ENV}" ] || (echo "ERROR: This should be run from a virtualenv" && exit 1)
pip install -r requirements.txt
pip install Django tox

.PHONY: requirements.txt
requirements.txt: ## Regenerate requirements.txt
pip-compile requirements.in > $@
install: ## Install development dependencies
poetry install
pip install Django

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

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

coverage: ## Run and then display coverage report
coverage erase
coverage run $(MANAGE) test django_object_actions
coverage report --show-missing
poetry run coverage erase
PYTHONPATH=. poetry run coverage run $(MANAGE) test django_object_actions
poetry run coverage report --show-missing

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

# DEPRECATED: Docker builds are currently broken and will likely get deleted rather than fixed

docker/build: ## Build a full set of Docker images
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

Expand Down Expand Up @@ -80,26 +73,3 @@ test/%:

bash:
docker run --rm -it $(IMAGE):3.1 /bin/sh

# TODO figure out how to get Make to insert a \n in --header and actually output Refactor sections
# --skip.commit --skip.tag \
.PHONY: version
version:
@sed -i -r /version/s/[0-9.]+/$(VERSION)/ setup.py
@sed -i -r /version/s/[0-9.]+/$(VERSION)/ django_object_actions/__init__.py
git add . && standard-version \
--commit-all \
--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}]' \
--header "# Changelog"

# Release instructions
# 1. bump VERSION
# 2. `make version`
# 3. `make release`
# 4. `git push --follow-tags origin master`
# 5. `chandler push`
# 6. `make docker/build docker/publish`
release: clean
@-pip install twine wheel > /dev/null
python setup.py sdist bdist_wheel
twine upload dist/*
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Limitations
Python and Django compatibility
-------------------------------

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


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

Getting started *(with virtualenvwrapper)*:
Getting started:

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

This will install whatever the latest stable version of Django is. You
can also install a specific version of Django and
`pip install -r requirements.txt`.

Various helpers are available as make commands. Type `make help` and
view the `Makefile` to see what other things you can do.

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


Similar Packages
----------------
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

Loading

0 comments on commit f16cb00

Please sign in to comment.