Skip to content

Commit

Permalink
dev: Switch to poetry as package manager, etc
Browse files Browse the repository at this point in the history
This commit swaps us to using poetry as our package manager,
virtual environment manager, and build tool. Some of the changes:

- Install poetry using they're recommended python installer, instead
of off PyPI. IDK how important this really is, maybe it's overkill vs
`python3 -m pip install poetry`
- Dev dependencies only used to be available inside the specific tox
environments they were used. This made it impossible to directly call
`pytest`, for instance. You had to call `tox -e pytest`. Now developers
have access to the toolchain directly more directly, though you still
have to work within poetry's venv with `poetry run pytest`, or just
start up a shell in the venv with `poetry shell` and then `pytest`
directly should work.
- Dev install is as easy as `poetry install -E dev`. Dependencies
are only specified in one place now, pyproject.toml
- Now the version info is necessarily in both pyproject.toml and
in the source code, so add a simple test_meta.py file to make sure
the two sources of truth stay in sync. version.py is no longer needed,
so put the version info directly in __init__.py.
- The [metadata] and [wheel] entries in setup.cfg are no longer
needed since we're using poetry to build instead of setuptools.
MANIFEST.in was never needed in the first place, since LICENSE
has always by default been included in distributions.
- Add a check with twine after building to ensure the built
distributions are OK.
- The GitHub actions workflows had to be tweaked a bit,
though they are basically the same.
- Add a makefile rule to update dependencies easily with `make update`
- Specify using poetry as our build system in the [build-system] area of
pyproject.toml. Now build and publish just with `poetry build` and
`poetry publish` instead of using `python setup.py sdist upload` etc.
Tell tox about this change with `isolated_build = True` intox.ini

It was tricky deciding how to make tox and poetry play nicely with each
other, in terms of making sure they used the same deps, the deps
didn't have to be defined in multiple places, and the deps were
available outside of tox. I used the extra dependencies method outlined
in python-poetry/poetry#1941, though there
are probably other ways to do this.
  • Loading branch information
NickCrews committed Feb 2, 2021
1 parent 9c7ff39 commit 111a376
Show file tree
Hide file tree
Showing 16 changed files with 1,321 additions and 134 deletions.
20 changes: 4 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install tox
run: make init
# Run tox using the version of Python in `PATH`
- name: Run tox
run: tox -e py --skip-missing-interpreters=false
Expand All @@ -53,10 +50,7 @@ jobs:
with:
python-version: '3.x' # Latest python release
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install tox
run: make init
- name: Run flake8 with tox
run: tox -e flake8 --skip-missing-interpreters=false
docs:
Expand All @@ -68,10 +62,7 @@ jobs:
with:
python-version: '3.x' # Latest python release
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install tox
run: make init
- name: Run tox with docs environment
run: tox -e docs --skip-missing-interpreters=false
coverage:
Expand All @@ -84,10 +75,7 @@ jobs:
with:
python-version: '3.x' # Latest python release
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install tox
run: make init
- name: Run tox `coverage` environment and upload results
# Use -Z to fail the workflow if the upload fails.
# Use -f to specify the report file explicitly.
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Upgrade to latest setuptools and wheel
run: pip install --user --upgrade setuptools wheel
- name: Build a binary wheel and a source tarball to dist/
run: python setup.py sdist bdist_wheel
- name: Install dependencies
run: make init
- name: Build package
run: make build
- name: Publish package to PyPI
uses: pypa/[email protected]
with:
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Unreleased_

.. _Unreleased: https://github.com/staticjinja/staticjinja/compare/1.0.3...HEAD

Changed
^^^^^^^

* Use ``poetry`` as our package manager. This should change the development
workflow but not the user experience.

1.0.3_ (2021-01-24)
-------------------

Expand Down
29 changes: 15 additions & 14 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,37 @@ Get the Code
------------

Fork the `staticjinja/staticjinja`_ repository on GitHub. Clone a copy of your
fork, install all the dependencies, and then install tox_ for testing:
fork and get set up:

.. code-block:: bash
$ cd $HOME/projects
$ git clone git://github.com/{YOUR_USERNAME}/staticjinja.git
$ cd staticjinja
$ python -m pip install --upgrade pip
$ pip install -r requirements.txt
$ pip install tox
$ make init
The dev dependencies are installed in a virtual environment managed by poetry.
To use the dev tools (such as the ``pytest`` or ``flake8`` commands),
you need to either run them inside the poetry virtual environment with
``poetry run pytest``, or enter a poetry shell with ``poetry shell`` and then
you can run them directly such as ``pytest``. See the `Poetry docs`_ for more
info.

Making Changes
--------------

Start making edits! If you want to test your personal project on your changes,
then you'll want to install staticjinja as ``editable``. Then your project
will use the local, edited version of staticjinja.

.. code-block:: bash
$ python3 -m pip install -e .
Start making edits! The ``poetry install`` command that was run in ``make init``
should have installed the local version of staticjinja in editable mode.
Any other projects on your system should be using the local version.

Testing your Changes
--------------------

You should test your changes with tox_:
You should test your changes:

.. code-block:: bash
$ tox
$ make test
This will:

Expand Down Expand Up @@ -77,5 +78,5 @@ Thanks for your help!

.. _staticjinja/staticjinja : https://github.com/staticjinja/staticjinja
.. _Issues: https://github.com/staticjinja/staticjinja/issues
.. _tox: https://tox.readthedocs.org/en/stable/
.. _Poetry docs: https://python-poetry.org/docs/basic-usage/#using-your-virtual-environment
.. _good commit message style: https://chris.beams.io/posts/git-commit/
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

16 changes: 13 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
.PHONY: docs

init:
pip install -r requirements.txt
# Install poetry
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 -
# Install dependencies, including dev deps
poetry install -E dev

test:
tox

coverage:
tox -e coverage

build:
poetry build
poetry run twine check dist/*

publish:
python setup.py sdist upload
python setup.py bdist_wheel upload
poetry publish

update:
poetry update
poetry install -E dev

docs:
cd docs && make html
Expand Down
Loading

0 comments on commit 111a376

Please sign in to comment.