Skip to content

Commit 5ac881e

Browse files
authored
Merge pull request #458 from crytic/dev
prepare for 0.3.2 release
2 parents fc58a91 + 5fa747c commit 5ac881e

30 files changed

+735
-269
lines changed

.github/dependabot.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ version: 2
33
updates:
44
- package-ecosystem: "github-actions"
55
directory: "/"
6+
target-branch: "dev"
67
schedule:
78
interval: "weekly"

.github/workflows/ci.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Set up Node
4343
uses: actions/setup-node@v3
4444
with:
45-
node-version: 'lts/*'
45+
node-version: 18.15
4646
- name: Set up Python 3.8
4747
uses: actions/setup-python@v4
4848
with:
@@ -60,6 +60,9 @@ jobs:
6060
uses: cachix/cachix-action@v12
6161
with:
6262
name: dapp
63+
- name: Install Foundry
64+
if: matrix.type == 'foundry'
65+
uses: foundry-rs/foundry-toolchain@v1
6366
- name: Run Tests
6467
env:
6568
TEST_TYPE: ${{ matrix.type }}

.github/workflows/doc.yml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: docs
2+
3+
on:
4+
# Runs on pushes targeting the default branch
5+
push:
6+
branches: ["master"]
7+
8+
# Allows you to run this workflow manually from the Actions tab
9+
workflow_dispatch:
10+
11+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
# Allow one concurrent deployment
18+
concurrency:
19+
group: "pages"
20+
cancel-in-progress: true
21+
22+
jobs:
23+
# Single deploy job since we're just deploying
24+
build:
25+
environment:
26+
name: Crytic-Compile Documentation
27+
url: ${{ steps.deployment.outputs.page_url }}
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v3
32+
- name: Setup Pages
33+
uses: actions/configure-pages@v3
34+
- uses: actions/setup-python@v4
35+
with:
36+
python-version: '3.8'
37+
- run: pip install -e ".[doc]"
38+
- run: pdoc -o html/ crytic_compile
39+
- name: Upload artifact
40+
uses: actions/upload-pages-artifact@v1
41+
with:
42+
# Upload the doc
43+
path: './html/'
44+
- name: Deploy to GitHub Pages
45+
id: deployment
46+
uses: actions/deploy-pages@v1

.github/workflows/linter.yml

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ jobs:
4444
VALIDATE_ALL_CODEBASE: true
4545
DEFAULT_BRANCH: master
4646
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
# Until we upgrade the super linter for actionlintÒ
48+
VALIDATE_GITHUB_ACTIONS: false
4749
# Always false
4850
VALIDATE_PYTHON: false
4951
VALIDATE_PYTHON_PYLINT: false

.github/workflows/publish.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build-release:
9+
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.x'
19+
20+
- name: Build distributions
21+
run: |
22+
python -m pip install --upgrade pip
23+
python -m pip install build
24+
python -m build
25+
26+
- name: Upload distributions
27+
uses: actions/upload-artifact@v3
28+
with:
29+
name: crytic-compile-dists
30+
path: dist/
31+
32+
publish:
33+
runs-on: ubuntu-latest
34+
environment: release
35+
permissions:
36+
id-token: write # For trusted publishing + codesigning.
37+
contents: write # For attaching signing artifacts to the release.
38+
needs:
39+
- build-release
40+
steps:
41+
- name: fetch dists
42+
uses: actions/download-artifact@v3
43+
with:
44+
name: crytic-compile-dists
45+
path: dist/
46+
47+
- name: publish
48+
uses: pypa/[email protected]
49+
50+
- name: sign
51+
uses: sigstore/[email protected]
52+
with:
53+
inputs: ./dist/*.tar.gz ./dist/*.whl
54+
release-signing-artifacts: true
55+
bundle-only: true

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ dist/
1010
node_modules
1111
package-lock.json
1212
result
13+
env/
14+
.coverage*

Makefile

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
SHELL := /bin/bash
2+
3+
PY_MODULE := crytic_compile
4+
TEST_MODULE := tests
5+
6+
ALL_PY_SRCS := $(shell find $(PY_MODULE) -name '*.py') \
7+
$(shell find test -name '*.py')
8+
9+
# Optionally overriden by the user, if they're using a virtual environment manager.
10+
VENV ?= env
11+
12+
# On Windows, venv scripts/shims are under `Scripts` instead of `bin`.
13+
VENV_BIN := $(VENV)/bin
14+
ifeq ($(OS),Windows_NT)
15+
VENV_BIN := $(VENV)/Scripts
16+
endif
17+
18+
# Optionally overridden by the user in the `release` target.
19+
BUMP_ARGS :=
20+
21+
# Optionally overridden by the user in the `test` target.
22+
TESTS :=
23+
24+
# Optionally overridden by the user/CI, to limit the installation to a specific
25+
# subset of development dependencies.
26+
CRYTIC_COMPILE_EXTRA := dev
27+
28+
# If the user selects a specific test pattern to run, set `pytest` to fail fast
29+
# and only run tests that match the pattern.
30+
# Otherwise, run all tests and enable coverage assertions, since we expect
31+
# complete test coverage.
32+
ifneq ($(TESTS),)
33+
TEST_ARGS := -x -k $(TESTS)
34+
COV_ARGS :=
35+
else
36+
# TEST_ARGS := -n auto
37+
COV_ARGS := # --fail-under 100
38+
endif
39+
40+
.PHONY: all
41+
all:
42+
@echo "Run my targets individually!"
43+
44+
.PHONY: dev
45+
dev: $(VENV)/pyvenv.cfg
46+
47+
.PHONY: run
48+
run: $(VENV)/pyvenv.cfg
49+
@. $(VENV_BIN)/activate && crytic-compile $(ARGS)
50+
51+
$(VENV)/pyvenv.cfg: pyproject.toml
52+
# Create our Python 3 virtual environment
53+
python3 -m venv env
54+
$(VENV_BIN)/python -m pip install --upgrade pip
55+
$(VENV_BIN)/python -m pip install -e .[$(CRYTIC_COMPILE_EXTRA)]
56+
57+
.PHONY: lint
58+
lint: $(VENV)/pyvenv.cfg
59+
. $(VENV_BIN)/activate && \
60+
black --check . && \
61+
pylint $(PY_MODULE) $(TEST_MODULE) && \
62+
mypy $(PY_MODULE)
63+
# ruff $(ALL_PY_SRCS)
64+
65+
.PHONY: reformat
66+
reformat:
67+
. $(VENV_BIN)/activate && \
68+
black .
69+
70+
.PHONY: test tests
71+
test tests: $(VENV)/pyvenv.cfg
72+
. $(VENV_BIN)/activate && \
73+
pytest --cov=$(PY_MODULE) $(T) $(TEST_ARGS) && \
74+
python -m coverage report -m $(COV_ARGS)
75+
76+
.PHONY: doc
77+
doc: $(VENV)/pyvenv.cfg
78+
. $(VENV_BIN)/activate && \
79+
pdoc -o html crytic_compile
80+
81+
.PHONY: package
82+
package: $(VENV)/pyvenv.cfg
83+
. $(VENV_BIN)/activate && \
84+
python3 -m build
85+
86+
.PHONY: edit
87+
edit:
88+
$(EDITOR) $(ALL_PY_SRCS)

crytic_compile/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
2-
Init module
2+
.. include:: ../README.md
33
"""
4-
54
from .crytic_compile import CryticCompile, compile_all, is_supported
65
from .compilation_unit import CompilationUnit
76
from .cryticparser import cryticparser

crytic_compile/compilation_unit.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88
import uuid
99
from collections import defaultdict
10-
from typing import TYPE_CHECKING, Dict, Set, Optional
10+
from typing import TYPE_CHECKING, Dict, List, Set, Optional
1111

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

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

4141
# mapping from absolute/relative/used to filename
4242
self._filenames_lookup: Optional[Dict[str, Filename]] = None
@@ -114,6 +114,8 @@ def create_source_unit(self, filename: Filename) -> SourceUnit:
114114
Create the source unit associated with the filename
115115
Add the relevant info in the compilation unit/crytic compile
116116
If the source unit already exist, return it
117+
Also appends filename to the end of filenames, if not already present
118+
So this function should be called in the order you want filenames to have
117119
118120
Args:
119121
filename (Filename): filename of the source unit
@@ -123,8 +125,9 @@ def create_source_unit(self, filename: Filename) -> SourceUnit:
123125
"""
124126
if not filename in self._source_units:
125127
source_unit = SourceUnit(self, filename) # type: ignore
126-
self.filenames.add(filename)
127128
self._source_units[filename] = source_unit
129+
if filename not in self.filenames:
130+
self.filenames.append(filename)
128131
return self._source_units[filename]
129132

130133
# endregion
@@ -135,20 +138,20 @@ def create_source_unit(self, filename: Filename) -> SourceUnit:
135138
###################################################################################
136139

137140
@property
138-
def filenames(self) -> Set[Filename]:
141+
def filenames(self) -> List[Filename]:
139142
"""Return the filenames used by the compilation unit
140143
141144
Returns:
142-
Set[Filename]: Filenames used by the compilation units
145+
list[Filename]: Filenames used by the compilation units
143146
"""
144147
return self._filenames
145148

146149
@filenames.setter
147-
def filenames(self, all_filenames: Set[Filename]) -> None:
150+
def filenames(self, all_filenames: List[Filename]) -> None:
148151
"""Set the filenames
149152
150153
Args:
151-
all_filenames (Set[Filename]): new filenames
154+
all_filenames (List[Filename]): new filenames
152155
"""
153156
self._filenames = all_filenames
154157

crytic_compile/crytic_compile.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ def filenames(self) -> Set[Filename]:
175175
Return the set of all the filenames used
176176
177177
Returns:
178-
Set[Filename]: list of filenames
178+
Set[Filename]: set of filenames
179179
"""
180180
filenames: Set[Filename] = set()
181181
for compile_unit in self._compilation_units.values():
182-
filenames = filenames.union(compile_unit.filenames)
182+
filenames |= set(compile_unit.filenames)
183183
return filenames
184184

185185
def filename_lookup(self, filename: str) -> Filename:
@@ -566,7 +566,10 @@ def _run_custom_build(custom_build: str) -> None:
566566
custom_build (str): Command to run
567567
"""
568568
cmd = custom_build.split(" ")
569-
569+
LOGGER.info(
570+
"'%s' running",
571+
" ".join(cmd),
572+
)
570573
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as process:
571574
stdout_bytes, stderr_bytes = process.communicate()
572575
stdout, stderr = (
@@ -663,6 +666,6 @@ def compile_all(target: str, **kwargs: str) -> List[CryticCompile]:
663666
for filename in filenames:
664667
compilations.append(CryticCompile(filename, **kwargs))
665668
else:
666-
raise ValueError(f"Unresolved target: {str(target)}")
669+
raise ValueError(f"{str(target)} is not a file or directory.")
667670

668671
return compilations

crytic_compile/platform/brownie.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def compile(self, crytic_compile: "CryticCompile", **kwargs: str) -> None:
5555

5656
if not brownie_ignore_compile:
5757
cmd = base_cmd + ["compile"]
58+
LOGGER.info(
59+
"'%s' running",
60+
" ".join(cmd),
61+
)
5862
try:
5963
with subprocess.Popen(
6064
cmd,
@@ -181,7 +185,7 @@ def _iterate_over_files(
181185

182186
compilation_unit.filename_to_contracts[filename].add(contract_name)
183187

184-
source_unit.contracts_names.add(contract_name)
188+
source_unit.add_contract_name(contract_name)
185189
source_unit.abis[contract_name] = target_loaded["abi"]
186190
source_unit.bytecodes_init[contract_name] = target_loaded["bytecode"].replace("0x", "")
187191
source_unit.bytecodes_runtime[contract_name] = target_loaded[

0 commit comments

Comments
 (0)