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

Migrate from dev-dependencies to dependency-groups #15

Merged
merged 8 commits into from
Jan 16, 2025
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
52 changes: 42 additions & 10 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,50 @@
# https://github.com/devcontainers/images/tree/main/src/python
FROM mcr.microsoft.com/devcontainers/python:1-3.12-bookworm
#FROM mcr.microsoft.com/devcontainers/python:1-3.13-bookworm
FROM python:3.13-slim-bookworm

# https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME --shell /bin/bash \
# [Optional] Add sudo support. Omit if you don't need to install software after connecting.
&& apt-get update \
&& apt-get install -y sudo \
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

# Install additional packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends \
# <your-package-list-here> \
# && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
git \
make \
openssh-client \
&& apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*

# Install the project into `/app`
WORKDIR /app

# Enable bytecode compilation
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy

# Install UV / UVX
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
ENV UV_COMPILE_BYTECODE=1
ENV UV_LINK_MODE=copy

# Install project dependencies
RUN --mount=type=bind,source=pyproject.toml,target=pyproject.toml \
--mount=type=bind,source=uv.lock,target=uv.lock \
uv sync --frozen --no-install-project --all-extras
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-install-project --all-groups \
&& rm pyproject.toml uv.lock \
&& chown -R $USERNAME:$USERNAME /app

# Place executables in the environment at the front of the path
ENV PATH="/app/.venv/bin:$PATH"

# HACK: https://github.com/sphinx-doc/sphinx/issues/11739
ENV LC_ALL=C.UTF-8

# [Optional] Set the default user. Omit if you want to keep the default as root.
USER $USERNAME
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Exclude the project virtual environment from image builds
.venv
8 changes: 4 additions & 4 deletions .github/workflows/docker-build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ on:
branches:
- main
paths:
- Pipfile
- Pipfile.lock
- .devcontainer/Dockerfile
- pyproject.toml
- uv.lock
pull_request:
branches:
- main
paths:
- Pipfile
- Pipfile.lock
- .devcontainer/Dockerfile
- pyproject.toml
- uv.lock
workflow_dispatch:

jobs:
Expand Down
16 changes: 12 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ build-backend = "setuptools.build_meta"
[project]
name = "python_training_project"
authors = [
{name = "Andreas", email = "[email protected]"},
{name = "Thomas", email = "[email protected]"},
{name = "Andreas Nussberger", email = "[email protected]"},
{name = "Thomas Keller", email = "[email protected]"},
]
description = "Python Training Project by devminds GmbH"
readme = "README.md"
Expand All @@ -33,8 +33,8 @@ dynamic = ["version"]
[project.scripts]
python_training_project = "python_training_project.__main__:cli"

[tool.uv]
dev-dependencies = [
[dependency-groups]
dev = [
"coverage",
"flake8",
"mypy",
Expand All @@ -54,6 +54,9 @@ write_to = "src/python_training_project/version.py"
[tool.pytest.ini_options]
minversion = "6.0"
addopts = "--cov --cov-report term --cov-report xml --junitxml=build/test-report.xml"
pythonpath = [
"src",
]
testpaths = [
"tests",
]
Expand All @@ -79,3 +82,8 @@ include = [
"tests/**/*.py"
]
output-format = "pylint"

[tool.pylint.main]
ignore = [
"version.py"
]
4 changes: 2 additions & 2 deletions src/python_training_project/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import click

from python_training_project.calculate import sum
from python_training_project.calculate import calc_sum

log = logging.getLogger(__name__)

Expand All @@ -28,7 +28,7 @@ def cli():
@click.argument("b", type=float)
def cli_sum(a: float, b: float):
"""Show the sum of two numbers on the console."""
log.info("Sum of %f and %f is %f", a, b, sum(a, b))
log.info("Sum of %f and %f is %f", a, b, calc_sum(a, b))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion src/python_training_project/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""


def sum(a: float, b: float) -> float:
def calc_sum(a: float, b: float) -> float:
"""Calculate the sum of two numbers."""
return a + b

Expand Down
16 changes: 8 additions & 8 deletions tests/test_calculate.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from python_training_project.calculate import sum
from python_training_project.calculate import calc_sum


def test_sum():
assert sum(1, 1) == 2
assert sum(2, 1) == 3
assert sum(1, 2) == 3
def test_calc_sum():
assert calc_sum(1, 1) == 2
assert calc_sum(2, 1) == 3
assert calc_sum(1, 2) == 3


def test_sum_negative():
assert sum(1, -1) == 0
assert sum(-1, 1) == 0
assert sum(-1, -1) == -2
assert calc_sum(1, -1) == 0
assert calc_sum(-1, 1) == 0
assert calc_sum(-1, -1) == -2
2 changes: 1 addition & 1 deletion tools/build-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ pushd "${REPO_ROOT}" 2>&1 > /dev/null
echo "Building documentation..."
mkdir -p build
cd docs
uv run --all-extras make html
make html

popd 2>&1 > /dev/null
10 changes: 5 additions & 5 deletions tools/lint-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ STATUS=0
set +e

echo "Running flake8..."
uv run --all-extras flake8 src/python_training_project --format=pylint > build/flake8.txt
flake8 src/python_training_project --format=pylint > build/flake8.txt
if [ $? -ne 0 ]; then
STATUS=1
fi

echo "Running mypy..."
uv run --all-extras mypy src/python_training_project > build/mypy.txt
mypy src/python_training_project > build/mypy.txt
if [ $? -ne 0 ]; then
STATUS=1
fi

echo "Running pylint..."
uv run --all-extras pylint src/python_training_project --msg-template="{path}:{line}: [{msg_id}, {obj}] {msg} ({symbol})" > build/pylint.txt
pylint src/python_training_project --msg-template="{path}:{line}: [{msg_id}, {obj}] {msg} ({symbol})" > build/pylint.txt
if [ $? -ne 0 ]; then
STATUS=1
fi

echo "Running ruff check..."
uv run --all-extras ruff check > build/ruff.txt
ruff check > build/ruff.txt
if [ $? -ne 0 ]; then
STATUS=1
fi

echo "Running ruff format..."
uv run --all-extras ruff format --check
ruff format --check
if [ $? -ne 0 ]; then
STATUS=1
fi
Expand Down
2 changes: 1 addition & 1 deletion tools/test-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ pushd "${REPO_ROOT}" 2>&1 > /dev/null
mkdir -p build

echo "Running tests..."
uv run --all-extras pytest
pytest

popd 2>&1 > /dev/null
3 changes: 1 addition & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading