diff --git a/.github/workflows/darglint.yml b/.github/workflows/darglint.yml index 7aa8947..d0360f0 100644 --- a/.github/workflows/darglint.yml +++ b/.github/workflows/darglint.yml @@ -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 diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 16cdb0c..cfa4252 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -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: | diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 430c6f0..73abded 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -1,4 +1,4 @@ -name: CI +name: Pytest defaults: run: @@ -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 diff --git a/.github/workflows/pytest310.yml b/.github/workflows/pytest310.yml index a632eb6..b19f477 100644 --- a/.github/workflows/pytest310.yml +++ b/.github/workflows/pytest310.yml @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fe4c0ea..14b3113 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 707f9b3..fbf2d11 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 = """ diff --git a/setup.py b/setup.py index 4cc5083..b908cbe 100644 --- a/setup.py +++ b/setup.py @@ -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() diff --git a/tealer/__main__.py b/tealer/__main__.py index 3381344..79dfb80 100644 --- a/tealer/__main__.py +++ b/tealer/__main__.py @@ -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 @@ -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", ) diff --git a/tealer/utils/command_line/common.py b/tealer/utils/command_line/common.py index 73832e2..74d4db2 100644 --- a/tealer/utils/command_line/common.py +++ b/tealer/utils/command_line/common.py @@ -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, @@ -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 @@ -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. @@ -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()