Skip to content

Commit

Permalink
Merge pull request #458 from crytic/dev
Browse files Browse the repository at this point in the history
prepare for 0.3.2 release
  • Loading branch information
0xalpharush authored Jun 23, 2023
2 parents fc58a91 + 5fa747c commit 5ac881e
Show file tree
Hide file tree
Showing 30 changed files with 735 additions and 269 deletions.
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
target-branch: "dev"
schedule:
interval: "weekly"
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
node-version: 18.15
- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
Expand All @@ -60,6 +60,9 @@ jobs:
uses: cachix/cachix-action@v12
with:
name: dapp
- name: Install Foundry
if: matrix.type == 'foundry'
uses: foundry-rs/foundry-toolchain@v1
- name: Run Tests
env:
TEST_TYPE: ${{ matrix.type }}
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: docs

on:
# Runs on pushes targeting the default branch
push:
branches: ["master"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: "pages"
cancel-in-progress: true

jobs:
# Single deploy job since we're just deploying
build:
environment:
name: Crytic-Compile Documentation
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Pages
uses: actions/configure-pages@v3
- uses: actions/setup-python@v4
with:
python-version: '3.8'
- run: pip install -e ".[doc]"
- run: pdoc -o html/ crytic_compile
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
# Upload the doc
path: './html/'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
2 changes: 2 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jobs:
VALIDATE_ALL_CODEBASE: true
DEFAULT_BRANCH: master
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Until we upgrade the super linter for actionlintÒ
VALIDATE_GITHUB_ACTIONS: false
# Always false
VALIDATE_PYTHON: false
VALIDATE_PYTHON_PYLINT: false
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Publish to PyPI

on:
release:
types: [published]

jobs:
build-release:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Build distributions
run: |
python -m pip install --upgrade pip
python -m pip install build
python -m build
- name: Upload distributions
uses: actions/upload-artifact@v3
with:
name: crytic-compile-dists
path: dist/

publish:
runs-on: ubuntu-latest
environment: release
permissions:
id-token: write # For trusted publishing + codesigning.
contents: write # For attaching signing artifacts to the release.
needs:
- build-release
steps:
- name: fetch dists
uses: actions/download-artifact@v3
with:
name: crytic-compile-dists
path: dist/

- name: publish
uses: pypa/[email protected]

- name: sign
uses: sigstore/[email protected]
with:
inputs: ./dist/*.tar.gz ./dist/*.whl
release-signing-artifacts: true
bundle-only: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ dist/
node_modules
package-lock.json
result
env/
.coverage*
88 changes: 88 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
SHELL := /bin/bash

PY_MODULE := crytic_compile
TEST_MODULE := tests

ALL_PY_SRCS := $(shell find $(PY_MODULE) -name '*.py') \
$(shell find test -name '*.py')

# Optionally overriden by the user, if they're using a virtual environment manager.
VENV ?= env

# On Windows, venv scripts/shims are under `Scripts` instead of `bin`.
VENV_BIN := $(VENV)/bin
ifeq ($(OS),Windows_NT)
VENV_BIN := $(VENV)/Scripts
endif

# Optionally overridden by the user in the `release` target.
BUMP_ARGS :=

# Optionally overridden by the user in the `test` target.
TESTS :=

# Optionally overridden by the user/CI, to limit the installation to a specific
# subset of development dependencies.
CRYTIC_COMPILE_EXTRA := dev

# If the user selects a specific test pattern to run, set `pytest` to fail fast
# and only run tests that match the pattern.
# Otherwise, run all tests and enable coverage assertions, since we expect
# complete test coverage.
ifneq ($(TESTS),)
TEST_ARGS := -x -k $(TESTS)
COV_ARGS :=
else
# TEST_ARGS := -n auto
COV_ARGS := # --fail-under 100
endif

.PHONY: all
all:
@echo "Run my targets individually!"

.PHONY: dev
dev: $(VENV)/pyvenv.cfg

.PHONY: run
run: $(VENV)/pyvenv.cfg
@. $(VENV_BIN)/activate && crytic-compile $(ARGS)

$(VENV)/pyvenv.cfg: pyproject.toml
# Create our Python 3 virtual environment
python3 -m venv env
$(VENV_BIN)/python -m pip install --upgrade pip
$(VENV_BIN)/python -m pip install -e .[$(CRYTIC_COMPILE_EXTRA)]

.PHONY: lint
lint: $(VENV)/pyvenv.cfg
. $(VENV_BIN)/activate && \
black --check . && \
pylint $(PY_MODULE) $(TEST_MODULE) && \
mypy $(PY_MODULE)
# ruff $(ALL_PY_SRCS)

.PHONY: reformat
reformat:
. $(VENV_BIN)/activate && \
black .

.PHONY: test tests
test tests: $(VENV)/pyvenv.cfg
. $(VENV_BIN)/activate && \
pytest --cov=$(PY_MODULE) $(T) $(TEST_ARGS) && \
python -m coverage report -m $(COV_ARGS)

.PHONY: doc
doc: $(VENV)/pyvenv.cfg
. $(VENV_BIN)/activate && \
pdoc -o html crytic_compile

.PHONY: package
package: $(VENV)/pyvenv.cfg
. $(VENV_BIN)/activate && \
python3 -m build

.PHONY: edit
edit:
$(EDITOR) $(ALL_PY_SRCS)
3 changes: 1 addition & 2 deletions crytic_compile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Init module
.. include:: ../README.md
"""

from .crytic_compile import CryticCompile, compile_all, is_supported
from .compilation_unit import CompilationUnit
from .cryticparser import cryticparser
Expand Down
17 changes: 10 additions & 7 deletions crytic_compile/compilation_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
import uuid
from collections import defaultdict
from typing import TYPE_CHECKING, Dict, Set, Optional
from typing import TYPE_CHECKING, Dict, List, Set, Optional

from crytic_compile.compiler.compiler import CompilerVersion
from crytic_compile.source_unit import SourceUnit
Expand Down Expand Up @@ -36,7 +36,7 @@ def __init__(self, crytic_compile: "CryticCompile", unique_id: str):
self._source_units: Dict[Filename, SourceUnit] = {}

# set containing all the filenames of this compilation unit
self._filenames: Set[Filename] = set()
self._filenames: List[Filename] = []

# mapping from absolute/relative/used to filename
self._filenames_lookup: Optional[Dict[str, Filename]] = None
Expand Down Expand Up @@ -114,6 +114,8 @@ def create_source_unit(self, filename: Filename) -> SourceUnit:
Create the source unit associated with the filename
Add the relevant info in the compilation unit/crytic compile
If the source unit already exist, return it
Also appends filename to the end of filenames, if not already present
So this function should be called in the order you want filenames to have
Args:
filename (Filename): filename of the source unit
Expand All @@ -123,8 +125,9 @@ def create_source_unit(self, filename: Filename) -> SourceUnit:
"""
if not filename in self._source_units:
source_unit = SourceUnit(self, filename) # type: ignore
self.filenames.add(filename)
self._source_units[filename] = source_unit
if filename not in self.filenames:
self.filenames.append(filename)
return self._source_units[filename]

# endregion
Expand All @@ -135,20 +138,20 @@ def create_source_unit(self, filename: Filename) -> SourceUnit:
###################################################################################

@property
def filenames(self) -> Set[Filename]:
def filenames(self) -> List[Filename]:
"""Return the filenames used by the compilation unit
Returns:
Set[Filename]: Filenames used by the compilation units
list[Filename]: Filenames used by the compilation units
"""
return self._filenames

@filenames.setter
def filenames(self, all_filenames: Set[Filename]) -> None:
def filenames(self, all_filenames: List[Filename]) -> None:
"""Set the filenames
Args:
all_filenames (Set[Filename]): new filenames
all_filenames (List[Filename]): new filenames
"""
self._filenames = all_filenames

Expand Down
11 changes: 7 additions & 4 deletions crytic_compile/crytic_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ def filenames(self) -> Set[Filename]:
Return the set of all the filenames used
Returns:
Set[Filename]: list of filenames
Set[Filename]: set of filenames
"""
filenames: Set[Filename] = set()
for compile_unit in self._compilation_units.values():
filenames = filenames.union(compile_unit.filenames)
filenames |= set(compile_unit.filenames)
return filenames

def filename_lookup(self, filename: str) -> Filename:
Expand Down Expand Up @@ -566,7 +566,10 @@ def _run_custom_build(custom_build: str) -> None:
custom_build (str): Command to run
"""
cmd = custom_build.split(" ")

LOGGER.info(
"'%s' running",
" ".join(cmd),
)
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as process:
stdout_bytes, stderr_bytes = process.communicate()
stdout, stderr = (
Expand Down Expand Up @@ -663,6 +666,6 @@ def compile_all(target: str, **kwargs: str) -> List[CryticCompile]:
for filename in filenames:
compilations.append(CryticCompile(filename, **kwargs))
else:
raise ValueError(f"Unresolved target: {str(target)}")
raise ValueError(f"{str(target)} is not a file or directory.")

return compilations
6 changes: 5 additions & 1 deletion crytic_compile/platform/brownie.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:

if not brownie_ignore_compile:
cmd = base_cmd + ["compile"]
LOGGER.info(
"'%s' running",
" ".join(cmd),
)
try:
with subprocess.Popen(
cmd,
Expand Down Expand Up @@ -181,7 +185,7 @@ def _iterate_over_files(

compilation_unit.filename_to_contracts[filename].add(contract_name)

source_unit.contracts_names.add(contract_name)
source_unit.add_contract_name(contract_name)
source_unit.abis[contract_name] = target_loaded["abi"]
source_unit.bytecodes_init[contract_name] = target_loaded["bytecode"].replace("0x", "")
source_unit.bytecodes_runtime[contract_name] = target_loaded[
Expand Down
Loading

0 comments on commit 5ac881e

Please sign in to comment.