Skip to content

Commit

Permalink
WIP: Refactor setup tools to pyproject.toml.
Browse files Browse the repository at this point in the history
  • Loading branch information
hoh committed Jun 10, 2024
1 parent 991ae3c commit e2bdb80
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 184 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test code quality

on:
push:
pull_request:
branches:
- main

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

steps:
- uses: actions/checkout@v4

- name: Workaround github issue https://github.com/actions/runner-images/issues/7192
run: sudo echo RESET grub-efi/install_devices | sudo debconf-communicate grub-pc

- name: Install pip and hatch
run: |
sudo apt-get install -y python3-pip
pip3 install hatch hatch-vcs
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-code-quality-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-code-quality-
- name: Install required system packages only for Ubuntu Linux
run: sudo apt-get install -y libsecp256k1-dev

- name: Run Hatch lint
run: hatch run linting:all
37 changes: 37 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Pytest and code Coverage

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
# Run every night at 04:00 (GitHub Actions timezone)
# in order to catch when unfrozen dependency updates
# break the use of the library.
- cron: '4 0 * * *'

jobs:
build:
strategy:
matrix:
os: [ macos-11, macos-12, macos-13, macos-14, ubuntu-20.04, ubuntu-22.04, ubuntu-24.04 ]
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v4
- run: sudo apt-get install -y python3-pip libsecp256k1-dev
- run: python -m pip install --upgrade pip hatch coverage

# Only run coverage on one OS
- run: hatch run testing:test
if: matrix.python-version != '3.11'
- run: hatch run testing:cov
if: matrix.os == 'ubuntu-24.04'
- uses: codecov/[email protected]
if: matrix.os == 'ubuntu-24.04'
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: aleph-im/aleph-sdk-python
14 changes: 6 additions & 8 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ on:
- master

jobs:
build:
strategy:
build:
strategy:
matrix:
os: [macos-11, macos-12, ubuntu-20.04, ubuntu-22.04]
os: [macos-11, macos-12, macos-13, macos-14, ubuntu-20.04, ubuntu-22.04, ubuntu-24.04]
runs-on: ${{matrix.os}}

steps:
Expand All @@ -35,22 +35,20 @@ jobs:
with:
python-version: 3.11


- name: Install required system packages only for Ubuntu Linux
if: startsWith(matrix.os, 'ubuntu-')
run: |
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install -y libsecp256k1-dev
- name: Install required Python packages
run: |
python3 -m pip install --upgrade build
python3 -m pip install --user --upgrade twine
python3 -m pip install --upgrade hatch hatch-vcs
- name: Build source and wheel packages
run: |
python3 -m build
hatch build
- name: Install the Python wheel
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2
Expand Down
File renamed without changes.
231 changes: 231 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "aleph-client"
dynamic = ["version"]
description = "Python Client library for the Aleph.im network"
readme = "README.md"
readme-content-type = "text/x-rst; charset=UTF-8"
requires-python = ">=3.6"
license = { file = "LICENSE.txt" }
authors = [
{ name = "Aleph.im Team", email = "[email protected]" },
]
keywords = ["Aleph.im", "Client", "Library", "Python"]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3",
"Environment :: Console",
"Framework :: aiohttp",
"License :: OSI Approved :: MIT License",
"Topic :: System :: Distributed Computing",
]

dependencies = [
"aleph-sdk-python~=0.9.1",
"aleph-message>=0.4.5",
"coincurve==18.0.0",
"aiohttp==3.9.5",
"eciespy==0.4.1",
"typer==0.12.3",
"eth-account==0.11.2",
"python-magic==0.4.27",
"pygments==2.18.0",
"rich==13.7.1",
"aiodns==3.2.0",
]
[project.optional-dependencies]
nuls2 = ["nuls2-sdk==0.1.0"]
ethereum = ["eth_account>=0.4.0"]
polkadot = ["substrate-interface==1.3.4"]
cosmos = ["cosmospy==6.0.0"]
solana = ["pynacl==1.5.0", "base58==2.1.1"]
tezos = ["pynacl==1.5.0", "aleph-pytezos==0.1.0"]
docs = ["sphinxcontrib-plantuml==0.27"]

[project.urls]
Documentation = "https://docs.aleph.im/tools/aleph-client/"
Issues = "https://github.com/aleph-im/aleph-client/issues"
Source = "https://github.com/aleph-im/aleph-client"
Discussions = "https://community.aleph.im/"

[project.scripts]
aleph = "aleph_client.__main__:app"

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

[tool.hatch.build.targets.sdist]
include = [
"src/aleph_client",
]

[tool.hatch.build.targets.wheel]
packages = ["src/aleph_client"]

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

[tool.hatch.envs.default]
platforms = ["linux", "osx", "windows"]
dependencies = [
# "pytest==7.4.2",
# "pytest-asyncio==0.21.1",
# "pytest-cov==4.1.0",
# "mypy==1.5.1",
# "secp256k1==0.14.0",
# "pynacl==1.5.0",
# "base58==2.1.1",
# "aleph-pytezos==0.1.0",
# "fastapi==0.111.0",
# "httpx==0.25.0",
# "types-requests==2.31.0.10",
# "types-setuptools==68.2.0.0",
# "typing_extensions==4.5.0",
# "sphinxcontrib-plantuml==0.27"
]

[tool.hatch.envs.testing]
type = "virtual"
dependencies = [
"pytest==8.2.2",
# "pytest-asyncio==0.23.7",
# "pytest-cov==5.0.0",
# "mypy==1.10.0",
# "secp256k1==0.14.0",
# "pynacl==1.5.0",
# "base58==2.1.1",
# "aleph-pytezos==0.1.0",
# "fastapi==0.98.0",
# "httpx==0.27.0",
# "types-requests==2.32.0.20240602",
# "types-setuptools==70.0.0.20240524",
# "typing_extensions==4.12.2",
]
[tool.hatch.envs.testing.scripts]
test = "pytest {args:tests}"
test-cov = "pytest --cov {args:tests}"
cov-report = [
"coverage combine",
"coverage report",
]
cov = [
"test-cov",
"cov-report",
]

[[tool.hatch.envs.all.matrix]]
python = ["3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.linting]
dependencies = [
"black==24.1.1",
"mypy==1.8.0",
"ruff==0.1.15",
"isort==5.13.2",
]
[tool.hatch.envs.linting.scripts]
typing = "mypy {args:src/aleph_client/ tests/}"
style = [
# "ruff {args:.}",
"black --check --diff {args:.}",
"isort --check-only --profile black {args:.}",
]
fmt = [
"black {args:.}",
# "ruff --fix {args:.}",
"isort --profile black {args:.}",
"style",
]
all = [
"style",
"typing",
]

[tool.pytest.ini_options]
pythonpath = [
"src"
]
testpaths = [
"tests"
]

[tool.black]
line-length = 120
target-version = ["py39"]

[tool.mypy]
python_version = "3.9"
install_types = true
non_interactive = true
ignore_missing_imports = true
explicit_package_bases = true
check_untyped_defs = true

[tool.ruff]
target-version = "py39"
line-length = 120
select = [
"A",
"ARG",
"B",
"C",
"DTZ",
"E",
"EM",
"F",
"FBT",
"I",
"ICN",
"ISC",
"N",
"PLC",
"PLE",
"PLR",
"PLW",
"Q",
"RUF",
"S",
"T",
"TID",
"UP",
"W",
"YTT",
]
ignore = [
# # Allow non-abstract empty methods in abstract base classes
# "B027",
# # Allow boolean positional values in function calls, like `dict.get(... True)`
# "FBT003",
# # Ignore checks for possible passwords
# "S105", "S106", "S107",
# # Ignore complexity
# "C901", "PLR0911", "PLR0912", "PLR0913", "PLR0915",
# Allow the use of assert statements
"S101"
]

#[tool.ruff.isort]
#known-first-party = ["aleph_client"]

[tool.coverage.run]
branch = true
parallel = true
source_pkgs = ["aleph_client", "tests"]

[tool.coverage.paths]
aleph_client = ["src/aleph_client"]
tests = ["tests"]

[tool.coverage.report]
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
"if TYPE_CHECKING:",
]

[tool.spinx]
source-dir = "docs"
build-dir = "docs/_build"
Loading

0 comments on commit e2bdb80

Please sign in to comment.