Skip to content

Commit

Permalink
feat: migrate to pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
Psycojoker committed Jan 10, 2025
1 parent e1e2f92 commit 0f67f01
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 85 deletions.
20 changes: 5 additions & 15 deletions .github/workflows/tests.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ name: Tests

on:
push:
pull_request:
branches:
- main
pull_request:
branches:
- "*"

jobs:
build:
Expand All @@ -19,24 +21,12 @@ jobs:

- name: Build the Docker image
run: |
git fetch --prune --unshallow --tags
git fetch --tags
docker build . -t aleph-message:${GITHUB_REF##*/} -f Dockerfile --cache-from=docker.pkg.github.com/$GITHUB_REPOSITORY/aleph-message-build-cache
- name: Cache the image on GitHub's repository
run: docker tag aleph-message:${GITHUB_REF##*/} docker.pkg.github.com/$GITHUB_REPOSITORY/aleph-message-build-cache && docker push docker.pkg.github.com/$GITHUB_REPOSITORY/aleph-message-build-cache || true

- name: Test with black in the Docker image
run: |
docker run aleph-message:${GITHUB_REF##*/} black --check aleph_message
- name: Test with ruff in the Docker image
run: |
docker run aleph-message:${GITHUB_REF##*/} ruff check aleph_message
- name: Pytest in the Docker image
run: |
docker run aleph-message:${GITHUB_REF##*/} pytest -vv --cov aleph_message
- name: MyPy in the Docker image
run: |
docker run aleph-message:${GITHUB_REF##*/} mypy aleph_message --install-types --non-interactive --check-untyped-defs --ignore-missing-imports
docker run aleph-message:${GITHUB_REF##*/} python -m "from aleph_message import parse_message"
32 changes: 32 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Tests

on:
push:
branches:
- main
pull_request:
branches:
- "*"

jobs:
code-quality:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/pip
~/.local/share/hatch/env/virtual/
key: ${GITHUB_JOB}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${GITHUB_JOB}
- run: |
python3 -m venv /tmp/venv
/tmp/venv/bin/python -m pip install --upgrade pip hatch coverage
- run: /tmp/venv/bin/hatch run linting:all
42 changes: 42 additions & 0 deletions .github/workflows/pytests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Tests

on:
push:
branches:
- main
pull_request:
branches:
- "*"

jobs:
tests:
strategy:
fail-fast: false
matrix:
python-version: [ "3.9", "3.10", "3.11", "3.12" ]
os: [ubuntu-22.04, ubuntu-24.04]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3

- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/pip
~/.local/share/hatch/env/virtual/
key: ${{ runner.os }}-${GITHUB_JOB}-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-${GITHUB_JOB}
- run: |
python3 -m venv /tmp/venv
/tmp/venv/bin/python -m pip install --upgrade pip hatch coverage
- run: /tmp/venv/bin/hatch run testing:cov

- uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: aleph-im/aleph-message
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM ubuntu:20.04
FROM ubuntu:24.04
RUN apt-get update && apt-get install -y python3-pip

RUN pip install pytest requests types-requests pytest-cov mypy twine typing-extensions
RUN pip install types-requests mypy twine typing-extensions hatch
COPY . /opt/aleph-message
WORKDIR /opt/aleph-message
RUN pip install -e .
RUN pip install mypy ruff black
RUN hatch build
159 changes: 159 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
[build-system]
build-backend = "hatchling.build"

requires = [ "hatch-vcs", "hatchling" ]

[project]
name = "aleph-message"
description = "Aleph.im message specification"
readme = "README.md"
license = { file = "LICENSE" }
authors = [
{ name = "Hugo Herter", email = "[email protected]" },
]
requires-python = ">=3"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: System :: Distributed Computing",
]
dynamic = [ "version" ]
dependencies = [
"pydantic>=1.10.5,<2",
"typing-extensions>=4.5",
]
urls.Documentation = "https://aleph.im/"
urls.Homepage = "https://github.com/aleph-im/aleph-message"

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.version]
source = "vcs"

[tool.hatch.build.targets.wheel]
packages = [
"Dockerfile",
"LICENSE",
"pyproject.toml",
"README.md",
"aleph_message",
]

[tool.hatch.build.targets.sdist]
include = [
"Dockerfile",
"LICENSE",
"pyproject.toml",
"README.md",
"aleph_message",
]

[tool.hatch.envs.testing]
dependencies = [
"requests",
"rich",
"pytest==8.0.1",
"pytest-cov==4.1.0",
]

# XXX see https://github.com/aleph-im/pyaleph/blob/main/.github/workflows/pyaleph-ci.yml
[tool.hatch.envs.testing.scripts]
test = "pytest -v {args:.}"
test-cov = "pytest -v --cov {args:.}"
cov-report = [
"- coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]

[tool.hatch.envs.linting]
detached = true
dependencies = [
"black==24.2.0",
"mypy==1.2.0",
"mypy-extensions==1.0.0",
"ruff==0.4.8",
"isort==5.13.2",
"check-sdist==0.1.3",
"yamlfix==1.16.1",
"pyproject-fmt==2.2.1",
"types-requests",
"typing-extensions",
]

[tool.hatch.envs.linting.scripts]
typing = "mypy --config-file=pyproject.toml {args:} ./aleph_message/"
style = [
"ruff check {args:.}",
"black --check --diff {args:} ./aleph_message/",
"isort --check-only --profile black {args:} ./aleph_message/",
"yamlfix --check .",
"pyproject-fmt --check pyproject.toml",
]
sdist = "check-sdist --inject-junk"
fmt = [
"black {args:} ./aleph_message/",
"ruff check --fix {args:.} ./aleph_message/",
"isort --profile black {args:} ./aleph_message/",
"yamlfix .",
"pyproject-fmt pyproject.toml",
"style",
]
all = [
"style",
"typing",
"sdist",
]

[tool.isort]
profile = "black"

[tool.check-sdist]
git-only = [
"tests",
"docs",
"deployment",
".coveragerc",
".dockerignore",
"shell.nix",
]
default-ignore = true

[tool.pytest]
markers = [
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
]

[tool.coverage.run]
branch = true
parallel = true
source = [
"aleph_message/",
]
omit = [
"*/site-packages/*",
]

[tool.coverage.paths]
source = [
"aleph_message/",
]
omit = [
"*/site-packages/*",
]

[tool.yamlfix]
sequence_style = "keep_style"
preserve_quotes = true
whitelines = 1
section_whitelines = 2
3 changes: 0 additions & 3 deletions pytest.ini

This file was deleted.

63 changes: 0 additions & 63 deletions setup.py

This file was deleted.

0 comments on commit 0f67f01

Please sign in to comment.