diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 20fa16a7..6fd178d5 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -43,4 +43,4 @@ jobs: path: './html/' - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v1 \ No newline at end of file + uses: actions/deploy-pages@v2 \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4faba206..ae3164d6 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -45,7 +45,7 @@ jobs: path: dist/ - name: publish - uses: pypa/gh-action-pypi-publish@v1.8.6 + uses: pypa/gh-action-pypi-publish@v1.8.7 - name: sign uses: sigstore/gh-action-sigstore-python@v1.2.3 diff --git a/README.md b/README.md index 62b7c43f..d06404a9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Crytic-compile -[![Build Status](https://img.shields.io/github/workflow/status/crytic/crytic-compile/CI/master)](https://github.com/crytic/crytic-compile/actions?query=workflow%3ACI) +[![Build Status](https://img.shields.io/github/actions/workflow/status/crytic/crytic-compile/ci.yml?branch=master)](https://github.com/crytic/crytic-compile/actions?query=workflow%3ACI) [![Slack Status](https://slack.empirehacking.nyc/badge.svg)](https://slack.empirehacking.nyc) [![PyPI version](https://badge.fury.io/py/crytic-compile.svg)](https://badge.fury.io/py/crytic-compile) diff --git a/crytic_compile/crytic_compile.py b/crytic_compile/crytic_compile.py index b9ae62bb..7b81bbaa 100644 --- a/crytic_compile/crytic_compile.py +++ b/crytic_compile/crytic_compile.py @@ -36,14 +36,14 @@ def get_platforms() -> List[Type[AbstractPlatform]]: - """Return the available platforms classes + """Return the available platforms classes in order of preference Returns: List[Type[AbstractPlatform]]: Available platforms """ platforms = [getattr(all_platforms, name) for name in dir(all_platforms)] platforms = [d for d in platforms if inspect.isclass(d) and issubclass(d, AbstractPlatform)] - return sorted(platforms, key=lambda platform: platform.TYPE) + return sorted(platforms, key=lambda platform: (platform.TYPE.priority(), platform.TYPE)) def is_supported(target: str) -> bool: diff --git a/crytic_compile/platform/hardhat.py b/crytic_compile/platform/hardhat.py index b11bdbb6..ca3f5f84 100755 --- a/crytic_compile/platform/hardhat.py +++ b/crytic_compile/platform/hardhat.py @@ -212,12 +212,10 @@ def is_supported(target: str, **kwargs: str) -> bool: if hardhat_ignore: return False - # If there is both foundry and hardhat, foundry takes priority - if os.path.isfile(os.path.join(target, "foundry.toml")): - return False - - return os.path.isfile(os.path.join(target, "hardhat.config.js")) | os.path.isfile( - os.path.join(target, "hardhat.config.ts") + return ( + os.path.isfile(os.path.join(target, "hardhat.config.js")) + or os.path.isfile(os.path.join(target, "hardhat.config.ts")) + or os.path.isfile(os.path.join(target, "hardhat.config.cjs")) ) def is_dependency(self, path: str) -> bool: diff --git a/crytic_compile/platform/truffle.py b/crytic_compile/platform/truffle.py index e654c1be..67c3b74c 100755 --- a/crytic_compile/platform/truffle.py +++ b/crytic_compile/platform/truffle.py @@ -305,12 +305,6 @@ def is_supported(target: str, **kwargs: str) -> bool: if truffle_ignore: return False - # Avoid conflicts with hardhat - if os.path.isfile(os.path.join(target, "hardhat.config.js")) | os.path.isfile( - os.path.join(target, "hardhat.config.ts") - ): - return False - return os.path.isfile(os.path.join(target, "truffle.js")) or os.path.isfile( os.path.join(target, "truffle-config.js") ) diff --git a/crytic_compile/platform/types.py b/crytic_compile/platform/types.py index e662780e..e07eaeb1 100644 --- a/crytic_compile/platform/types.py +++ b/crytic_compile/platform/types.py @@ -66,3 +66,24 @@ def __str__(self) -> str: # pylint: disable=too-many-branches if self == Type.FOUNDRY: return "Foundry" raise ValueError + + def priority(self) -> int: + """Return the priority for a certain platform. + + A lower priority means the platform is more preferable. This is used to + consistently select a platform when two or more are available. + + Returns: + int: priority number + """ + + if self == Type.FOUNDRY: + return 100 + + if self == Type.HARDHAT: + return 200 + + if self in [Type.TRUFFLE, Type.WAFFLE]: + return 300 + + return 1000 diff --git a/crytic_compile/platform/waffle.py b/crytic_compile/platform/waffle.py index 302972e3..6735649a 100755 --- a/crytic_compile/platform/waffle.py +++ b/crytic_compile/platform/waffle.py @@ -245,12 +245,6 @@ def is_supported(target: str, **kwargs: str) -> bool: if waffle_ignore: return False - # Avoid conflicts with hardhat - if os.path.isfile(os.path.join(target, "hardhat.config.js")) | os.path.isfile( - os.path.join(target, "hardhat.config.ts") - ): - return False - if os.path.isfile(os.path.join(target, "waffle.json")) or os.path.isfile( os.path.join(target, ".waffle.json") ): diff --git a/setup.py b/setup.py index 7cf39c7b..b268b07b 100644 --- a/setup.py +++ b/setup.py @@ -35,6 +35,7 @@ }, license="AGPL-3.0", long_description=long_description, + long_description_content_type="text/markdown", package_data={"crytic_compile": ["py.typed"]}, entry_points={"console_scripts": ["crytic-compile = crytic_compile.__main__:main"]}, )