Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to Poetry and Nox #91

Merged
merged 20 commits into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
# Except the following.
!src
!LICENSE.txt
!MANIFEST.in
!pyproject.toml
!poetry.lock
!README.md
!requirements.txt
!setup.py

# Filter unwanted files from included folders.
**/__pycache__
Expand Down
17 changes: 10 additions & 7 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox
- run: tox -e docs-github-pages
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install Poetry
run: pipx install poetry
- name: Install all dependencies, including Nox
run: poetry install --no-root
- name: Publish Docs
run: poetry run nox -s docs_github_pages
20 changes: 11 additions & 9 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ name: python
on: [push, pull_request]

jobs:
tox:
nox:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.8", "3.9", "3.10" ]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions
- name: Test with tox
run: tox
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install Poetry
run: pipx install poetry
- name: Install all dependencies, including Nox
run: poetry install --no-root
- name: Test with Nox
run: poetry run nox
19 changes: 9 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
*.egg-info
.tox
.idea
__pycache__
.coverage
.coverage.*
htmlcov
*.pyc
venv
dist
.pytest_cache
.mypy_cache
.nox
.pytest_cache
dist
build
htmlcov
site
__pycache__
*.pyc
*.egg-info
.coverage
.coverage.*
22 changes: 18 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# will need to be recompiled fully within the Docker images, increasing build times.
FROM python:3.9-slim-bullseye AS python_builder

# Pin Poetry to a specific version to make Docker builds reproducible.
ENV POETRY_VERSION 1.1.13

# Set ENV variables that make Python more friendly to running inside a container.
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONBUFFERED 1
Expand All @@ -31,21 +34,32 @@ WORKDIR ${WORKDIR}
# gcc \
# && rm -rf /var/lib/apt/lists/*

# Install Poetry into the global environment to isolate it from the venv. This prevents Poetry
# from uninstalling parts of itself.
# TODO: Improve Poetry usage in multi-stage Dockerfiles once these issues are fixed in Poetry.
# Non-editable `poetry install`: https://github.com/python-poetry/poetry/issues/1382
# Specifying venv path: https://github.com/python-poetry/poetry/issues/1579
RUN pip install "poetry==${POETRY_VERSION}"

# Copy in project dependency specification.
COPY pyproject.toml poetry.lock ./
RUN poetry export --output requirements.txt

# Pre-download/compile wheel dependencies into a virtual environment.
# Doing this in a multi-stage build allows ommitting compile dependencies from the final image.
RUN python -m venv ${VIRTUAL_ENV}
ENV PATH "${VIRTUAL_ENV}/bin:${PATH}"

COPY requirements.txt ${WORKDIR}
RUN pip install --upgrade pip wheel && \
pip install -r requirements.txt

# Copy in source files.
COPY LICENSE.txt MANIFEST.in pyproject.toml README.md requirements.txt setup.py ./
COPY README.md ./
COPY src src

# Install console script.
RUN pip install .
# Don't install the package itself with Poetry because it will install it as an editable install.
RUN poetry build && \
pip install dist/*.whl

## Final Image
# The image used in the final image MUST match exactly to the python_builder image.
Expand Down
5 changes: 0 additions & 5 deletions MANIFEST.in

This file was deleted.

Loading