Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
branchvincent committed Oct 28, 2023
1 parent 821d306 commit 1f48a0c
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 63 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ on:
jobs:
test:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip')"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- name: Install dependencies
run: pip install poetry~=1.1 'copier>=6.0.0a6'
run: |
pipx install copier
pipx install poetry
- name: Run test
run: |
git config --global user.name "GitHub Action"
git config --global user.email "action@github.com"
copier -f -d docker=True -d docs=True . build/ && cd build/
copier copy --trust -f -d docker=True -d docs=True . build/ && cd build/
pwd
ls -la
poetry run task lint
- name: Push rendered project
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ A [Copier](https://github.com/copier-org/copier) template for a Python package b

## Usage

> **Requires**: copier>=6.0.0a7
```sh
copier gh:branchvincent/python-template <dest>
pipx run copier copy --trust gh:branchvincent/python-template <dest>
```

## Features

- Package manager: [Poetry](https://python-poetry.org/)
- Formatting: [Black](https://black.readthedocs.io/en/stable/) and [isort](https://isort.readthedocs.io/en/latest/)
- Formatting: [Ruff](https://docs.astral.sh/ruff/formatter/)
- Testing: [pytest](https://docs.pytest.org/en/latest/)
- Linting: [flake8](https://flake8.pycqa.org/) and [pre-commit](https://pre-commit.com/)
- Linting: [Ruff](https://docs.astral.sh/ruff/linter/) and [pre-commit](https://pre-commit.com/)
- Typing: [mypy](https://mypy.readthedocs.io/en/stable/)
- Task runner: [taskipy](https://github.com/illBeRoy/taskipy)
- CI/CD: [Github Actions](https://docs.github.com/en/actions)
Expand Down
3 changes: 1 addition & 2 deletions copier.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ _exclude:
- /macros
_skip_if_exists:
- pyproject.toml
_min_copier_version: 6.0.0a7
_tasks:
- bash postgenerate.sh
- bash -x postgenerate.sh
21 changes: 7 additions & 14 deletions src/.github/workflows/ci.yaml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,14 @@ on:
jobs:
build:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, 'ci skip')"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.9
- uses: actions/checkout@v4
- name: Set up Poetry
run: |
pip install poetry
poetry config virtualenvs.in-project true
- name: Set up cache
uses: actions/cache@v2
run: pipx install poetry
- uses: actions/setup-python@v4
with:
path: .venv
key: {% raw %}${{ runner.os }}-venv-py3.9-${{ hashFiles('**/poetry.lock') }}{% endraw %}
python-version: 3.12
cache: poetry
- name: Install package
run: poetry install
- name: Run linters
Expand All @@ -36,7 +29,7 @@ jobs:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && !contains(github.event.head_commit.message, 'cd skip')
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Bump version
uses: TriPSs/conventional-changelog-action@v3
id: version
Expand All @@ -58,7 +51,7 @@ jobs:
{% if not private -%}
- name: Publish to PyPI
if: steps.version.outputs.skipped == 'false'
run: pip install poetry && poetry publish --build
run: pipx run poetry publish --build
env:
POETRY_PYPI_TOKEN_PYPI: {% raw %}${{ secrets.PYPI_TOKEN }}{% endraw %}
{% endif -%}
Expand Down
23 changes: 8 additions & 15 deletions src/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.20.1
hooks:
- id: pyupgrade
- repo: local
hooks:
- id: isort
name: isort
entry: poetry run isort
language: system
types: [python]
- id: black
name: black
entry: poetry run black
- id: ruff-format
name: ruff-format
entry: poetry run ruff format
require_serial: true
language: system
types: [python]
- id: flake8
name: flake8
entry: poetry run pflake8
- id: ruff-check
name: ruff-check
entry: poetry run ruff check
require_serial: true
language: system
types: [python]
- id: mypy
Expand Down
3 changes: 1 addition & 2 deletions src/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ poetry run task --list

To ensure code quality, we use the following tools:

- Formatting: [black](https://black.readthedocs.io/en/stable/) and [isort](https://isort.readthedocs.io/en/latest/)
- Linting: [flake8](http://flake8.pycqa.org/en/latest/)
- Formatting and linting: [ruff](https://docs.astral.sh/ruff/)
- Type checking: [mypy](https://mypy.readthedocs.io/en/stable/)

To run these:
Expand Down
18 changes: 6 additions & 12 deletions src/pyproject.toml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,17 @@ classifiers = ["Private :: Do Not Upload"]
{%- endif %}

[tool.poetry.dependencies]
python = "^3.9"
python = "^3.12"

[tool.poetry.dev-dependencies]
black = "*"
flake8 = "*"
isort = "*"
[tool.poetry.group.dev.dependencies]
{% if docs -%}
mkdocs = "*"
mkdocs-material = "*"
{% endif -%}
mypy = "*"
pre-commit = "*"
pyproject-flake8 = "*"
pytest = "*"
ruff = "*"
taskipy = "*"

[tool.taskipy.tasks]
Expand All @@ -35,12 +32,9 @@ docs = { cmd = "mkdocs serve -f docs/mkdocs.yaml", help = "Serve documentation"}
lint = { cmd = "pre-commit run --all-files", help = "Run linters and formatters" }
test = { cmd = "pytest", help = "Run tests" }

[tool.flake8]
max-line-length = 88
extend-ignore = "E203"

[tool.isort]
profile = "black"
[tool.ruff]
fix = true
select = ["B", "E", "F", "I", "SIM", "UP"]

[tool.mypy]
strict = true
Expand Down
8 changes: 4 additions & 4 deletions src/{% if docker %}Dockerfile{% endif %}.jinja
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
FROM python:3.9-alpine AS base
FROM python:3.12-alpine AS base
WORKDIR /app

### Builder ###
FROM base AS builder

# Install poetry
RUN pip install --no-cache-dir poetry~=1.1 \
RUN pip install --no-cache-dir poetry~=1.6 \
&& poetry config virtualenvs.in-project true

# Install deps
COPY pyproject.toml poetry.lock ./
RUN poetry install --no-root --no-dev
RUN poetry install --no-root --only=main

# Add source
COPY . .
RUN poetry install --no-dev
RUN poetry install --only=main

### Runner ###
FROM base AS runner
Expand Down

0 comments on commit 1f48a0c

Please sign in to comment.