From 2a7526b4252f4efe69677e3d493d711c1a167227 Mon Sep 17 00:00:00 2001 From: mhh Date: Wed, 13 Mar 2024 16:28:06 +0100 Subject: [PATCH 01/29] Setup hatch for project & dependencies management --- pyproject.toml | 105 ++++++++++++++++++++++++++++++++++++++++++ src/aleph/__init__.py | 1 + 2 files changed, 106 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..1ddbc278 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,105 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "aleph-sdk-python" +dynamic = ["version"] +description = "Lightweight Python Client library for the Aleph.im network" +readme = "README.md" +license = "mit" +authors = [ + { name = "Aleph.im Team", email = "hello@aleph.im" }, +] +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python :: 3", +] +dependencies = [ + "aiohttp>=3.8.3", + "aleph-message~=0.4.3", + "coincurve; python_version<\"3.11\"", + "coincurve>=17.0.0; python_version>=\"3.11\"", + "eciespy; python_version<\"3.11\"", + "eciespy>=0.3.13; python_version>=\"3.11\"", + "eth_abi>=4.0.0; python_version>=\"3.11\"", + "eth_account>=0.4.0", + "python-magic", + "typer", + "typing_extensions", +] + +[project.optional-dependencies] +cosmos = [ + "cosmospy", +] +dns = [ + "aiodns", +] +docs = [ + "sphinxcontrib-plantuml", +] +ethereum = [ + "eth_abi>=4.0.0; python_version>=\"3.11\"", + "eth_account>=0.4.0", +] +ledger = [ + "ledgereth==0.9.0", +] +mqtt = [ + "aiomqtt<=0.1.3", + "certifi", + "Click", +] +nuls2 = [ + "aleph-nuls2", +] +polkadot = [ + "py-sr25519-bindings", + "substrate-interface", +] +solana = [ + "base58", + "pynacl", +] +testing = [ + "aiodns", + "aiomqtt<=0.1.3", + "aleph-pytezos==0.1.1", + "base58", + "black", + "fastapi", + "flake8", + "httpx", + "isort", + "ledgereth==0.9.0", + "mypy", + "psutil", + "py-sr25519-bindings", + "pynacl", + "pytest", + "pytest-asyncio", + "pytest-cov", + "pytest-mock", + "requests", + "secp256k1", + "substrate-interface", + "types-certifi", + "types-setuptools", +] +tezos = [ + "aleph-pytezos==0.1.1", + "pynacl", +] + +[project.urls] +Documentation = "https://aleph.im/" +Homepage = "https://github.com/aleph-im/aleph-sdk-python" + +[tool.hatch.version] +path = "src/aleph/__init__.py" + +[tool.hatch.build.targets.sdist] +include = [ + "/src", +] diff --git a/src/aleph/__init__.py b/src/aleph/__init__.py index e69de29b..3efa2fa4 100644 --- a/src/aleph/__init__.py +++ b/src/aleph/__init__.py @@ -0,0 +1 @@ +VERSION = "0.9.1" From 2777788678b1b5f99f0cd1f5265a9ba7070255db Mon Sep 17 00:00:00 2001 From: mhh Date: Wed, 13 Mar 2024 16:32:01 +0100 Subject: [PATCH 02/29] Fix build targets --- pyproject.toml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 1ddbc278..52233d6e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,7 +99,17 @@ Homepage = "https://github.com/aleph-im/aleph-sdk-python" [tool.hatch.version] path = "src/aleph/__init__.py" +[tool.hatch.build.targets.wheel] +packages = [ + "src/aleph", + "pyproject.toml", + "README.md", + "LICENSE.txt", +] [tool.hatch.build.targets.sdist] include = [ - "/src", -] + "src/aleph", + "pyproject.toml", + "README.md", + "LICENSE.txt", +] \ No newline at end of file From 99a4aa78ca480f324d9738fba0c5540135b72436 Mon Sep 17 00:00:00 2001 From: mhh Date: Wed, 13 Mar 2024 16:34:44 +0100 Subject: [PATCH 03/29] Add Mike as author --- AUTHORS.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index a7c7459a..65119268 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -5,3 +5,4 @@ Contributors * Henry Taieb * Hugo Herter * Moshe Malawach +* Mike Hukiewitz \ No newline at end of file From 2d6e2498c019bdd12ca6a74b571f80104b1f2e9a Mon Sep 17 00:00:00 2001 From: mhh Date: Wed, 13 Mar 2024 16:49:08 +0100 Subject: [PATCH 04/29] Remove unneeded files --- CHANGELOG.rst | 8 --- setup.cfg | 181 -------------------------------------------------- setup.py | 23 ------- 3 files changed, 212 deletions(-) delete mode 100644 CHANGELOG.rst delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst deleted file mode 100644 index 30607221..00000000 --- a/CHANGELOG.rst +++ /dev/null @@ -1,8 +0,0 @@ -========= -Changelog -========= - -Version 0.1 -=========== - -- Converted from minialeph \ No newline at end of file diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 1d71a697..00000000 --- a/setup.cfg +++ /dev/null @@ -1,181 +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-sdk-python -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.md -long_description_content_type = text/markdown; charset=UTF-8 -url = https://github.com/aleph-im/aleph-sdk-python -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 = - coincurve; python_version<"3.11" - coincurve>=17.0.0; python_version>="3.11" # Technically, this should be >=18.0.0 but there is a conflict with eciespy - aiohttp>=3.8.3 - typing_extensions - typer - aleph-message~=0.4.3 - eth_account>=0.4.0 - # Required to fix a dependency issue with parsimonious and Python3.11 - eth_abi>=4.0.0; python_version>="3.11" - python-magic -# 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-sdk-python[PDF]` like: -# PDF = ReportLab; RXP -# Add here test requirements (semicolon/line-separated) -testing = - aiomqtt<=0.1.3 - psutil - pytest - pytest-cov - pytest-asyncio - pytest-mock - mypy - secp256k1 - pynacl - base58 - fastapi - # httpx is required in tests by fastapi.testclient - httpx - requests - aleph-pytezos==0.1.1 - types-certifi - types-setuptools - black - isort - flake8 - substrate-interface - py-sr25519-bindings - ledgereth==0.9.0 - aiodns - eciespy; python_version<"3.11" - eciespy>=0.3.13; python_version>="3.11" -dns = - aiodns -mqtt = - aiomqtt<=0.1.3 - certifi - Click -nuls2 = - aleph-nuls2 -ethereum = - eth_account>=0.4.0 - # Required to fix a dependency issue with parsimonious and Python3.11 - eth_abi>=4.0.0; python_version>="3.11" -polkadot = - substrate-interface - py-sr25519-bindings -cosmos = - cosmospy -solana = - pynacl - base58 -tezos = - pynacl - aleph-pytezos==0.1.1 -ledger = - ledgereth==0.9.0 -docs = - sphinxcontrib-plantuml -encryption = - eciespy; python_version<"3.11" - eciespy>=0.3.13; python_version>="3.11" - -[options.entry_points] -# Add here console scripts like: -# For example: -# console_scripts = -# fibonacci = aleph.sdk.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.sdk --cov-report term-missing - --verbose - -m "not ledger_hardware" -norecursedirs = - dist - build - .tox -testpaths = tests -markers = - "ledger_hardware: marks tests as requiring ledger hardware" -[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 -ignore = E501 W291 W503 E203 E704 - -[isort] -profile = black - -[pyscaffold] -# PyScaffold's parameters when the project was created. -# This will be used when updating. Do not change! -version = 3.2.1 -package = aleph.sdk diff --git a/setup.py b/setup.py deleted file mode 100644 index 9b29e6b3..00000000 --- a/setup.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -""" - Setup file for aleph.sdk - 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) From 3d483071ba547a2236dd6e8fec14a0084bcd6ede Mon Sep 17 00:00:00 2001 From: mhh Date: Wed, 13 Mar 2024 16:57:38 +0100 Subject: [PATCH 05/29] Add missing configs from setup.py --- pyproject.toml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 52233d6e..18b3d204 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -106,10 +106,28 @@ packages = [ "README.md", "LICENSE.txt", ] + [tool.hatch.build.targets.sdist] include = [ "src/aleph", "pyproject.toml", "README.md", "LICENSE.txt", -] \ No newline at end of file +] + +[tool.pytest] +addopts = ["--cov=aleph.sdk", "--cov-report=term-missing", "--verbose", "-m", "not ledger_hardware"] +norecursedirs = ["dist", "build", ".tox"] +testpaths = ["tests"] +markers = {ledger_hardware = "marks tests as requiring ledger hardware"} + +[tool.devpi.upload] +no-vcs = 1 +formats = ["bdist_wheel"] + +[tool.flake8] +exclude = [".tox", "build", "dist", ".eggs", "docs/conf.py"] +ignore = ["E501", "W291", "W503", "E203", "E704"] + +[tool.isort] +profile = "black" From 428469d291ce099578a7cfc2fe3fc5629ec14efd Mon Sep 17 00:00:00 2001 From: mhh Date: Wed, 13 Mar 2024 17:21:03 +0100 Subject: [PATCH 06/29] Update README.md to reflect latest changes and use hatch in setup --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e2e74cf9..12efc42e 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,9 @@ Python SDK for the Aleph.im network, next generation network of decentralized bi Development follows the [Aleph Whitepaper](https://github.com/aleph-im/aleph-whitepaper). ## Documentation -Documentation (albeit still vastly incomplete as it is a work in progress) can be found at [http://aleph-sdk-python.readthedocs.io/](http://aleph-sdk-python.readthedocs.io/) or built from this repo with: +The latest documentation, albeit incomplete, is available at [https://docs.aleph.im/libraries/python-sdk/](https://docs.aleph.im/libraries/python-sdk/). -```shell -$ python setup.py docs -``` +For the full documentation, please refer to the docstrings in the source code. ## Requirements ### Linux @@ -31,18 +29,55 @@ $ brew install libsecp256k1 Using pip and [PyPI](https://pypi.org/project/aleph-sdk-python/): ```shell -$ pip install aleph-sdk-python[ethereum,solana,tezos] +$ pip install aleph-sdk-python ``` +### Additional dependencies +Some functionalities require additional dependencies. They can be installed like this: + +```shell +$ pip install aleph-sdk-python[ethereum, dns] +``` + +The following extra dependencies are available: +- `ethereum` for Ethereum and Ethereum-compatible chains +- `solana` for Solana accounts and signatures +- `cosmos` for Substrate/Cosmos accounts and signatures +- `nuls2` for NULS2 accounts and signatures +- `polkadot` for Polkadot accounts and signatures +- `ledger` for Ledger hardware wallet support, see [Usage with LedgerHQ hardware](#usage-with-ledgerhq-hardware) +- `mqtt` for MQTT-related functionalities, see [examples/mqtt.py](examples/mqtt.py) +- `docs` for building the documentation, see [Documentation](#documentation) +- `dns` for DNS-related functionalities +- `testing` installs all dependencies required for running the tests + + ## Installation for development -To install from source and still be able to modify the source code: +Setup a virtual environment using [hatch](https://hatch.pypa.io/): +```shell +$ hatch shell +``` + +Then install the SDK from source with all extra dependencies: ```shell $ pip install -e .[testing] ``` -or + +### Generating the documentation [DEPRECATED] +The documentation is built using [Sphinx](https://www.sphinx-doc.org/). + +To build the documentation, install the SDK with the `docs` extra dependencies: + +```shell +$ pip install -e .[docs] +``` + +Then build the documentation: + ```shell -$ python setup.py develop +$ cd docs +$ make html ``` ## Usage with LedgerHQ hardware From c3df27c0adaf7de9205e952b6e4916daf3498753 Mon Sep 17 00:00:00 2001 From: mhh Date: Wed, 13 Mar 2024 17:38:33 +0100 Subject: [PATCH 07/29] Add Flake8-pyproject plugin to enable flake8 configuration through pyproject.toml; Add ethereum deps to "testing" deps; Update workflows to only use `pip install -e .[testing]` --- .github/workflows/code-quality.yml | 2 +- docker/python-3.10.dockerfile | 2 +- docker/python-3.11.dockerfile | 2 +- docker/python-3.9.dockerfile | 2 +- docker/ubuntu-20.04.dockerfile | 2 +- docker/ubuntu-22.04.dockerfile | 2 +- docker/with-ipfs.dockerfile | 2 +- pyproject.toml | 7 +++++-- src/aleph/__init__.py | 2 +- src/aleph/sdk/conf.py | 4 +--- src/aleph/sdk/types.py | 12 ++++++++---- src/aleph/sdk/utils.py | 6 ++++-- 12 files changed, 26 insertions(+), 19 deletions(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 6576a34e..c9feb682 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -32,7 +32,7 @@ jobs: - name: Install required Python packages run: | - python3 -m pip install -e .[testing,ethereum] + python3 -m pip install -e .[testing] - name: Test with Black run: | diff --git a/docker/python-3.10.dockerfile b/docker/python-3.10.dockerfile index 3af183ca..4b7a0d38 100644 --- a/docker/python-3.10.dockerfile +++ b/docker/python-3.10.dockerfile @@ -29,7 +29,7 @@ USER root RUN chown -R user:user /opt/aleph-sdk-python RUN git config --global --add safe.directory /opt/aleph-sdk-python -RUN pip install -e .[testing,ethereum,solana,tezos,ledger] +RUN pip install -e .[testing] RUN mkdir /data RUN chown user:user /data diff --git a/docker/python-3.11.dockerfile b/docker/python-3.11.dockerfile index 644195a7..45494783 100644 --- a/docker/python-3.11.dockerfile +++ b/docker/python-3.11.dockerfile @@ -29,7 +29,7 @@ USER root RUN chown -R user:user /opt/aleph-sdk-python RUN git config --global --add safe.directory /opt/aleph-sdk-python -RUN pip install -e .[testing,ethereum,solana,tezos,ledger] +RUN pip install -e .[testing] RUN mkdir /data RUN chown user:user /data diff --git a/docker/python-3.9.dockerfile b/docker/python-3.9.dockerfile index ff6d3c41..c5df3bf0 100644 --- a/docker/python-3.9.dockerfile +++ b/docker/python-3.9.dockerfile @@ -29,7 +29,7 @@ USER root RUN chown -R user:user /opt/aleph-sdk-python RUN git config --global --add safe.directory /opt/aleph-sdk-python -RUN pip install -e .[testing,ethereum,solana,tezos,ledger] +RUN pip install -e .[testing] RUN mkdir /data RUN chown user:user /data diff --git a/docker/ubuntu-20.04.dockerfile b/docker/ubuntu-20.04.dockerfile index cb0d7c7e..22bd1196 100644 --- a/docker/ubuntu-20.04.dockerfile +++ b/docker/ubuntu-20.04.dockerfile @@ -34,7 +34,7 @@ USER root RUN chown -R user:user /opt/aleph-sdk-python RUN git config --global --add safe.directory /opt/aleph-sdk-python -RUN pip install -e .[testing,ethereum,solana,tezos,ledger] +RUN pip install -e .[testing] RUN mkdir /data RUN chown user:user /data diff --git a/docker/ubuntu-22.04.dockerfile b/docker/ubuntu-22.04.dockerfile index 8e44e482..8ebfb4c3 100644 --- a/docker/ubuntu-22.04.dockerfile +++ b/docker/ubuntu-22.04.dockerfile @@ -34,7 +34,7 @@ USER root RUN chown -R user:user /opt/aleph-sdk-python RUN git config --global --add safe.directory /opt/aleph-sdk-python -RUN pip install -e .[testing,ethereum,solana,tezos,ledger] +RUN pip install -e .[testing] RUN mkdir /data RUN chown user:user /data diff --git a/docker/with-ipfs.dockerfile b/docker/with-ipfs.dockerfile index e9625f18..507ee0ea 100644 --- a/docker/with-ipfs.dockerfile +++ b/docker/with-ipfs.dockerfile @@ -29,7 +29,7 @@ RUN mkdir /opt/aleph-sdk-python/ WORKDIR /opt/aleph-sdk-python/ COPY . . -RUN pip install -e .[testing,ethereum] +RUN pip install -e .[testing] # - User 'aleph' to run the code itself diff --git a/pyproject.toml b/pyproject.toml index 18b3d204..37b244ba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -68,8 +68,11 @@ testing = [ "aleph-pytezos==0.1.1", "base58", "black", + "eth_abi>=4.0.0; python_version>=\"3.11\"", + "eth_account>=0.4.0", "fastapi", "flake8", + "Flake8-pyproject", "httpx", "isort", "ledgereth==0.9.0", @@ -115,8 +118,8 @@ include = [ "LICENSE.txt", ] -[tool.pytest] -addopts = ["--cov=aleph.sdk", "--cov-report=term-missing", "--verbose", "-m", "not ledger_hardware"] +[tool.pytest.ini_options] +addopts = "--cov=aleph.sdk --cov-report=term-missing --verbose -m \"not ledger_hardware\"" norecursedirs = ["dist", "build", ".tox"] testpaths = ["tests"] markers = {ledger_hardware = "marks tests as requiring ledger hardware"} diff --git a/src/aleph/__init__.py b/src/aleph/__init__.py index 3efa2fa4..d69d16e9 100644 --- a/src/aleph/__init__.py +++ b/src/aleph/__init__.py @@ -1 +1 @@ -VERSION = "0.9.1" +__version__ = "0.9.1" diff --git a/src/aleph/sdk/conf.py b/src/aleph/sdk/conf.py index 318536e4..f8d798c6 100644 --- a/src/aleph/sdk/conf.py +++ b/src/aleph/sdk/conf.py @@ -29,9 +29,7 @@ class Settings(BaseSettings): REMOTE_CRYPTO_UNIX_SOCKET: Optional[str] = None ADDRESS_TO_USE: Optional[str] = None - DEFAULT_RUNTIME_ID: str = ( - "f873715dc2feec3833074bd4b8745363a0e0093746b987b4c8191268883b2463" # Debian 12 official runtime - ) + DEFAULT_RUNTIME_ID: str = "f873715dc2feec3833074bd4b8745363a0e0093746b987b4c8191268883b2463" # Debian 12 official runtime DEFAULT_VM_MEMORY: int = 256 DEFAULT_VM_VCPUS: int = 1 DEFAULT_VM_TIMEOUT: float = 30.0 diff --git a/src/aleph/sdk/types.py b/src/aleph/sdk/types.py index 2f57b280..67c0dda3 100644 --- a/src/aleph/sdk/types.py +++ b/src/aleph/sdk/types.py @@ -18,19 +18,23 @@ class Account(Protocol): CURVE: str @abstractmethod - async def sign_message(self, message: Dict) -> Dict: ... + async def sign_message(self, message: Dict) -> Dict: + ... @abstractmethod - def get_address(self) -> str: ... + def get_address(self) -> str: + ... @abstractmethod - def get_public_key(self) -> str: ... + def get_public_key(self) -> str: + ... class AccountFromPrivateKey(Account, Protocol): """Only accounts that are initialized from a private key string are supported.""" - def __init__(self, private_key: bytes): ... + def __init__(self, private_key: bytes): + ... GenericMessage = TypeVar("GenericMessage", bound=AlephMessage) diff --git a/src/aleph/sdk/utils.py b/src/aleph/sdk/utils.py index ab17f44a..72a219b9 100644 --- a/src/aleph/sdk/utils.py +++ b/src/aleph/sdk/utils.py @@ -98,11 +98,13 @@ def check_unix_socket_valid(unix_socket_path: str) -> bool: class AsyncReadable(Protocol[T]): - async def read(self, n: int = -1) -> T: ... + async def read(self, n: int = -1) -> T: + ... class Writable(Protocol[U]): - def write(self, buffer: U) -> int: ... + def write(self, buffer: U) -> int: + ... async def copy_async_readable_to_buffer( From e0bd8f694b7753b0dd2631df2235faf8c242096e Mon Sep 17 00:00:00 2001 From: mhh Date: Wed, 13 Mar 2024 17:42:53 +0100 Subject: [PATCH 08/29] Revert faulty formatting --- src/aleph/sdk/conf.py | 4 +++- src/aleph/sdk/types.py | 12 ++++-------- src/aleph/sdk/utils.py | 6 ++---- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/aleph/sdk/conf.py b/src/aleph/sdk/conf.py index f8d798c6..318536e4 100644 --- a/src/aleph/sdk/conf.py +++ b/src/aleph/sdk/conf.py @@ -29,7 +29,9 @@ class Settings(BaseSettings): REMOTE_CRYPTO_UNIX_SOCKET: Optional[str] = None ADDRESS_TO_USE: Optional[str] = None - DEFAULT_RUNTIME_ID: str = "f873715dc2feec3833074bd4b8745363a0e0093746b987b4c8191268883b2463" # Debian 12 official runtime + DEFAULT_RUNTIME_ID: str = ( + "f873715dc2feec3833074bd4b8745363a0e0093746b987b4c8191268883b2463" # Debian 12 official runtime + ) DEFAULT_VM_MEMORY: int = 256 DEFAULT_VM_VCPUS: int = 1 DEFAULT_VM_TIMEOUT: float = 30.0 diff --git a/src/aleph/sdk/types.py b/src/aleph/sdk/types.py index 67c0dda3..2f57b280 100644 --- a/src/aleph/sdk/types.py +++ b/src/aleph/sdk/types.py @@ -18,23 +18,19 @@ class Account(Protocol): CURVE: str @abstractmethod - async def sign_message(self, message: Dict) -> Dict: - ... + async def sign_message(self, message: Dict) -> Dict: ... @abstractmethod - def get_address(self) -> str: - ... + def get_address(self) -> str: ... @abstractmethod - def get_public_key(self) -> str: - ... + def get_public_key(self) -> str: ... class AccountFromPrivateKey(Account, Protocol): """Only accounts that are initialized from a private key string are supported.""" - def __init__(self, private_key: bytes): - ... + def __init__(self, private_key: bytes): ... GenericMessage = TypeVar("GenericMessage", bound=AlephMessage) diff --git a/src/aleph/sdk/utils.py b/src/aleph/sdk/utils.py index 72a219b9..ab17f44a 100644 --- a/src/aleph/sdk/utils.py +++ b/src/aleph/sdk/utils.py @@ -98,13 +98,11 @@ def check_unix_socket_valid(unix_socket_path: str) -> bool: class AsyncReadable(Protocol[T]): - async def read(self, n: int = -1) -> T: - ... + async def read(self, n: int = -1) -> T: ... class Writable(Protocol[U]): - def write(self, buffer: U) -> int: - ... + def write(self, buffer: U) -> int: ... async def copy_async_readable_to_buffer( From 543d2c7c7cdc3f605b37f9081e439b6773b02682 Mon Sep 17 00:00:00 2001 From: mhh Date: Wed, 13 Mar 2024 18:24:46 +0100 Subject: [PATCH 09/29] Move mypy.ini to pyproject.toml and make it lean --- mypy.ini | 67 -------------------------------------------------- pyproject.toml | 14 +++++++++++ 2 files changed, 14 insertions(+), 67 deletions(-) delete mode 100644 mypy.ini diff --git a/mypy.ini b/mypy.ini deleted file mode 100644 index 87a87653..00000000 --- a/mypy.ini +++ /dev/null @@ -1,67 +0,0 @@ -# Global options: - -[mypy] -python_version = 3.8 - -mypy_path = src - -exclude = conftest.py - - -show_column_numbers = True - -# Suppressing errors -# Shows errors related to strict None checking, if the global strict_optional flag is enabled -strict_optional = True -no_implicit_optional = True - -# Import discovery -# Suppresses error messages about imports that cannot be resolved -ignore_missing_imports = True -# Forces import to reference the original source file -no_implicit_reexport = True -# show error messages from unrelated files -follow_imports = silent -follow_imports_for_stubs = False - - -# Disallow dynamic typing -# Disallows usage of types that come from unfollowed imports -disallow_any_unimported = False -# Disallows all expressions in the module that have type Any -disallow_any_expr = False -# Disallows functions that have Any in their signature after decorator transformation. -disallow_any_decorated = False -# Disallows explicit Any in type positions such as type annotations and generic type parameters. -disallow_any_explicit = False -# Disallows usage of generic types that do not specify explicit type parameters. -disallow_any_generics = False -# Disallows subclassing a value of type Any. -disallow_subclassing_any = False - -# Untyped definitions and calls -# Disallows calling functions without type annotations from functions with type annotations. -disallow_untyped_calls = False -# Disallows defining functions without type annotations or with incomplete type annotations -disallow_untyped_defs = False -# Disallows defining functions with incomplete type annotations. -check_untyped_defs = True -# Type-checks the interior of functions without type annotations. -disallow_incomplete_defs = False -# Reports an error whenever a function with type annotations is decorated with a decorator without annotations. -disallow_untyped_decorators = False - -# Prohibit comparisons of non-overlapping types (ex: 42 == "no") -strict_equality = True - -# Configuring warnings -# Warns about unneeded # type: ignore comments. -warn_unused_ignores = True -# Shows errors for missing return statements on some execution paths. -warn_no_return = True -# Shows a warning when returning a value with type Any from a function declared with a non- Any return type. -warn_return_any = False - -# Miscellaneous strictness flags -# Allows variables to be redefined with an arbitrary type, as long as the redefinition is in the same block and nesting level as the original definition. -allow_redefinition = True diff --git a/pyproject.toml b/pyproject.toml index 37b244ba..9ece91ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -134,3 +134,17 @@ ignore = ["E501", "W291", "W503", "E203", "E704"] [tool.isort] profile = "black" + +[tool.mypy] +python_version = 3.8 +mypy_path = "src" +exclude = "conftest.py" +show_column_numbers = "True" + +# Import discovery +# Suppresses error messages about imports that cannot be resolved (no py.typed file, no stub file, etc). +ignore_missing_imports = "True" + +# Miscellaneous strictness flags +# Allows variables to be redefined with an arbitrary type, as long as the redefinition is in the same block and nesting level as the original definition. +allow_redefinition = "True" From 7b60805e7960c7b4df592bac85a0a31825f5742c Mon Sep 17 00:00:00 2001 From: mhh Date: Wed, 13 Mar 2024 18:28:58 +0100 Subject: [PATCH 10/29] Remove need for mypy.ini in workflow --- .github/workflows/code-quality.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index c9feb682..2ae32791 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -44,7 +44,7 @@ jobs: - name: Test with MyPy run: | - mypy --config-file ./mypy.ini ./src/ ./tests/ ./examples/ + mypy ./src/ ./tests/ ./examples/ - name: Test with flake8 run: | From 4d4da2b32e2ff03f2beb4a92dfd8d3020ac694a1 Mon Sep 17 00:00:00 2001 From: mhh Date: Wed, 13 Mar 2024 18:51:47 +0100 Subject: [PATCH 11/29] Fix mypy config --- pyproject.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9ece91ac..3aebc7ef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -138,12 +138,17 @@ profile = "black" [tool.mypy] python_version = 3.8 mypy_path = "src" -exclude = "conftest.py" +exclude = [ + "conftest.py" +] show_column_numbers = "True" # Import discovery # Suppresses error messages about imports that cannot be resolved (no py.typed file, no stub file, etc). ignore_missing_imports = "True" +# Don't follow imports +follow_imports = "silent" + # Miscellaneous strictness flags # Allows variables to be redefined with an arbitrary type, as long as the redefinition is in the same block and nesting level as the original definition. From 1b9e86c1cbe1f168c0cfc685591acd79acc1f0a8 Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 14 Mar 2024 10:48:59 +0100 Subject: [PATCH 12/29] Adding py.typed marker and automatically install type stubs when running mypy --- pyproject.toml | 10 +++++++--- src/aleph/py.typed | 0 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 src/aleph/py.typed diff --git a/pyproject.toml b/pyproject.toml index 3aebc7ef..998b9a35 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,6 +77,7 @@ testing = [ "isort", "ledgereth==0.9.0", "mypy", + "mypy-extensions", "psutil", "py-sr25519-bindings", "pynacl", @@ -141,15 +142,18 @@ mypy_path = "src" exclude = [ "conftest.py" ] -show_column_numbers = "True" +show_column_numbers = true # Import discovery +# Install types for third-party library stubs (e.g. from typeshed repository) +install_types = true +non_interactive = true # Suppresses error messages about imports that cannot be resolved (no py.typed file, no stub file, etc). -ignore_missing_imports = "True" +ignore_missing_imports = true # Don't follow imports follow_imports = "silent" # Miscellaneous strictness flags # Allows variables to be redefined with an arbitrary type, as long as the redefinition is in the same block and nesting level as the original definition. -allow_redefinition = "True" +allow_redefinition = true diff --git a/src/aleph/py.typed b/src/aleph/py.typed new file mode 100644 index 00000000..e69de29b From 0504a51b955dbc125196c153589b005a5aa08578 Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 14 Mar 2024 10:53:07 +0100 Subject: [PATCH 13/29] Use LICENCE.txt file in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 998b9a35..902e11a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "aleph-sdk-python" dynamic = ["version"] description = "Lightweight Python Client library for the Aleph.im network" readme = "README.md" -license = "mit" +license = { file = "LICENSE.txt" } authors = [ { name = "Aleph.im Team", email = "hello@aleph.im" }, ] From 8948883d7cc00c40fcaadee80db1e9f8040f4123 Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 14 Mar 2024 10:53:18 +0100 Subject: [PATCH 14/29] Add classifiers --- pyproject.toml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 902e11a8..f778151c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,8 +12,14 @@ authors = [ { name = "Aleph.im Team", email = "hello@aleph.im" }, ] classifiers = [ - "Development Status :: 4 - Beta", "Programming Language :: Python :: 3", + "Development Status :: 4 - Beta", + "Framework :: aiohttp", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: POSIX :: Linux", + "Operating System :: MacOS :: MacOS X", + "Topic :: Software Development :: Libraries", ] dependencies = [ "aiohttp>=3.8.3", From 890773c48f840b115a5254c6405afa77034d0712 Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 14 Mar 2024 10:53:37 +0100 Subject: [PATCH 15/29] Use VCS version (git tag) --- pyproject.toml | 4 ++-- src/aleph/__init__.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f778151c..53d3b9f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["hatchling"] +requires = ["hatchling", "hatch-vcs"] build-backend = "hatchling.build" [project] @@ -107,7 +107,7 @@ Documentation = "https://aleph.im/" Homepage = "https://github.com/aleph-im/aleph-sdk-python" [tool.hatch.version] -path = "src/aleph/__init__.py" +source = "vcs" [tool.hatch.build.targets.wheel] packages = [ diff --git a/src/aleph/__init__.py b/src/aleph/__init__.py index d69d16e9..e69de29b 100644 --- a/src/aleph/__init__.py +++ b/src/aleph/__init__.py @@ -1 +0,0 @@ -__version__ = "0.9.1" From 8dece12f0c427b04498b7daa251fbebe8dbca293 Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 14 Mar 2024 11:04:40 +0100 Subject: [PATCH 16/29] Add envs for testing and linting --- pyproject.toml | 53 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 53d3b9f0..80885c15 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -131,10 +131,6 @@ norecursedirs = ["dist", "build", ".tox"] testpaths = ["tests"] markers = {ledger_hardware = "marks tests as requiring ledger hardware"} -[tool.devpi.upload] -no-vcs = 1 -formats = ["bdist_wheel"] - [tool.flake8] exclude = [".tox", "build", "dist", ".eggs", "docs/conf.py"] ignore = ["E501", "W291", "W503", "E203", "E704"] @@ -142,6 +138,55 @@ ignore = ["E501", "W291", "W503", "E203", "E704"] [tool.isort] profile = "black" +[tool.hatch.envs.testing] +dependencies = [ + "pytest==8.0.1", + "pytest-cov==4.1.0", + "pytest-mock==3.12.0", + "pytest-asyncio==0.23.5", +] +[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.lint] +detached = true +dependencies = [ + "black==24.1.1", + "mypy==1.8.0", + "mypy-extensions==0.4.3", + "ruff==0.1.15", + "isort==5.13.2", +] +[tool.hatch.envs.lint.scripts] +typing = "mypy {args:src/aleph/vm/ tests/ examples/example_fastapi runtimes/aleph-debian-12-python}" +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.mypy] python_version = 3.8 mypy_path = "src" From fb22bfb553bb46249d9ce2396353be725d77dcd7 Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 14 Mar 2024 11:18:30 +0100 Subject: [PATCH 17/29] Merge optional encryption dependencies from #110 --- pyproject.toml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 80885c15..6dd8528e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,8 +26,6 @@ dependencies = [ "aleph-message~=0.4.3", "coincurve; python_version<\"3.11\"", "coincurve>=17.0.0; python_version>=\"3.11\"", - "eciespy; python_version<\"3.11\"", - "eciespy>=0.3.13; python_version>=\"3.11\"", "eth_abi>=4.0.0; python_version>=\"3.11\"", "eth_account>=0.4.0", "python-magic", @@ -94,13 +92,17 @@ testing = [ "requests", "secp256k1", "substrate-interface", - "types-certifi", - "types-setuptools", + "eciespy; python_version<\"3.11\"", + "eciespy>=0.3.13; python_version>=\"3.11\"", ] tezos = [ "aleph-pytezos==0.1.1", "pynacl", ] +encryption = [ + "eciespy; python_version<\"3.11\"", + "eciespy>=0.3.13; python_version>=\"3.11\"", +] [project.urls] Documentation = "https://aleph.im/" From 9058e49c6cc8ee517b67545e993c89a9a768b10b Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 14 Mar 2024 14:01:31 +0100 Subject: [PATCH 18/29] Fix test and coverage; remove need for docker files in pytest workflow --- .coveragerc | 31 -------------- .github/workflows/pytest-docker.yml | 38 ----------------- .github/workflows/pytest.yml | 34 +++++++++++++++ docker/python-3.10.dockerfile | 39 ------------------ docker/python-3.11.dockerfile | 39 ------------------ docker/python-3.9.dockerfile | 39 ------------------ docker/ubuntu-20.04.dockerfile | 44 -------------------- docker/ubuntu-22.04.dockerfile | 44 -------------------- pyproject.toml | 64 ++++++++++++++++++++++++----- 9 files changed, 88 insertions(+), 284 deletions(-) delete mode 100644 .coveragerc delete mode 100644 .github/workflows/pytest-docker.yml create mode 100644 .github/workflows/pytest.yml delete mode 100644 docker/python-3.10.dockerfile delete mode 100644 docker/python-3.11.dockerfile delete mode 100644 docker/python-3.9.dockerfile delete mode 100644 docker/ubuntu-20.04.dockerfile delete mode 100644 docker/ubuntu-22.04.dockerfile diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index bf5bfda2..00000000 --- a/.coveragerc +++ /dev/null @@ -1,31 +0,0 @@ -# .coveragerc to control coverage.py -[run] -branch = True -source = aleph.sdk -# omit = bad_file.py - -[paths] -source = - src/ - */site-packages/ - -[report] -# Regexes for lines to exclude from consideration -exclude_lines = - # Have to re-enable the standard pragma - pragma: no cover - - # Don't complain about missing debug-only code: - def __repr__ - if self\.debug - - # Don't complain if tests don't hit defensive assertion code: - raise AssertionError - raise NotImplementedError - - # Don't complain if non-runnable code isn't run: - if 0: - if __name__ == .__main__.: - - # Don't complain about ineffective code: - pass diff --git a/.github/workflows/pytest-docker.yml b/.github/workflows/pytest-docker.yml deleted file mode 100644 index d6e0759d..00000000 --- a/.github/workflows/pytest-docker.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: Test using Pytest in Docker - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - build: - strategy: - matrix: - image: [ "python-3.9", "python-3.10", "python-3.11", "ubuntu-20.04", "ubuntu-22.04" ] - runs-on: ubuntu-22.04 - - steps: - - uses: actions/checkout@v3 - - # Use GitHub's Docker registry to cache intermediate layers - - run: echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com -u $GITHUB_ACTOR --password-stdin - - run: docker pull docker.pkg.github.com/$GITHUB_REPOSITORY/aleph-sdk-python-build-cache || true - - - name: Build the Docker image - run: | - git fetch --prune --unshallow --tags - docker build . -t aleph-sdk-python:${GITHUB_REF##*/} -f docker/${{matrix.image}}.dockerfile --cache-from=docker.pkg.github.com/$GITHUB_REPOSITORY/aleph-sdk-python-build-cache - - - name: Push the image on GitHub's repository - run: docker tag aleph-sdk-python:${GITHUB_REF##*/} docker.pkg.github.com/$GITHUB_REPOSITORY/aleph-sdk-python:${GITHUB_REF##*/} && docker push docker.pkg.github.com/$GITHUB_REPOSITORY/aleph-sdk-python:${GITHUB_REF##*/} || true - - - name: Cache the image on GitHub's repository - run: docker tag aleph-sdk-python:${GITHUB_REF##*/} docker.pkg.github.com/$GITHUB_REPOSITORY/aleph-sdk-python-build-cache && docker push docker.pkg.github.com/$GITHUB_REPOSITORY/aleph-sdk-python-build-cache || true - - - name: Pytest in the Docker image - run: | - docker run --entrypoint /opt/venv/bin/pytest aleph-sdk-python:${GITHUB_REF##*/} /opt/aleph-sdk-python/ diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 00000000..8328caae --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,34 @@ +name: Test with Python ${{ matrix.python-version }} + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + strategy: + matrix: + python-version: [ 3.8, 3.9, 3.10, 3.11 ] + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - run: apt-get install -y python3-pip libsecp256k1-dev + - run: python -m pip install --upgrade pip hatch + - run: hatch build + - run: hatch run testing:run + if: matrix.python-version != '3.11' + - run: hatch run testing:run-coverage-report + if: matrix.python-version == '3.11' + - uses: codecov/codecov-action@v4.0.1 + if: matrix.python-version == '3.11' + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: aleph-im/aleph-vm diff --git a/docker/python-3.10.dockerfile b/docker/python-3.10.dockerfile deleted file mode 100644 index 4b7a0d38..00000000 --- a/docker/python-3.10.dockerfile +++ /dev/null @@ -1,39 +0,0 @@ -FROM python:3.10-bullseye -MAINTAINER The aleph.im project - -RUN apt-get update && apt-get -y upgrade && apt-get install -y \ - libsecp256k1-dev \ - && rm -rf /var/lib/apt/lists/* - -RUN useradd -s /bin/bash --create-home user -RUN mkdir /opt/venv -RUN mkdir /opt/aleph-sdk-python/ -RUN chown user:user /opt/venv -RUN chown user:user /opt/aleph-sdk-python - -USER user -RUN python3 -m venv /opt/venv -ENV PATH="/opt/venv/bin:$PATH" -ENV PATH="/opt/venv/bin:$PATH" - -RUN pip install --upgrade pip wheel twine - -# Preinstall dependencies for faster steps -RUN pip install --upgrade secp256k1 coincurve aiohttp eciespy python-magic typer -RUN pip install --upgrade 'aleph-message~=0.4.0' eth_account pynacl base58 -RUN pip install --upgrade pytest pytest-cov pytest-asyncio mypy types-setuptools pytest-asyncio fastapi httpx requests - -WORKDIR /opt/aleph-sdk-python/ -COPY . . -USER root -RUN chown -R user:user /opt/aleph-sdk-python - -RUN git config --global --add safe.directory /opt/aleph-sdk-python -RUN pip install -e .[testing] - -RUN mkdir /data -RUN chown user:user /data -ENV ALEPH_PRIVATE_KEY_FILE=/data/secret.key - -WORKDIR /home/user -USER user diff --git a/docker/python-3.11.dockerfile b/docker/python-3.11.dockerfile deleted file mode 100644 index 45494783..00000000 --- a/docker/python-3.11.dockerfile +++ /dev/null @@ -1,39 +0,0 @@ -FROM python:3.11-bullseye -MAINTAINER The aleph.im project - -RUN apt-get update && apt-get -y upgrade && apt-get install -y \ - libsecp256k1-dev \ - && rm -rf /var/lib/apt/lists/* - -RUN useradd -s /bin/bash --create-home user -RUN mkdir /opt/venv -RUN mkdir /opt/aleph-sdk-python/ -RUN chown user:user /opt/venv -RUN chown user:user /opt/aleph-sdk-python - -USER user -RUN python3 -m venv /opt/venv -ENV PATH="/opt/venv/bin:$PATH" -ENV PATH="/opt/venv/bin:$PATH" - -RUN pip install --upgrade pip wheel twine - -# Preinstall dependencies for faster steps -RUN pip install --upgrade secp256k1 coincurve aiohttp eciespy python-magic typer -RUN pip install --upgrade 'aleph-message~=0.4.0' pynacl base58 -RUN pip install --upgrade pytest pytest-cov pytest-asyncio mypy types-setuptools pytest-asyncio fastapi httpx requests - -WORKDIR /opt/aleph-sdk-python/ -COPY . . -USER root -RUN chown -R user:user /opt/aleph-sdk-python - -RUN git config --global --add safe.directory /opt/aleph-sdk-python -RUN pip install -e .[testing] - -RUN mkdir /data -RUN chown user:user /data -ENV ALEPH_PRIVATE_KEY_FILE=/data/secret.key - -WORKDIR /home/user -USER user diff --git a/docker/python-3.9.dockerfile b/docker/python-3.9.dockerfile deleted file mode 100644 index c5df3bf0..00000000 --- a/docker/python-3.9.dockerfile +++ /dev/null @@ -1,39 +0,0 @@ -FROM python:3.9-bullseye -MAINTAINER The aleph.im project - -RUN apt-get update && apt-get -y upgrade && apt-get install -y \ - libsecp256k1-dev \ - && rm -rf /var/lib/apt/lists/* - -RUN useradd -s /bin/bash --create-home user -RUN mkdir /opt/venv -RUN mkdir /opt/aleph-sdk-python/ -RUN chown user:user /opt/venv -RUN chown user:user /opt/aleph-sdk-python - -USER user -RUN python3 -m venv /opt/venv -ENV PATH="/opt/venv/bin:$PATH" -ENV PATH="/opt/venv/bin:$PATH" - -RUN pip install --upgrade pip wheel twine - -# Preinstall dependencies for faster steps -RUN pip install --upgrade secp256k1 coincurve aiohttp eciespy python-magic typer -RUN pip install --upgrade 'aleph-message~=0.4.0' eth_account pynacl base58 -RUN pip install --upgrade pytest pytest-cov pytest-asyncio mypy types-setuptools pytest-asyncio fastapi httpx requests - -WORKDIR /opt/aleph-sdk-python/ -COPY . . -USER root -RUN chown -R user:user /opt/aleph-sdk-python - -RUN git config --global --add safe.directory /opt/aleph-sdk-python -RUN pip install -e .[testing] - -RUN mkdir /data -RUN chown user:user /data -ENV ALEPH_PRIVATE_KEY_FILE=/data/secret.key - -WORKDIR /home/user -USER user diff --git a/docker/ubuntu-20.04.dockerfile b/docker/ubuntu-20.04.dockerfile deleted file mode 100644 index 22bd1196..00000000 --- a/docker/ubuntu-20.04.dockerfile +++ /dev/null @@ -1,44 +0,0 @@ -FROM ubuntu:20.04 -MAINTAINER The aleph.im project - -RUN apt-get update && apt-get -y upgrade && apt-get install -y \ - libsecp256k1-dev \ - python3-dev \ - python3-venv \ - git \ - build-essential \ - libgmp3-dev \ - && rm -rf /var/lib/apt/lists/* - -RUN useradd -s /bin/bash --create-home user -RUN mkdir /opt/venv -RUN mkdir /opt/aleph-sdk-python/ -RUN chown user:user /opt/venv -RUN chown user:user /opt/aleph-sdk-python - -USER user -RUN python3 -m venv /opt/venv -ENV PATH="/opt/venv/bin:$PATH" -ENV PATH="/opt/venv/bin:$PATH" - -RUN pip install --upgrade pip wheel twine - -# Preinstall dependencies for faster steps -RUN pip install --upgrade secp256k1 coincurve aiohttp eciespy python-magic typer -RUN pip install --upgrade 'aleph-message~=0.4.0' eth_account pynacl base58 -RUN pip install --upgrade pytest pytest-cov pytest-asyncio mypy types-setuptools pytest-asyncio fastapi httpx requests - -WORKDIR /opt/aleph-sdk-python/ -COPY . . -USER root -RUN chown -R user:user /opt/aleph-sdk-python - -RUN git config --global --add safe.directory /opt/aleph-sdk-python -RUN pip install -e .[testing] - -RUN mkdir /data -RUN chown user:user /data -ENV ALEPH_PRIVATE_KEY_FILE=/data/secret.key - -WORKDIR /home/user -USER user diff --git a/docker/ubuntu-22.04.dockerfile b/docker/ubuntu-22.04.dockerfile deleted file mode 100644 index 8ebfb4c3..00000000 --- a/docker/ubuntu-22.04.dockerfile +++ /dev/null @@ -1,44 +0,0 @@ -FROM ubuntu:22.04 -MAINTAINER The aleph.im project - -RUN apt-get update && apt-get -y upgrade && apt-get install -y \ - libsecp256k1-dev \ - python3-dev \ - python3-venv \ - git \ - build-essential \ - libgmp3-dev \ - && rm -rf /var/lib/apt/lists/* - -RUN useradd -s /bin/bash --create-home user -RUN mkdir /opt/venv -RUN mkdir /opt/aleph-sdk-python/ -RUN chown user:user /opt/venv -RUN chown user:user /opt/aleph-sdk-python - -USER user -RUN python3 -m venv /opt/venv -ENV PATH="/opt/venv/bin:$PATH" -ENV PATH="/opt/venv/bin:$PATH" - -RUN pip install --upgrade pip wheel twine - -# Preinstall dependencies for faster steps -RUN pip install --upgrade secp256k1 coincurve aiohttp eciespy python-magic typer -RUN pip install --upgrade 'aleph-message~=0.4.0' eth_account pynacl base58 -RUN pip install --upgrade pytest pytest-cov pytest-asyncio mypy types-setuptools pytest-asyncio fastapi httpx requests - -WORKDIR /opt/aleph-sdk-python/ -COPY . . -USER root -RUN chown -R user:user /opt/aleph-sdk-python - -RUN git config --global --add safe.directory /opt/aleph-sdk-python -RUN pip install -e .[testing] - -RUN mkdir /data -RUN chown user:user /data -ENV ALEPH_PRIVATE_KEY_FILE=/data/secret.key - -WORKDIR /home/user -USER user diff --git a/pyproject.toml b/pyproject.toml index 6dd8528e..feb13eb8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -127,12 +127,6 @@ include = [ "LICENSE.txt", ] -[tool.pytest.ini_options] -addopts = "--cov=aleph.sdk --cov-report=term-missing --verbose -m \"not ledger_hardware\"" -norecursedirs = ["dist", "build", ".tox"] -testpaths = ["tests"] -markers = {ledger_hardware = "marks tests as requiring ledger hardware"} - [tool.flake8] exclude = [".tox", "build", "dist", ".eggs", "docs/conf.py"] ignore = ["E501", "W291", "W503", "E203", "E704"] @@ -141,6 +135,7 @@ ignore = ["E501", "W291", "W503", "E203", "E704"] profile = "black" [tool.hatch.envs.testing] +features = ["testing"] dependencies = [ "pytest==8.0.1", "pytest-cov==4.1.0", @@ -148,14 +143,14 @@ dependencies = [ "pytest-asyncio==0.23.5", ] [tool.hatch.envs.testing.scripts] -test = "pytest {args:tests}" -test-cov = "pytest --cov {args:tests}" +run-coverage = "pytest --cov-config=pyproject.toml --cov=pkg --cov=tests" +run = "run-coverage --no-cov" cov-report = [ "- coverage combine", "coverage report", ] -cov = [ - "test-cov", +run-coverage-report = [ + "run-coverage", "cov-report", ] @@ -210,3 +205,52 @@ follow_imports = "silent" # Miscellaneous strictness flags # Allows variables to be redefined with an arbitrary type, as long as the redefinition is in the same block and nesting level as the original definition. allow_redefinition = true + +[tool.pytest.ini_options] +minversion = "6.0" +pythonpath = ["src"] +addopts = "-vv -m \"not ledger_hardware\"" +norecursedirs = ["*.egg", "dist", "build", ".tox", ".venv", "*/site-packages/*"] +testpaths = ["tests/unit"] +markers = {ledger_hardware = "marks tests as requiring ledger hardware"} + +[tool.coverage.run] +branch = true +parallel = true +source = [ + "src/", +] +omit = [ + "*/site-packages/*", +] + +[tool.coverage.paths] +source = [ + "src/", +] +omit = [ + "*/site-packages/*", +] + +[tool.coverage.report] +show_missing = true +skip_empty = true +exclude_lines = [ + # Have to re-enable the standard pragma + "pragma: no cover", + + # Don't complain about missing debug-only code: + "def __repr__", + "if self\\.debug", + + # Don't complain if tests don't hit defensive assertion code: + "raise AssertionError", + "raise NotImplementedError", + + # Don't complain if non-runnable code isn't run: + "if 0:", + "if __name__ == .__main__.:", + + # Don't complain about ineffective code: + "pass", +] \ No newline at end of file From 51d82ded1b4f057c3aa57f87260adf03747b15e5 Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 14 Mar 2024 14:23:18 +0100 Subject: [PATCH 19/29] Fix workflows --- .github/workflows/build-wheels.yml | 4 ++-- .github/workflows/code-quality.yml | 4 ++-- .github/workflows/pytest.yml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-wheels.yml b/.github/workflows/build-wheels.yml index 241d738c..ced2a661 100644 --- a/.github/workflows/build-wheels.yml +++ b/.github/workflows/build-wheels.yml @@ -16,7 +16,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Workaround github issue https://github.com/actions/runner-images/issues/7192 if: startsWith(matrix.os, 'ubuntu-') @@ -29,7 +29,7 @@ jobs: python-version: 3.11 - name: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-build-wheels-${{ hashFiles('setup.cfg', 'setup.py') }} diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 2ae32791..0e3d92b3 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -11,13 +11,13 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - 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: Cache dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.cache/pip key: ${{ runner.os }}-code-quality-${{ hashFiles('setup.cfg', 'setup.py') }} diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 8328caae..fb84d80f 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -1,4 +1,4 @@ -name: Test with Python ${{ matrix.python-version }} +name: Test/Coverage with Python on: push: @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} From d44b5cbe64d0887f40b21a01f661c11538abd869 Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 14 Mar 2024 14:56:35 +0100 Subject: [PATCH 20/29] Further improve hatch scripts and workflows --- .github/workflows/code-quality.yml | 28 ++++------- .github/workflows/pytest.yml | 9 ++-- README.md | 13 ++++- pyproject.toml | 81 +++++++++++------------------- 4 files changed, 53 insertions(+), 78 deletions(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 0e3d92b3..2e0796fc 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -16,11 +16,17 @@ jobs: - 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 update + sudo apt-get install -y python3-pip + pip3 install hatch + - name: Cache dependencies uses: actions/cache@v4 with: path: ~/.cache/pip - key: ${{ runner.os }}-code-quality-${{ hashFiles('setup.cfg', 'setup.py') }} + key: ${{ runner.os }}-code-quality-${{ hashFiles('pyproject.toml') }} restore-keys: | ${{ runner.os }}-code-quality- @@ -30,22 +36,6 @@ jobs: sudo apt-get -y upgrade sudo apt-get install -y libsecp256k1-dev - - name: Install required Python packages - run: | - python3 -m pip install -e .[testing] - - - name: Test with Black - run: | - black --check ./src/ ./tests/ ./examples/ - - - name: Test with isort - run: | - isort --check-only ./src/ ./tests/ ./examples/ - - - name: Test with MyPy - run: | - mypy ./src/ ./tests/ ./examples/ - - - name: Test with flake8 + - name: Run Hatch lint run: | - flake8 ./src/ ./tests/ ./examples/ + hatch run lint:all diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index fb84d80f..6d51c2b4 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -12,7 +12,7 @@ jobs: build: strategy: matrix: - python-version: [ 3.8, 3.9, 3.10, 3.11 ] + python-version: [ 3.8, 3.9, 3.10, 3.11, 3.12 ] runs-on: ubuntu-latest steps: @@ -20,12 +20,11 @@ jobs: - uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - - run: apt-get install -y python3-pip libsecp256k1-dev + - run: sudo apt-get install -y python3-pip libsecp256k1-dev - run: python -m pip install --upgrade pip hatch - - run: hatch build - - run: hatch run testing:run + - run: hatch run test:run if: matrix.python-version != '3.11' - - run: hatch run testing:run-coverage-report + - run: hatch run test:run-coverage-report if: matrix.python-version == '3.11' - uses: codecov/codecov-action@v4.0.1 if: matrix.python-version == '3.11' diff --git a/README.md b/README.md index 12efc42e..88117865 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ The following extra dependencies are available: - `mqtt` for MQTT-related functionalities, see [examples/mqtt.py](examples/mqtt.py) - `docs` for building the documentation, see [Documentation](#documentation) - `dns` for DNS-related functionalities -- `testing` installs all dependencies required for running the tests +- `all` installs all extra dependencies ## Installation for development @@ -61,9 +61,18 @@ $ hatch shell Then install the SDK from source with all extra dependencies: ```shell -$ pip install -e .[testing] +$ pip install -e .[all] ``` +### Running tests & Hatch scripts +You can use the test env defined for hatch to run the tests: + +```shell +$ hatch run test:run +``` + +See `hatch env show` for more information about all the environments and their scripts. + ### Generating the documentation [DEPRECATED] The documentation is built using [Sphinx](https://www.sphinx-doc.org/). diff --git a/pyproject.toml b/pyproject.toml index feb13eb8..087f9d2a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,35 +66,6 @@ solana = [ "base58", "pynacl", ] -testing = [ - "aiodns", - "aiomqtt<=0.1.3", - "aleph-pytezos==0.1.1", - "base58", - "black", - "eth_abi>=4.0.0; python_version>=\"3.11\"", - "eth_account>=0.4.0", - "fastapi", - "flake8", - "Flake8-pyproject", - "httpx", - "isort", - "ledgereth==0.9.0", - "mypy", - "mypy-extensions", - "psutil", - "py-sr25519-bindings", - "pynacl", - "pytest", - "pytest-asyncio", - "pytest-cov", - "pytest-mock", - "requests", - "secp256k1", - "substrate-interface", - "eciespy; python_version<\"3.11\"", - "eciespy>=0.3.13; python_version>=\"3.11\"", -] tezos = [ "aleph-pytezos==0.1.1", "pynacl", @@ -103,6 +74,9 @@ encryption = [ "eciespy; python_version<\"3.11\"", "eciespy>=0.3.13; python_version>=\"3.11\"", ] +all = [ + "aleph-sdk-python[cosmos,dns,docs,ethereum,ledger,mqtt,nuls2,polkadot,solana,tezos,encryption]", +] [project.urls] Documentation = "https://aleph.im/" @@ -127,56 +101,59 @@ include = [ "LICENSE.txt", ] -[tool.flake8] -exclude = [".tox", "build", "dist", ".eggs", "docs/conf.py"] -ignore = ["E501", "W291", "W503", "E203", "E704"] - [tool.isort] profile = "black" -[tool.hatch.envs.testing] -features = ["testing"] +[tool.hatch.envs.test] +features = [ + "cosmos", + "dns", + "ethereum", + "ledger", + "nuls2", + "polkadot", + "solana", + "tezos", + "encryption", +] dependencies = [ "pytest==8.0.1", "pytest-cov==4.1.0", "pytest-mock==3.12.0", "pytest-asyncio==0.23.5", ] -[tool.hatch.envs.testing.scripts] +[tool.hatch.envs.test.scripts] run-coverage = "pytest --cov-config=pyproject.toml --cov=pkg --cov=tests" -run = "run-coverage --no-cov" -cov-report = [ - "- coverage combine", - "coverage report", -] +run = "run-coverage --no-cov {args:.}" run-coverage-report = [ "run-coverage", - "cov-report", + "- coverage combine", + "coverage report", ] [[tool.hatch.envs.all.matrix]] -python = ["3.9", "3.10", "3.11", "3.12"] +python = ["3.8", "3.9", "3.10", "3.11", "3.12"] [tool.hatch.envs.lint] detached = true dependencies = [ - "black==24.1.1", - "mypy==1.8.0", - "mypy-extensions==0.4.3", - "ruff==0.1.15", + "black==24.2.0", + "mypy==1.9.0", + "mypy-extensions==1.0.0", + # "ruff==0.1.15", "isort==5.13.2", ] [tool.hatch.envs.lint.scripts] -typing = "mypy {args:src/aleph/vm/ tests/ examples/example_fastapi runtimes/aleph-debian-12-python}" +typing = "mypy --config-file=pyproject.toml {args:} ./src/ ./tests/ ./examples/" style = [ # "ruff {args:.}", - "black --check --diff {args:.}", - "isort --check-only --profile black {args:.}", + "black --check --diff {args:} ./src/ ./tests/ ./examples/", + "isort --check-only --profile black {args:} ./src/ ./tests/ ./examples/", ] fmt = [ - "black {args:.}", + "black {args:} ./src/ ./tests/ ./examples/", # "ruff --fix {args:.}", - "isort --profile black {args:.}", + "isort --profile black {args:} ./src/ ./tests/ ./examples/", "style", ] all = [ From 3ff50b10bc526bc3d96457f6c29029fdf4c921b6 Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 14 Mar 2024 14:59:05 +0100 Subject: [PATCH 21/29] Fix python-version matrix --- .github/workflows/pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 6d51c2b4..4e82e8a1 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -12,7 +12,7 @@ jobs: build: strategy: matrix: - python-version: [ 3.8, 3.9, 3.10, 3.11, 3.12 ] + python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ] runs-on: ubuntu-latest steps: From e18c6b790c629ca51581ddd0f70928a51a62793a Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 14 Mar 2024 15:06:34 +0100 Subject: [PATCH 22/29] Fix missing test dependencies --- pyproject.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 087f9d2a..7b0a3dcc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -121,6 +121,8 @@ dependencies = [ "pytest-cov==4.1.0", "pytest-mock==3.12.0", "pytest-asyncio==0.23.5", + "fastapi", + "httpx", ] [tool.hatch.envs.test.scripts] run-coverage = "pytest --cov-config=pyproject.toml --cov=pkg --cov=tests" From fc77e27cedbeb67cd9c46453a087508bdd8ca349 Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 14 Mar 2024 15:12:06 +0100 Subject: [PATCH 23/29] Fix missing test dependencies for Python 3.12 and further improve workflow --- .github/workflows/code-quality.yml | 9 ++------- pyproject.toml | 1 + 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 2e0796fc..2f63a626 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -18,7 +18,6 @@ jobs: - name: Install pip and hatch run: | - sudo apt-get update sudo apt-get install -y python3-pip pip3 install hatch @@ -31,11 +30,7 @@ jobs: ${{ runner.os }}-code-quality- - name: Install required system packages only for Ubuntu Linux - run: | - sudo apt-get update - sudo apt-get -y upgrade - sudo apt-get install -y libsecp256k1-dev + run: sudo apt-get install -y libsecp256k1-dev - name: Run Hatch lint - run: | - hatch run lint:all + run: hatch run lint:all diff --git a/pyproject.toml b/pyproject.toml index 7b0a3dcc..fb5179f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -123,6 +123,7 @@ dependencies = [ "pytest-asyncio==0.23.5", "fastapi", "httpx", + "secp256k1", ] [tool.hatch.envs.test.scripts] run-coverage = "pytest --cov-config=pyproject.toml --cov=pkg --cov=tests" From a90fd8664bb96ffabebe2e93cd6edf10de29ac39 Mon Sep 17 00:00:00 2001 From: mhh Date: Thu, 14 Mar 2024 15:16:04 +0100 Subject: [PATCH 24/29] Remove Python 3.12 from supported versions --- .github/workflows/pytest.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 4e82e8a1..836a5175 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -12,7 +12,7 @@ jobs: build: strategy: matrix: - python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ] + python-version: [ "3.8", "3.9", "3.10", "3.11" ] runs-on: ubuntu-latest steps: diff --git a/pyproject.toml b/pyproject.toml index fb5179f0..5afb6d94 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -135,7 +135,7 @@ run-coverage-report = [ ] [[tool.hatch.envs.all.matrix]] -python = ["3.8", "3.9", "3.10", "3.11", "3.12"] +python = ["3.8", "3.9", "3.10", "3.11"] [tool.hatch.envs.lint] detached = true From 1ff3155f5f4557208ae3abe06f2e206ecd88bc1f Mon Sep 17 00:00:00 2001 From: Mike Hukiewitz <70762838+MHHukiewitz@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:41:15 +0100 Subject: [PATCH 25/29] Update pyproject.toml Co-authored-by: Hugo Herter --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5afb6d94..e5cbdf7c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ classifiers = [ ] dependencies = [ "aiohttp>=3.8.3", - "aleph-message~=0.4.3", + "aleph-message~=0.4.4", "coincurve; python_version<\"3.11\"", "coincurve>=17.0.0; python_version>=\"3.11\"", "eth_abi>=4.0.0; python_version>=\"3.11\"", From ec194dc1cbaee57495da335d775d14958c5fdb99 Mon Sep 17 00:00:00 2001 From: Mike Hukiewitz <70762838+MHHukiewitz@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:42:04 +0100 Subject: [PATCH 26/29] Update pyproject.toml Co-authored-by: Hugo Herter --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index e5cbdf7c..e5b1666e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -127,7 +127,7 @@ dependencies = [ ] [tool.hatch.envs.test.scripts] run-coverage = "pytest --cov-config=pyproject.toml --cov=pkg --cov=tests" -run = "run-coverage --no-cov {args:.}" +run = "pytest {args:.}" run-coverage-report = [ "run-coverage", "- coverage combine", From a803ba2f7d49f764d141263c0f26ab9638d57254 Mon Sep 17 00:00:00 2001 From: mhh Date: Fri, 15 Mar 2024 17:37:41 +0100 Subject: [PATCH 27/29] Unify script/env names to equal aleph-vm conventions --- .github/workflows/code-quality.yml | 2 +- .github/workflows/pytest.yml | 4 ++-- pyproject.toml | 29 ++++++++++++++++------------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 2f63a626..79a3ac5b 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -33,4 +33,4 @@ jobs: run: sudo apt-get install -y libsecp256k1-dev - name: Run Hatch lint - run: hatch run lint:all + run: hatch run linting:all diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 836a5175..1c42ce1c 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -22,9 +22,9 @@ jobs: python-version: ${{ matrix.python-version }} - run: sudo apt-get install -y python3-pip libsecp256k1-dev - run: python -m pip install --upgrade pip hatch - - run: hatch run test:run + - run: hatch run testing:test if: matrix.python-version != '3.11' - - run: hatch run test:run-coverage-report + - run: hatch run testing:cov if: matrix.python-version == '3.11' - uses: codecov/codecov-action@v4.0.1 if: matrix.python-version == '3.11' diff --git a/pyproject.toml b/pyproject.toml index e5b1666e..832084d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -104,7 +104,10 @@ include = [ [tool.isort] profile = "black" -[tool.hatch.envs.test] +[[tool.hatch.envs.all.matrix]] +python = ["3.8", "3.9", "3.10", "3.11"] + +[tool.hatch.envs.testing] features = [ "cosmos", "dns", @@ -125,19 +128,19 @@ dependencies = [ "httpx", "secp256k1", ] -[tool.hatch.envs.test.scripts] -run-coverage = "pytest --cov-config=pyproject.toml --cov=pkg --cov=tests" -run = "pytest {args:.}" -run-coverage-report = [ - "run-coverage", - "- coverage combine", - "coverage report", +[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.8", "3.9", "3.10", "3.11"] - -[tool.hatch.envs.lint] +[tool.hatch.envs.linting] detached = true dependencies = [ "black==24.2.0", @@ -146,7 +149,7 @@ dependencies = [ # "ruff==0.1.15", "isort==5.13.2", ] -[tool.hatch.envs.lint.scripts] +[tool.hatch.envs.linting.scripts] typing = "mypy --config-file=pyproject.toml {args:} ./src/ ./tests/ ./examples/" style = [ # "ruff {args:.}", From ada98af7b0ea1d9f9b2e217dfd8b3801adf4611c Mon Sep 17 00:00:00 2001 From: mhh Date: Fri, 15 Mar 2024 17:51:11 +0100 Subject: [PATCH 28/29] Fix codecov action param --- .github/workflows/pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 1c42ce1c..e92ab40e 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -30,4 +30,4 @@ jobs: if: matrix.python-version == '3.11' with: token: ${{ secrets.CODECOV_TOKEN }} - slug: aleph-im/aleph-vm + slug: aleph-im/aleph-sdk-python From 965de9ffc6e29c1ad6e453461be74d2c5d75cb8e Mon Sep 17 00:00:00 2001 From: mhh Date: Fri, 15 Mar 2024 18:09:32 +0100 Subject: [PATCH 29/29] Add coverage.py for the codecov action --- .github/workflows/pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index e92ab40e..69382ccd 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -21,7 +21,7 @@ jobs: with: python-version: ${{ matrix.python-version }} - run: sudo apt-get install -y python3-pip libsecp256k1-dev - - run: python -m pip install --upgrade pip hatch + - run: python -m pip install --upgrade pip hatch coverage - run: hatch run testing:test if: matrix.python-version != '3.11' - run: hatch run testing:cov