Skip to content

Commit

Permalink
feat: add support for Python 3.12 (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Apr 30, 2024
1 parent 339cfc6 commit ee523b8
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 22 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ jobs:

strategy:
matrix:
os: [ubuntu-latest, macos-latest] # eventually add `windows-latest`
python-version: [3.8, 3.9, '3.10', '3.11']
# TODO: Replace with macos-latest when works again.
# https://github.com/actions/setup-python/issues/808
os: [ubuntu-latest, macos-12] # eventually add `windows-latest`
python-version: [3.8, 3.9, '3.10', '3.11', '3.12']

env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ repos:
hooks:
- id: check-yaml

- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 24.3.0
rev: 24.4.2
hooks:
- id: black
name: black
Expand All @@ -21,7 +21,7 @@ repos:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.10.0
hooks:
- id: mypy
additional_dependencies: [types-requests, types-setuptools, pydantic, types-pkg-resources]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Compile Solidity contracts.

## Dependencies

- [python3](https://www.python.org/downloads) version 3.8 up to 3.11.
- [python3](https://www.python.org/downloads) version 3.8 up to 3.12.

## Installation

Expand Down
36 changes: 31 additions & 5 deletions ape_solidity/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
from ape.exceptions import CompilerError, ConfigError, ContractLogicError
from ape.logging import logger
from ape.types import AddressType, ContractType
from ape.utils import cached_property, get_relative_path
from ape.utils import cached_property, get_package_version, get_relative_path
from eth_pydantic_types import HexBytes
from eth_utils import add_0x_prefix, is_0x_prefixed
from ethpm_types import PackageManifest
from ethpm_types.source import Compiler, Content
from packaging.specifiers import SpecifierSet
from packaging.version import Version
from pkg_resources import get_distribution
from requests.exceptions import ConnectionError
from solcx import (
compile_source,
Expand Down Expand Up @@ -62,13 +61,39 @@


class SolidityConfig(PluginConfig):
# Configure re-mappings using a `=` separated-str,
# e.g. '@import_name=path/to/dependency'
"""
Configure the Solidity plugin.
"""

import_remapping: List[str] = []
"""
Configure re-mappings using a ``=`` separated-str,
e.g. ``"@import_name=path/to/dependency"``.
"""

optimize: bool = True
"""
Set to ``False`` to disable compiler-optimizations.
"""

version: Optional[str] = None
"""
The compiler version to use. Defaults to selecting
the best version(s) it can for each file-set.
"""

evm_version: Optional[str] = None
"""
The EVM version (fork) to use. Defaults to letting
the compiler decide.
"""

via_ir: Optional[bool] = None
"""
Set to ``True`` to turn on compilation mode via the IR.
Defaults to ``None`` which does not pass the flag to
the compiler (same as ``False``).
"""


class SolidityCompiler(CompilerAPI):
Expand Down Expand Up @@ -152,7 +177,8 @@ def _settings_version(self) -> Optional[Version]:

@cached_property
def _ape_version(self) -> Version:
return Version(get_distribution("eth-ape").version.split(".dev")[0].strip())
version_str = get_package_version("eth-ape").split(".dev")[0].strip()
return Version(version_str)

def add_library(self, *contracts: ContractInstance):
"""
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"pytest-benchmark", # For performance tests
],
"lint": [
"black>=24.3.0,<25", # Auto-formatter and linter
"mypy>=1.9.0,<2", # Static type analyzer
"black>=24.4.2,<25", # Auto-formatter and linter
"mypy>=1.10.0,<2", # Static type analyzer
"types-requests", # Needed for mypy type shed
"types-setuptools", # Needed for mypy type shed
"types-pkg-resources", # Needed for type checking tests
"flake8>=7.0.0,<8", # Style linter
"isort>=5.10.1,<6", # Import sorting linter
"isort>=5.13.2,<6", # Import sorting linter
"mdformat>=0.7.17", # Auto-formatter for markdown
"mdformat-gfm>=0.3.5", # Needed for formatting GitHub-flavored markdown
"mdformat-frontmatter>=0.4.1", # Needed for frontmatters-style headers in issue templates
Expand Down Expand Up @@ -95,5 +95,6 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
)
10 changes: 5 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import shutil
from contextlib import contextmanager
from distutils.dir_util import copy_tree
from pathlib import Path
from shutil import copytree
from tempfile import mkdtemp
from unittest import mock

Expand Down Expand Up @@ -57,7 +57,7 @@ def temp_solcx_path(monkeypatch):
@pytest.fixture(autouse=True)
def data_folder():
base_path = Path(__file__).parent / "data"
copy_tree(base_path.as_posix(), DATA_FOLDER.as_posix())
copytree(base_path, DATA_FOLDER, dirs_exist_ok=True)
return DATA_FOLDER


Expand Down Expand Up @@ -87,7 +87,7 @@ def project(data_folder, config):
if cache.is_dir():
shutil.rmtree(cache)

copy_tree(project_source_dir.as_posix(), project_dest_dir.as_posix())
copytree(project_source_dir, project_dest_dir, dirs_exist_ok=True)
with config.using_project(project_dest_dir) as project:
yield project
if project.local_project._cache_folder.is_dir():
Expand Down Expand Up @@ -147,5 +147,5 @@ def not_owner():

@pytest.fixture
def connection():
with ape.networks.ethereum.local.use_provider("test"):
yield
with ape.networks.ethereum.local.use_provider("test") as provider:
yield provider
2 changes: 0 additions & 2 deletions tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from ape.exceptions import CompilerError
from ape.logging import LogLevel
from packaging.version import Version
from pkg_resources import get_distribution
from requests.exceptions import ConnectionError

from ape_solidity import Extension
Expand All @@ -37,7 +36,6 @@
)
raises_because_not_sol = pytest.raises(CompilerError, match=EXPECTED_NON_SOLIDITY_ERR_MSG)
DEFAULT_OPTIMIZER = {"enabled": True, "runs": 200}
APE_VERSION = Version(get_distribution("eth-ape").version.split(".dev")[0].strip())


@pytest.mark.parametrize(
Expand Down

0 comments on commit ee523b8

Please sign in to comment.