Skip to content

Commit

Permalink
feat: add Python 3.12 support (#1994)
Browse files Browse the repository at this point in the history
Co-authored-by: NotPeopling2day <[email protected]>
  • Loading branch information
antazoey and NotPeopling2day committed Apr 24, 2024
1 parent f0d6c05 commit 6e3b584
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
# 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"]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]

env:
GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Read our [academic platform](https://academy.apeworx.io/) will help you master A
In the latest release, Ape requires:

- Linux or macOS
- Python 3.8 up to 3.11
- Python 3.8 up to 3.12
- **Windows**: Install Windows Subsystem Linux [(WSL)](https://docs.microsoft.com/en-us/windows/wsl/install)

Check your python version in a terminal with `python3 --version`.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ write_to = "src/ape/version.py"
# character.
[tool.black]
line-length = 100
target-version = ['py38', 'py39', 'py310']
target-version = ['py38', 'py39', 'py310', 'py311', 'py312']
include = '\.pyi?$'

[tool.pytest.ini_options]
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,6 @@
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
)
9 changes: 8 additions & 1 deletion src/ape/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ def commands(self) -> Dict:
if self._commands:
return self._commands

eps: Iterable = entry_points().get(self._CLI_GROUP_NAME, [])
# Update when dropping Python 3.9 support.
_entry_points = entry_points()
eps: Iterable = (
_entry_points.get(self._CLI_GROUP_NAME, [])
if isinstance(_entry_points, dict)
else entry_points(group=self._CLI_GROUP_NAME)
)

self._commands = {clean_plugin_name(cmd.name): cmd.load for cmd in eps}
return self._commands

Expand Down
4 changes: 2 additions & 2 deletions src/ape/api/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ def cached_manifest(self) -> Optional[PackageManifest]:

@property
def contracts(self) -> Dict[str, ContractType]:
if self._contracts is not None:
return self._contracts
if contracts := self._contracts:
return contracts

contracts = {}
for p in self._cache_folder.glob("*.json"):
Expand Down
6 changes: 3 additions & 3 deletions src/ape/managers/project/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,10 @@ def contracts(self) -> Dict[str, ContractType]:
Returns:
Dict[str, ``ContractType``]
"""
if self.local_project.cached_manifest is None:
return self.load_contracts()
if self.local_project.cached_manifest and (contracts := self.local_project.contracts):
return contracts

return self.local_project.contracts
return self.load_contracts()

def __getattr__(self, attr_name: str) -> Any:
"""
Expand Down
8 changes: 4 additions & 4 deletions tests/functional/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import threading
import time
from contextlib import contextmanager
from distutils.dir_util import copy_tree
from pathlib import Path
from shutil import copytree
from typing import Optional, cast

import pytest
Expand Down Expand Up @@ -307,7 +307,7 @@ def ds_note_test_contract(eth_tester_provider, vyper_contract_type, owner, get_c
@pytest.fixture
def project_with_contract(temp_config):
with temp_config() as project:
copy_tree(str(APE_PROJECT_FOLDER), str(project.path))
copytree(str(APE_PROJECT_FOLDER), str(project.path), dirs_exist_ok=True)
project.local_project._cached_manifest = None # Clean manifest
yield project

Expand All @@ -318,8 +318,8 @@ def project_with_source_files_contract(temp_config):
project_source_dir = APE_PROJECT_FOLDER

with temp_config() as project:
copy_tree(str(project_source_dir), str(project.path))
copy_tree(str(bases_source_dir), f"{project.path}/contracts/")
copytree(str(project_source_dir), str(project.path), dirs_exist_ok=True)
copytree(str(bases_source_dir), f"{project.path}/contracts/", dirs_exist_ok=True)
yield project


Expand Down

0 comments on commit 6e3b584

Please sign in to comment.