Skip to content

Commit ec87455

Browse files
authored
Merge pull request #2849 from crytic/build-system-hatchling
Build: Migrate from setuptools to hatchling with uv
2 parents 1e51e37 + 6c6593f commit ec87455

36 files changed

+5732
-183
lines changed

.github/workflows/black_auto.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ jobs:
3131
python-version: 3.8
3232

3333
- name: Run black
34-
uses: psf/black@stable
34+
uses: psf/black@24.8.0
3535
with:
3636
options: ""
3737
summary: false
38-
version: "~= 22.3.0"
38+
version: "<24.10.0"
3939

4040
- name: Annotate diff changes using reviewdog
4141
uses: reviewdog/action-suggester@v1

.github/workflows/ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,19 @@ jobs:
3535
# Requires nvm
3636
- os: windows-2022
3737
type: truffle
38+
# fasttext fails to install on Windows
39+
- os: windows-2022
40+
type: simil
3841
steps:
3942
- uses: actions/checkout@v6
40-
- name: Set up Python ${{ matrix.python }}
41-
uses: actions/setup-python@v6
43+
- name: Install uv and Python ${{ matrix.python }}
44+
uses: astral-sh/setup-uv@v7
4245
with:
4346
python-version: ${{ matrix.python }}
47+
activate-environment: true
4448
- name: Install dependencies
4549
run: |
46-
pip install ".[test]"
50+
uv sync --group test
4751
solc-select use 0.8.0 --always-install
4852
solc-select use 0.7.0 --always-install
4953
solc-select use 0.5.1 --always-install

.github/workflows/docs.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ jobs:
3131
uses: actions/checkout@v6
3232
- name: Setup Pages
3333
uses: actions/configure-pages@v5
34-
- uses: actions/setup-python@v6
34+
- name: Install uv and Python
35+
uses: astral-sh/setup-uv@v7
3536
with:
36-
python-version: '3.8'
37-
- run: pip install -e ".[doc]"
37+
python-version: "3.8"
38+
activate-environment: true
39+
- run: uv sync --group doc
3840
- run: pdoc -o html/ slither '!slither.tools' #TODO fix import errors on pdoc run
3941
- name: Upload artifact
4042
uses: actions/upload-pages-artifact@v4

.github/workflows/doctor.yml

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,13 @@ jobs:
3636
with:
3737
python-version: ${{ matrix.python }}
3838

39-
- name: Try system-wide Slither
40-
run: |
41-
echo "::group::Install slither"
42-
pip3 install .
43-
echo "::endgroup::"
44-
45-
# escape cwd so python doesn't pick up local module
46-
cd /
47-
48-
echo "::group::Via module"
49-
python3 -m slither.tools.doctor .
50-
echo "::endgroup::"
51-
52-
echo "::group::Via binary"
53-
slither-doctor .
54-
echo "::endgroup::"
39+
- name: Install uv
40+
uses: astral-sh/setup-uv@v7
5541

56-
- name: Try user Slither
42+
- name: Try system-wide Slither
5743
run: |
5844
echo "::group::Install slither"
59-
pip3 install --user .
45+
uv pip install --system .
6046
echo "::endgroup::"
6147
6248
# escape cwd so python doesn't pick up local module
@@ -73,10 +59,10 @@ jobs:
7359
- name: Try venv Slither
7460
run: |
7561
echo "::group::Install slither"
76-
python3 -m venv venv
77-
source venv/bin/activate || source venv/Scripts/activate
62+
uv venv
63+
uv pip install .
64+
source .venv/bin/activate || source .venv/Scripts/activate
7865
hash -r
79-
pip3 install .
8066
echo "::endgroup::"
8167
8268
# escape cwd so python doesn't pick up local module

.github/workflows/pip-audit.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@ jobs:
2020
- name: Checkout repository
2121
uses: actions/checkout@v6
2222

23-
- name: Install Python
24-
uses: actions/setup-python@v6
23+
- name: Install uv and Python
24+
uses: astral-sh/setup-uv@v7
2525
with:
2626
python-version: "3.10"
2727

2828
- name: Install Slither
2929
run: |
30-
python -m venv /tmp/pip-audit-env
31-
source /tmp/pip-audit-env/bin/activate
32-
33-
python -m pip install --upgrade pip setuptools wheel
34-
python -m pip install .
30+
uv export --format requirements-txt --no-emit-project > requirements.txt
3531
3632
- name: Run pip-audit
3733
uses: pypa/[email protected]
3834
with:
39-
virtual-environment: /tmp/pip-audit-env
35+
inputs: requirements.txt

.github/workflows/publish.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v6
1414

15-
- name: Set up Python
16-
uses: actions/setup-python@v6
15+
- name: Install uv
16+
uses: astral-sh/setup-uv@v7
1717
with:
18-
python-version: '3.x'
19-
18+
activate-environment: true
2019
- name: Build distributions
21-
run: |
22-
python -m pip install --upgrade pip
23-
python -m pip install build
24-
python -m build
20+
run: uv build
2521
- name: Upload distributions
2622
uses: actions/upload-artifact@v5
2723
with:

.github/workflows/test.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,15 @@ jobs:
2828
python: ${{ (github.event_name == 'pull_request' && fromJSON('["3.8", "3.12"]')) || fromJSON('["3.8", "3.9", "3.10", "3.11", "3.12"]') }}
2929
steps:
3030
- uses: actions/checkout@v6
31-
- name: Set up Python ${{ matrix.python }}
32-
uses: actions/setup-python@v6
31+
- name: Install uv and Python ${{ matrix.python }}
32+
uses: astral-sh/setup-uv@v7
3333
with:
3434
python-version: ${{ matrix.python }}
35-
cache: "pip"
36-
cache-dependency-path: setup.py
35+
activate-environment: true
3736

3837
- name: Install dependencies
3938
run: |
40-
pip install ".[test]"
39+
uv sync --group test
4140
4241
- name: Setup node
4342
uses: actions/setup-node@v6
@@ -101,12 +100,13 @@ jobs:
101100

102101
steps:
103102
- uses: actions/checkout@v6
104-
- name: Set up Python 3.8
105-
uses: actions/setup-python@v6
103+
- name: Install uv and Python
104+
uses: astral-sh/setup-uv@v7
106105
with:
107-
python-version: 3.8
106+
python-version: "3.8"
107+
activate-environment: true
108108

109-
- run: pip install coverage[toml]
109+
- run: uv pip install coverage[toml]
110110

111111
- name: download coverage data
112112
uses: actions/download-artifact@v6

CONTRIBUTING.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ A code walkthrough is available [here](https://www.youtube.com/watch?v=EUl3UlYSl
4747

4848
Instructions for installing a development version of Slither can be found in our [wiki](https://github.com/crytic/slither/wiki/Developer-installation).
4949

50+
For development setup, we use [uv](https://github.com/astral-sh/uv):
51+
52+
```bash
53+
# Install uv if you haven't already
54+
curl -LsSf https://astral.sh/uv/install.sh | sh
55+
56+
# Setup development environment
57+
make dev # Creates venv and installs all dependencies
58+
```
59+
5060
To run the unit tests, you need to clone this repository and run `make test`. Run a specific test with `make test TESTS=$test_name`. The names of tests can be obtained with `pytest tests --collect-only`.
5161

5262
### Linters
@@ -111,9 +121,9 @@ For each new detector, at least one regression tests must be present.
111121
112122
### Synchronization with crytic-compile
113123

114-
By default, `slither` follows either the latest version of crytic-compile in pip, or `crytic-compile@master` (look for dependencies in [`setup.py`](./setup.py). If crytic-compile development comes with breaking changes, the process to update `slither` is:
124+
By default, `slither` follows either the latest version of crytic-compile in pip, or `crytic-compile@master` (look for dependencies in [`pyproject.toml`](./pyproject.toml). If crytic-compile development comes with breaking changes, the process to update `slither` is:
115125

116-
- Update `slither/setup.py` to point to the related crytic-compile's branch
126+
- Update `slither/pyproject.toml` to point to the related crytic-compile's branch
117127
- Create a PR in `slither` and ensure it passes the CI
118128
- Once the development branch is merged in `crytic-compile@master`, ensure `slither` follows the `master` branch
119129

Makefile

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ run: $(VENV)/pyvenv.cfg
4949
@. $(VENV_BIN)/activate && slither $(ARGS)
5050

5151
$(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 .[$(SLITHER_EXTRA)]
52+
# Create virtual environment and install dependencies using uv
53+
uv venv $(VENV)
54+
uv sync --python $(VENV_BIN)/python --group $(SLITHER_EXTRA)
5655

5756
.PHONY: lint
5857
lint: $(VENV)/pyvenv.cfg
@@ -81,7 +80,7 @@ doc: $(VENV)/pyvenv.cfg
8180
.PHONY: package
8281
package: $(VENV)/pyvenv.cfg
8382
. $(VENV_BIN)/activate && \
84-
python3 -m build
83+
uv build
8584

8685
.PHONY: edit
8786
edit:

README.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
* [Features](#features)
1818
* [Usage](#usage)
1919
* [How to install](#how-to-install)
20+
* [Using uv (Recommended)](#using-uv-recommended)
2021
* [Using Pip](#using-pip)
21-
* [Using Git](#using-git)
22+
* [Using Git](#using-git-development)
2223
* [Using Docker](#using-docker)
2324
* [Integration](#integration)
2425
* [Detectors](#detectors)
@@ -70,13 +71,34 @@ slither tests/uninitialized.sol
7071
> Slither requires Python 3.8+.
7172
If you're **not** going to use one of the [supported compilation frameworks](https://github.com/crytic/crytic-compile), you need [solc](https://github.com/ethereum/solidity/), the Solidity compiler; we recommend using [solc-select](https://github.com/crytic/solc-select) to conveniently switch between solc versions.
7273

74+
### Using uv (Recommended)
75+
76+
[uv](https://github.com/astral-sh/uv) is a fast Python package manager that's 10-100x faster than pip.
77+
78+
```console
79+
# Install uv if you haven't already
80+
curl -LsSf https://astral.sh/uv/install.sh | sh
81+
82+
# Install slither as a tool
83+
uv tool install slither-analyzer
84+
85+
# Or run slither without installation
86+
uvx slither-analyzer <target>
87+
```
88+
89+
To upgrade:
90+
91+
```console
92+
uv tool upgrade slither-analyzer
93+
```
94+
7395
### Using Pip
7496

7597
```console
7698
python3 -m pip install slither-analyzer
7799
```
78100

79-
#### How to upgrade
101+
To upgrade:
80102

81103
```console
82104
python3 -m pip install --upgrade slither-analyzer
@@ -88,14 +110,19 @@ python3 -m pip install --upgrade slither-analyzer
88110
brew install slither-analyzer
89111
```
90112

91-
### Using Git
113+
### Using Git (Development)
92114

93115
```bash
94116
git clone https://github.com/crytic/slither.git && cd slither
95-
python3 -m pip install .
117+
118+
# Install as editable for development
119+
uv tool install -e .
120+
121+
# Or use uv run for testing without installation
122+
uv run slither <target>
96123
```
97124

98-
We recommend using a Python virtual environment, as detailed in the [Developer Installation Instructions](https://github.com/crytic/slither/wiki/Developer-installation), if you prefer to install Slither via git.
125+
The `-e` flag installs in editable mode, meaning changes to the source code are immediately reflected without reinstalling.
99126

100127
### Using Docker
101128

0 commit comments

Comments
 (0)