From e2bdb80dabf1d4d88f26ac0ca1348bd412f7d50c Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Mon, 10 Jun 2024 11:59:45 +0200 Subject: [PATCH] WIP: Refactor setup tools to `pyproject.toml`. --- .github/workflows/code-quality.yml | 36 +++ .github/workflows/pytest.yml | 37 +++ .github/workflows/test-build.yml | 14 +- .../{test-pytest.yml => test-docker.yml} | 2 +- README.rst => README.md | 0 pyproject.toml | 231 ++++++++++++++++++ setup.cfg | 152 ------------ setup.py | 23 -- 8 files changed, 311 insertions(+), 184 deletions(-) create mode 100644 .github/workflows/code-quality.yml create mode 100644 .github/workflows/pytest.yml rename .github/workflows/{test-pytest.yml => test-docker.yml} (98%) rename README.rst => README.md (100%) create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml new file mode 100644 index 00000000..5b968f6d --- /dev/null +++ b/.github/workflows/code-quality.yml @@ -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 diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 00000000..cd0c3582 --- /dev/null +++ b/.github/workflows/pytest.yml @@ -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/codecov-action@v4.0.1 + if: matrix.os == 'ubuntu-24.04' + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: aleph-im/aleph-sdk-python diff --git a/.github/workflows/test-build.yml b/.github/workflows/test-build.yml index a58d10f7..588219b8 100644 --- a/.github/workflows/test-build.yml +++ b/.github/workflows/test-build.yml @@ -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: @@ -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: | diff --git a/.github/workflows/test-pytest.yml b/.github/workflows/test-docker.yml similarity index 98% rename from .github/workflows/test-pytest.yml rename to .github/workflows/test-docker.yml index 457975c8..82c8d41a 100644 --- a/.github/workflows/test-pytest.yml +++ b/.github/workflows/test-docker.yml @@ -10,7 +10,7 @@ on: jobs: build: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 diff --git a/README.rst b/README.md similarity index 100% rename from README.rst rename to README.md diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..7874d6e3 --- /dev/null +++ b/pyproject.toml @@ -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 = "hello@aleph.im" }, +] +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" diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index fe2c4e5c..00000000 --- a/setup.cfg +++ /dev/null @@ -1,152 +0,0 @@ -# This file is used to configure your project. -# Read more about the various options under: -# http://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-setup-using-setup-cfg-files - -[metadata] -name = aleph-client -description = Lightweight Python Client library for the Aleph.im network -author = Aleph.im Team -author_email = hello@aleph.im -license = mit -long_description = file: README.rst -long_description_content_type = text/x-rst; charset=UTF-8 -url = https://github.com/aleph-im/aleph-client -project_urls = - Documentation = https://aleph.im/ -# Change if running only on Windows, Mac or Linux (comma-separated) -platforms = any -# Add here all kinds of additional classifiers as defined under -# https://pypi.python.org/pypi?%3Aaction=list_classifiers -classifiers = - Development Status :: 4 - Beta - Programming Language :: Python :: 3 - -[options] -zip_safe = False -packages = find: -include_package_data = True -package_dir = - =src -# DON'T CHANGE THE FOLLOWING LINE! IT WILL BE UPDATED BY PYSCAFFOLD! -setup_requires = pyscaffold>=3.2a0,<3.3a0 -# Add here dependencies of your project (semicolon/line-separated), e.g. -install_requires = - aleph-sdk-python~=0.9.1 - aleph-message>=0.4.3 - coincurve==17.0.0 - aiohttp==3.8.4 - eciespy==0.3.13 - typer==0.9.0 - eth_account==0.9.0 - python-magic==0.4.27 - pygments==2.16.1 - rich==13.6.0 - aiodns==3.1.1 -# The usage of test_requires is discouraged, see `Dependency Management` docs -# tests_require = pytest; pytest-cov -# Require a specific Python version, e.g. Python 2.7 or >= 3.4 -# python_requires = >=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.* - -[options.packages.find] -where = src -exclude = - tests - -[options.extras_require] -# Add here additional requirements for extra features, to install with: -# `pip install aleph-client[PDF]` like: -# PDF = ReportLab; RXP -# Add here test requirements (semicolon/line-separated) -testing = - 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.98.0 - # httpx is required in tests by fastapi.testclient - httpx==0.25.0 - types-requests==2.31.0.10 - types-setuptools==68.2.0.0 - typing_extensions==4.5.0 -nuls2 = - aleph-nuls2==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 - -[options.entry_points] -# Add here console scripts like: -console_scripts = - aleph = aleph_client.__main__:app -# For example: -# console_scripts = -# fibonacci = aleph_client.skeleton:run -# And any other entry points, for example: -# pyscaffold.cli = -# awesome = pyscaffoldext.awesome.extension:AwesomeExtension - -[test] -# py.test options when running `python setup.py test` -# addopts = --verbose -extras = True - -[tool:pytest] -# Options for py.test: -# Specify command line options as you would do when invoking py.test directly. -# e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml -# in order to write a coverage file that can be read by Jenkins. -addopts = - --cov aleph_client --cov-report term-missing - --verbose -norecursedirs = - dist - build - .tox -testpaths = tests - -[aliases] -dists = bdist_wheel - -[bdist_wheel] -# Use this option if your package is pure-python -universal = 0 - -[build_sphinx] -source_dir = docs -build_dir = build/sphinx - -[devpi:upload] -# Options for the devpi: PyPI server and packaging tool -# VCS export must be deactivated since we are using setuptools-scm -no-vcs = 1 -formats = bdist_wheel - -[flake8] -# Some sane defaults for the code style checker flake8 -exclude = - .tox - build - dist - .eggs - docs/conf.py - -[pyscaffold] -# PyScaffold's parameters when the project was created. -# This will be used when updating. Do not change! -version = 3.2.1 -package = aleph_client diff --git a/setup.py b/setup.py deleted file mode 100644 index 5ec256b1..00000000 --- a/setup.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -""" - Setup file for aleph_client. - Use setup.cfg to configure your project. - - This file was generated with PyScaffold 3.2.1. - PyScaffold helps you to put up the scaffold of your new Python project. - Learn more under: https://pyscaffold.org/ -""" -import sys - -from pkg_resources import VersionConflict, require -from setuptools import setup - -try: - require("setuptools>=38.3") -except VersionConflict: - print("Error: version of setuptools is too old (<38.3)!") - sys.exit(1) - - -if __name__ == "__main__": - setup(use_pyscaffold=True)