Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Upgrade to Poetry v1.2.0 and other related cleanup (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
pronovic authored Sep 5, 2022
1 parent 303998b commit 1316d41
Show file tree
Hide file tree
Showing 14 changed files with 577 additions and 477 deletions.
57 changes: 47 additions & 10 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# vim: set ft=yaml ts=2 sw=2:
name: Test Suite
on:
push:
Expand All @@ -10,44 +11,80 @@ on:
- cron: '05 17 15 * *' # 15th of the month at 5:05pm UTC
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: ["3.7", "3.8", "3.9", "3.10" ]
python: ["3.8", "3.9", "3.10" ]
runs-on: ${{ matrix.os }}
env:
# Run builds using a specific version of Poetry, to avoid surprises
POETRY_VERSION: "1.2.0"
# Prevent Poetry v1.2.0 from using the Python keyring, which sometimes fails or hangs on Linux
# See: https://github.com/python-poetry/poetry/issues/2692#issuecomment-1235683370
PYTHON_KEYRING_BACKEND: "keyring.backends.null.Keyring"
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install and configure Poetry
- name: Platform information
shell: bash
run: |
# Show platform information
python -c "import sys;print('Python %s' % sys.version)"
- name: Install Poetry
uses: snok/install-poetry@v1.2.1 # see https://github.com/snok/install-poetry
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install Poetry plugins
shell: bash
run: |
# Install Poetry plugins
poetry self add poetry-plugin-export
- name: Cache Poetry dependencies
uses: actions/cache@v2
with:
path: .venv
key: venv-${{ runner.os }}-${{ matrix.python }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
run: poetry install -v
shell: bash
run: |
# Install dependencies
poetry install --sync
- name: Upgrade embedded tools within virtualenv
run: poetry run pip install --upgrade pip setuptools wheel
shell: bash
run: |
# Upgrade embedded tools
poetry run pip install --upgrade pip setuptools wheel
- name: Run Tox test suite
run: poetry run tox -c .toxrc -e "checks,coverage"
shell: bash
run: |
# Run Tox test suite
poetry run tox -c .toxrc -e "checks,coverage"
- name: Upload coverage data to coveralls.io
run: poetry run coveralls --service=github
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: ${{ runner.os }}-python${{ matrix.python }}
COVERALLS_PARALLEL: true
run: |
# Upload coverage data to coveralls.io
poetry run coveralls --service=github
coveralls:
name: Indicate completion to coveralls.io
needs: build
runs-on: ubuntu-latest
container: python:3-slim
steps:
- name: Finished
run: |
pip3 install --upgrade coveralls
coveralls --service=github --finish
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Indicate completion to coveralls.io
pip3 install --upgrade coveralls
coveralls --service=github --finish
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
hooks:
- id: system
name: Requirements
entry: poetry export --format=requirements.txt --without-hashes --dev --output=docs/requirements.txt
entry: poetry export --format=requirements.txt --without-hashes --with dev --output=docs/requirements.txt
pass_filenames: false
language: system
- repo: local
Expand Down
9 changes: 0 additions & 9 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ disable=fixme,
missing-function-docstring,
unused-wildcard-import,
trailing-whitespace,
bad-continuation,
too-few-public-methods,
no-else-return,
no-else-raise,
no-self-use,
duplicate-code,
consider-using-f-string,
not-an-iterable, # gets confused with lists on attrs classes; MyPy covers this
Expand Down Expand Up @@ -273,13 +271,6 @@ max-line-length=132
# Maximum number of lines in a module.
max-module-lines=1000

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,
dict-separator

# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
Expand Down
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: 2
python:
version: 3.7
version: 3.8
install:
- requirements: docs/requirements.txt
6 changes: 3 additions & 3 deletions .toxrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ envlist =
ignore_basepython_conflict = true

[testenv:checks]
whitelist_externals = poetry
allowlist_externals = poetry
commands =
poetry --version
poetry version
poetry run pre-commit run --all-files --show-diff-on-failure

[testenv:coverage]
whitelist_externals = poetry
allowlist_externals = poetry
commands =
poetry --version
poetry version
Expand All @@ -23,7 +23,7 @@ commands =
poetry run coverage report

[testenv:docs]
whitelist_externals = poetry
allowlist_externals = poetry
changedir = docs
commands =
poetry --version
Expand Down
10 changes: 10 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Version 0.1.23 unreleased

* Remove support for Python 3.7.
* Upgrade to Poetry v1.2.0 and make related build process changes.
* Upgrade to Pylint v2.15.0 and make related changes to configuration
* Fix Pylint's configured class-attribute-naming-style to be snake_case.
* Add dependency caching to GitHub Actions workflow.
* Fix the GitHub Actions matrix build to properly target Windows and MacOS.
* Address annoying PyUnresolvedReferences warnings in PyCharm.

Version 0.1.22 09 Jun 2022

* Modernize usage of attrs library.
Expand Down
69 changes: 48 additions & 21 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ This code should work equivalently on MacOS, Linux, and Windows.

## Packaging and Dependencies

This project uses [Poetry](https://python-poetry.org/) to manage Python packaging and dependencies. Most day-to-day tasks (such as running unit tests from the command line) are orchestrated through Poetry.
This project uses [Poetry](https://python-poetry.org/) to manage Python packaging and dependencies. Most day-to-day tasks (such as running unit tests from the command line) are orchestrated through Poetry.

A coding standard is enforced using [Black](https://github.com/psf/black), [isort](https://pypi.org/project/isort/) and [Pylint](https://www.pylint.org/). Python 3 type hinting is validated using [MyPy](https://pypi.org/project/mypy/). To reduce boilerplate, classes are defined using [Attrs](https://www.attrs.org/) (see this [rationale](https://glyph.twistedmatrix.com/2016/08/attrs.html)).

To add dependencies use `poetry add package` (for runtime dependencies) or `poetry add --dev package` (for development environment dependencies).
To add dependencies use `poetry add package` (for runtime dependencies) or `poetry add --group dev package` (for development environment dependencies).

To update dependencies, use `poetry update`. This will update all of the dependencies without taking you past any major version changes that are likely to be incompatible. If you want to update a single package, use `poetry update package`. If you want to update past a major version change, either specify the version like `poetry add package=^2.0.3` or get the latest with `poetry add package@latest`.
To update dependencies, use `poetry update`. This will update all of the dependencies without taking you past any major version changes that are likely to be incompatible. If you want to update a single package, use `poetry update package`. If you want to update past a major version change, either specify the version like `poetry add package=^2.0.3` or get the latest with `poetry add package@latest`. [PEP 508](https://peps.python.org/pep-0508/) specifications are also supported.

## Pre-Commit Hooks

Expand Down Expand Up @@ -52,25 +52,47 @@ of this writing.
Nearly all prerequisites are managed by Poetry. All you need to do is make
sure that you have a working Python 3 enviroment and install Poetry itself.

### Poetry Version

The project is designed to work with Poetry >= 1.2.0. If you already have an older
version of Poetry installed on your system, uninstall it before following the setup
process below:

```
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3 - --uninstall
```

See the [Announcing Poetry 1.2.0](https://python-poetry.org/blog/announcing-poetry-1.2.0/)
blog post for more information.

### MacOS

On MacOS, it's easiest to use [Homebrew](https://brew.sh/):
On MacOS, it's easiest to use [Homebrew](https://brew.sh/) to install Python:

```
$ brew install python3
$ brew install poetry
brew install python3
```

Once that's done, make sure the `python` on your `$PATH` is Python 3 from
Homebrew (in `/usr/local`), rather than the standard Python 2 that comes with
MacOS.

Although Poetry can also be installed from Homebrew, it works better to use
to [official installer](https://python-poetry.org/docs/#installing-with-the-official-installer):

```
curl -sSL https://install.python-poetry.org | python3 -
```

> _Note:_ The installer prints the location of the installed `poetry` script.
> Make sure to add this to your `$PATH`, otherwise you won't be able to run it.
### Debian

First, install Python 3 and related tools:

```
$ sudo apt-get install python3 python3-venv python3-pip
sudo apt-get install python3 python3-venv python3-pip
```

Next, make sure that the `python` interpreter on your `$PATH` is Python 3.
Expand All @@ -81,42 +103,47 @@ However, by default there is only a `python3` interpreter on your `$PATH`, not
a `python` interpreter. To add the `python` interpreter, use:

```
$ sudo apt-get install python-is-python3
sudo apt-get install python-is-python3
```

For earlier releases of Debian where both Python 2 and Python 3 are available,
the process is a little more complicated. The approach I used before upgrading
to _bullseye_ was based on `update-alternatives`, as discussed on
[StackExchange](https://unix.stackexchange.com/a/410851).

Once Python 3 is on your `$PATH` as `python`, install Poetry in your home
directory:
Next, install Poetry using the [official installer](https://python-poetry.org/docs/#installing-with-the-official-installer):

```
$ curl -sSL https://install.python-poetry.org | python3 -
curl -sSL https://install.python-poetry.org | python3 -
```

> _Note:_ The installer prints the location of the installed `poetry` script.
> Make sure to add this to your `$PATH`, otherwise you won't be able to run it.
### Windows

First, install Python 3 from your preferred source, either a standard
installer or a meta-installer like Chocolatey. Make sure the `python`
on your `$PATH` is Python 3.

Then, install Poetry in your home directory:
Next, install Poetry using the [official installer](https://python-poetry.org/docs/#installing-with-the-official-installer):

```
$ curl -sSL https://install.python-poetry.org | python3 -
curl -sSL https://install.python-poetry.org | python -
```

The development environment (with the `run` script, etc.) expects a bash shell
> _Note:_ The installer prints the location of the installed `poetry` script.
> Make sure to add this to your `$PATH`, otherwise you won't be able to run it.
The development environment (the `run` script, etc.) expects a bash shell
to be available. On Windows, it works fine with the standard Git Bash.

## Developer Tasks

The [`run`](run) script provides shortcuts for common developer tasks:

```
$ run --help
run --help
------------------------------------
Shortcuts for common developer tasks
Expand All @@ -125,7 +152,6 @@ Shortcuts for common developer tasks
Usage: run <command>
- run install: Setup the virtualenv via Poetry and install pre-commit hooks
- run activate: Print command needed to activate the Poetry virtualenv
- run requirements: Regenerate the docs/requirements.txt file
- run format: Run the code formatters
- run checks: Run the code checkers
Expand Down Expand Up @@ -240,13 +266,13 @@ To run the demo, you must also have a server running elsewhere. Your
simplest option is to start the server in one window:

```
$ run server
run server
```

and the demo in another window:

```
$ run demo
run demo
```

The demo registers a "human" player, starts a 4-player game (getting 3
Expand Down Expand Up @@ -282,7 +308,7 @@ order. In particular, if you do not run the install step, there will be no
virtualenv for PyCharm to use:

```
$ run install && run checks && run test
run install && run checks && run test
```

### Open the Project
Expand Down Expand Up @@ -496,7 +522,7 @@ Version 0.1.29 unreleased
Run the release step:

```
$ run release 0.1.29
run release 0.1.29
```

This updates `pyproject.toml` and the `Changelog` to reflect the released
Expand All @@ -507,7 +533,7 @@ and revert your commit (`git reset HEAD~1`) if you made a mistake.
Finally, publish the release:

```
$ run publish
run publish
```

This builds the deployment artifacts, publishes the artifacts to PyPI, and
Expand Down Expand Up @@ -569,3 +595,4 @@ Deleting password for 'user' in 'testvalue':
At this point, the keyring should be fully functional and it should be ready
for use with Poetry. Whenever Poetry needs to read a secret from the keyring,
you'll get a popup window where you need to enter the keyring password.

Loading

0 comments on commit 1316d41

Please sign in to comment.