Skip to content

Commit

Permalink
Merge pull request #124 from life4/py311
Browse files Browse the repository at this point in the history
Python 3.11 compatibility
  • Loading branch information
orsinium committed Feb 20, 2023
2 parents 778519f + 4ef736c commit 26bb9f8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
Expand Down
2 changes: 0 additions & 2 deletions MANIFEST.in

This file was deleted.

74 changes: 53 additions & 21 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,76 @@ version: "3"

vars:
PYTHON: python3
VENVS: .venvs
FLITENV: "{{.VENVS}}/base/bin/flitenv --venvs={{.VENVS}}"
TEST_ENV: .venvs/test
LINT_ENV: .venvs/lint
DOCS_ENV: .venvs/docs
TEST_PYTHON: "{{.TEST_ENV}}/bin/python3"
LINT_PYTHON: "{{.LINT_ENV}}/bin/python3"
DOCS_PYTHON: "{{.DOCS_ENV}}/bin/python3"

env:
FLIT_ROOT_INSTALL: "1"

tasks:
install:base:
install:flit:
status:
- test -f {{.VENVS}}/base/bin/flitenv
- which flit
cmds:
- "{{.PYTHON}} -m venv {{.VENVS}}/base"
- >
{{.VENVS}}/base/bin/python3 -m pip install flitenv
- python3 -m pip install flit
venv:test:
status:
- test -d {{.TEST_ENV}}
cmds:
- "{{.PYTHON}} -m venv {{.TEST_ENV}}"
venv:lint:
status:
- test -d {{.LINT_ENV}}
cmds:
- "{{.PYTHON}} -m venv {{.LINT_ENV}}"
venv:docs:
status:
- test -d {{.DOCS_ENV}}
cmds:
- "{{.PYTHON}} -m venv {{.DOCS_ENV}}"
install:test:
sources:
- pyproject.toml
deps:
- install:base
- install:flit
- venv:test
cmds:
- >
{{.FLITENV}} test install
flit install
--python {{.TEST_PYTHON}}
--extras=test,integrations
--deps=production
--symlink
install:lint:
sources:
- pyproject.toml
deps:
- install:base
- install:flit
- venv:lint
cmds:
- >
{{.FLITENV}} lint install
flit install
--python {{.LINT_PYTHON}}
--extras=lint,integrations
--deps=production
--symlink
install:docs:
sources:
- pyproject.toml
deps:
- install:base
- install:flit
- venv:docs
cmds:
- >
{{.FLITENV}} docs install
flit install
--python {{.DOCS_PYTHON}}
--extras=docs
--deps=production
--symlink
release:
cmds:
Expand All @@ -60,51 +92,51 @@ tasks:
deps:
- install:test
cmds:
- "{{.FLITENV}} test run pytest {{.CLI_ARGS}}"
- "{{.TEST_PYTHON}} -m pytest {{.CLI_ARGS}}"
flake8:
desc: "lint Python code"
deps:
- install:lint
cmds:
- "{{.FLITENV}} lint run flake8 --ignore=DEL {{.CLI_ARGS}} ."
- "{{.LINT_PYTHON}} -m flake8 --ignore=DEL {{.CLI_ARGS}} ."
mypy:
desc: "check type annotations"
deps:
- install:lint
cmds:
- "{{.FLITENV}} lint run mypy {{.CLI_ARGS}}"
- "{{.LINT_PYTHON}} -m mypy {{.CLI_ARGS}}"
unify:
desc: "convert double quotes to single ones"
deps:
- install:lint
cmds:
- "{{.FLITENV}} lint run unify -r -i --quote=\\' {{.CLI_ARGS}} deal tests"
- "{{.LINT_PYTHON}} -m unify -r -i --quote=\\' {{.CLI_ARGS}} deal tests"
isort:
desc: "sort imports"
deps:
- install:lint
cmds:
- "{{.FLITENV}} lint run isort {{.CLI_ARGS}} ."
- "{{.LINT_PYTHON}} -m isort {{.CLI_ARGS}} ."
isort:check:
desc: "sort imports"
deps:
- install:lint
cmds:
- "{{.FLITENV}} lint run isort --check {{.CLI_ARGS}} ."
- "{{.LINT_PYTHON}} -m isort --check {{.CLI_ARGS}} ."
mypy_test:
desc: "validate type annotations"
deps:
- install:lint
cmds:
- "{{.FLITENV}} lint run mypy_test {{.CLI_ARGS}} ./types/"
- "{{.LINT_PYTHON}} -m mypy_test {{.CLI_ARGS}} ./types/"

sphinx:
desc: "generate documentation"
deps:
- install:docs
cmds:
- rm -rf docs/build
- "{{.FLITENV}} docs run sphinx-build -W docs docs/build {{.CLI_ARGS}}"
- "{{.DOCS_ENV}}/bin/sphinx-build -W docs docs/build {{.CLI_ARGS}}"

# groups
format:
Expand Down
26 changes: 7 additions & 19 deletions deal/linter/_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import enum
from copy import copy
from pathlib import Path
from types import CodeType
from typing import Iterable, Union

import astroid
Expand Down Expand Up @@ -47,8 +48,8 @@ class Contract:

def __init__(
self,
args: Iterable,
kwargs: Iterable,
args: Iterable[ast.expr | astroid.NodeNG],
kwargs: Iterable[ast.keyword | astroid.Keyword],
category: Category,
func_args: ast.arguments,
context: dict[str, ast.stmt] | None = None,
Expand Down Expand Up @@ -157,14 +158,7 @@ def module(self) -> ast.Module:
# inject function signature
func = ast.Lambda(
args=self.func_args,
body=ast.Set(
elts=[],
lineno=1,
col_offset=1,
ctx=ast.Load(),
),
lineno=1,
col_offset=1,
body=ast.Set(elts=[], ctx=ast.Load()),
ctx=ast.Load(),
)
module.body[FUNC_INDEX].value = func # type: ignore
Expand All @@ -184,10 +178,8 @@ def module(self) -> ast.Module:
# if contract is function, add it's definition and assign it's name
# to `contract` variable.
module.body = [contract] + module.body
module.body[FUNC_INDEX].value = ast.Name( # type: ignore
module.body[FUNC_INDEX].value = ast.Name( # type: ignore[attr-defined]
id=contract.name,
lineno=1,
col_offset=1,
ctx=ast.Load(),
)
return module
Expand All @@ -202,8 +194,6 @@ def module(self) -> ast.Module:
body = list(deps)
return_node = ast.Return(
value=contract.body,
lineno=1,
col_offset=1,
ctx=ast.Load(),
)
body.append(return_node)
Expand All @@ -212,18 +202,16 @@ def module(self) -> ast.Module:
args=contract.args,
body=body,
decorator_list=[],
lineno=1,
col_offset=1,
ctx=ast.Load(),
)
return module

# inject contract if contract is an unknown expression
module.body[CONTRACT_INDEX].value = contract # type: ignore
module.body[CONTRACT_INDEX].value = contract # type: ignore[attr-defined]
return module

@cached_property
def bytecode(self):
def bytecode(self) -> CodeType:
module = ast.fix_missing_locations(self.module)
return compile(module, filename='<ast>', mode='exec')

Expand Down

0 comments on commit 26bb9f8

Please sign in to comment.