Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tealer compatible with python 3.12 #209

Merged
merged 13 commits into from
Feb 8, 2024
4 changes: 2 additions & 2 deletions .github/workflows/darglint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.9
- name: Run Tests
run: |
bash scripts/ci_darglint.sh
4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v2

- name: Set up Python 3.8
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9

- name: Install dependencies
run: |
Expand Down
24 changes: 14 additions & 10 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Pytest

defaults:
run:
Expand All @@ -18,39 +18,43 @@ on:
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python: ${{fromJSON('["3.9", "3.10", "3.11", "3.12"]') }}


steps:
- uses: actions/checkout@v1
- name: Set up Python 3.8
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: ${{ matrix.python }}

# Used by ci_test.sh
- name: Install dependencies
- name: Install dependencies in ${{ matrix.python }}
run: |
python setup.py install
pip install .
pip install pytest
pip install pytest-cov

- name: Run Parsing tests
- name: Run Parsing tests in ${{ matrix.python }}
run: |
pytest tests/test_parsing.py tests/test_versions.py --cov=tealer/teal/instructions --cov-branch --cov-fail-under=96

- name: Run string tests
- name: Run string tests in ${{ matrix.python }}
run: |
pytest tests/test_string_representation.py

- name: Run version tests
- name: Run version tests in ${{ matrix.python }}
run: |
pytest tests/test_versions.py
pytest tests/test_mode_detector.py

- name: Run cfg recovery tests
- name: Run cfg recovery tests in ${{ matrix.python }}
run: |
pytest tests/test_cfg.py

- name: Run detectors tests
- name: Run detectors tests in ${{ matrix.python }}
run: |
pytest tests/test_detectors.py

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest310.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
# Used by ci_test.sh
- name: Install dependencies
run: |
python setup.py install
pip install .
pip install pytest
pip install pytest-cov
pip install pyteal==0.22.0
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@ on:
jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python: ${{fromJSON('["3.9", "3.10", "3.11", "3.12"]') }}

steps:
- uses: actions/checkout@v1
- name: Set up Python 3.8
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: ${{ matrix.python }}

# Used by ci_test.sh
- name: Install dependencies
- name: Install dependencies in ${{ matrix.python }}
run: |
python setup.py install
- name: Run Tests
pip install .
- name: Run Tests in ${{ matrix.python }}
run: |
bash scripts/test_algorand_contracts.sh
37 changes: 36 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "tealer"
version = "0.1.1"
authors = [{ name = "Trail of Bits" }]
description = "Teal analyzer."
readme = "README.md"
license = { "text" = "AGPL-3.0" }
urls = { "Homepage" = "https://github.com/crytic/tealer" }
requires-python = ">=3.9"
dependencies = [
"prettytable>=0.7.2",
"py-algorand-sdk",
"pycryptodomex",
"requests",
"pyyaml",
]

[project.optional-dependencies]
dev = [
"pylint==2.13.4",
"black==22.3.0",
"mypy==0.942",
"pytest-cov",
]

[project.scripts]
tealer = "tealer.__main__:main"

[tool.setuptools.packages.find]
where = ["."]

[tool.black]
target-version = ["py36"]
target-version = ["py39"]
line-length = 100
[tool.pylint.messages_control]
disable = """
Expand Down
28 changes: 2 additions & 26 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
from setuptools import setup, find_packages
import setuptools

with open("README.md", encoding="utf-8") as f:
long_description = f.read()

setup(
name="tealer",
description="Teal analyzer.",
url="https://github.com/crytic/tealer",
author="Trail of Bits",
version="0.1.1",
packages=find_packages(),
python_requires=">=3.8",
install_requires=[
"prettytable>=0.7.2",
"py-algorand-sdk",
"pycryptodomex",
"requests",
"pyyaml",
"setuptools",
],
extras_require={"dev": ["pylint==2.13.4", "black==22.3.0", "mypy==0.942", "pytest-cov"]},
license="AGPL-3.0",
long_description=long_description,
long_description_content_type="text/markdown",
entry_points={"console_scripts": ["tealer = tealer.__main__:main"]},
)
setuptools.setup()
4 changes: 2 additions & 2 deletions tealer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
from pathlib import Path
from typing import List, Any, Type, Tuple, TYPE_CHECKING, Optional, Union, Sequence

from pkg_resources import require # type: ignore
from importlib.metadata import version

from tealer.detectors.abstract_detector import AbstractDetector, DetectorType
from tealer.exceptions import TealerException
Expand Down Expand Up @@ -280,7 +280,7 @@ def parse_args(
parser.add_argument(
"--version",
help="displays the current version",
version=require("tealer")[0].version,
version=version("tealer"),
action="version",
)

Expand Down
25 changes: 22 additions & 3 deletions tealer/utils/command_line/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import argparse

from typing import List, Type, Tuple, TYPE_CHECKING, Dict
from pkg_resources import iter_entry_points # type: ignore
from importlib.metadata import entry_points, version, PackageNotFoundError

from tealer.detectors.abstract_detector import (
AbstractDetector,
Expand All @@ -81,7 +81,6 @@
)
from tealer.utils.command_line.group_config import USER_CONFIG_TRANSACTION_TYPES


if TYPE_CHECKING:
from tealer.teal.functions import Function
from tealer.teal.teal import Teal
Expand All @@ -91,6 +90,26 @@
)


def _get_entry_points(group: str): # type: ignore

try:
import_lib_version = version("importlib_metadata").split(".")
importlib_major = import_lib_version[0]
importlib_minor = import_lib_version[1]
except (IndexError, PackageNotFoundError):
importlib_major = "0"
importlib_minor = "0"

# For Python 3.10 and later, or import lib >= 3.6
# See https://pypi.org/project/backports.entry-points-selectable/
if sys.version_info >= (3, 10) or (importlib_major >= "3" and importlib_minor >= "6"):
return entry_points(group=group) # type: ignore

# For Python 3.9 (and 3.8)
all_entry_points = entry_points() # type: ignore
return all_entry_points.get(group, [])


def collect_plugins() -> Tuple[List[Type[AbstractDetector]], List[Type[AbstractPrinter]]]:
"""collect detectors and printers installed in form of plugins.

Expand All @@ -108,7 +127,7 @@ def collect_plugins() -> Tuple[List[Type[AbstractDetector]], List[Type[AbstractP
"""
detector_classes: List[Type[AbstractDetector]] = []
printer_classes: List[Type[AbstractPrinter]] = []
for entry_point in iter_entry_points(group="teal_analyzer.plugin", name=None):
for entry_point in _get_entry_points("teal_analyzer.plugin"):
make_plugin = entry_point.load()

plugin_detectors, plugin_printers = make_plugin()
Expand Down