Skip to content

Commit b867e7d

Browse files
authored
Migrate config to pyproject.toml and use uv for project management (#4627)
1 parent 4f74348 commit b867e7d

File tree

15 files changed

+2529
-419
lines changed

15 files changed

+2529
-419
lines changed

.github/dependabot.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
version: 2
22
updates:
3-
- package-ecosystem: pip
4-
directory: /
3+
4+
updates:
5+
- package-ecosystem: "uv"
6+
directory: "/"
57
schedule:
6-
interval: weekly
8+
interval: "weekly"
79
groups:
810
actions:
911
patterns:

.github/workflows/docs.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: Publish docs
32

43
on:
@@ -16,11 +15,16 @@ jobs:
1615
- name: Checkout repository
1716
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
1817

19-
- name: Setup python
18+
- name: Set up Python
2019
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
2120
with:
22-
python-version: '3.13'
23-
cache: 'pip'
21+
python-version-file: "pyproject.toml"
22+
23+
- name: Install uv ${{ vars.UV_VERSION }}
24+
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
25+
with:
26+
enable-cache: true
27+
version: ${{ vars.UV_VERSION }}
2428

2529
- name: Install dependencies to venv
2630
run: make _pyspec
@@ -29,4 +33,4 @@ jobs:
2933
run: make _copy_docs
3034

3135
- name: Deploy
32-
run: venv/bin/mkdocs gh-deploy --force
36+
run: uv run mkdocs gh-deploy --force

.github/workflows/generate_vectors.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,28 @@ on:
1818
type: string
1919
required: true
2020
schedule:
21-
- cron: '0 2 * * *'
21+
- cron: "0 2 * * *"
2222

2323
jobs:
2424
generate-tests:
25-
timeout-minutes: 720 # 12 hours
25+
timeout-minutes: 720 # 12 hours
2626
runs-on: [self-hosted-ghr-custom, size-xl-x64, profile-consensusSpecs]
2727
steps:
2828
- name: Checkout repository
2929
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3030
with:
3131
repository: ${{ inputs.repo }}
32-
path: 'consensus-specs'
32+
path: "consensus-specs"
3333
ref: ${{ inputs.ref }}
34-
- name: Setup Python
34+
- name: Set up Python
3535
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
3636
with:
37-
python-version: '3.13'
38-
cache: ''
37+
python-version-file: "consensus-specs/pyproject.toml"
38+
- name: Install uv ${{ vars.UV_VERSION }}
39+
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
40+
with:
41+
enable-cache: true
42+
version: ${{ vars.UV_VERSION }}
3943
- name: Generate tests
4044
run: |
4145
cd consensus-specs

.github/workflows/nightly-tests.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ on:
1414
required: true
1515
schedule:
1616
# Every day at 00:00 UTC
17-
- cron: '0 0 * * *'
17+
- cron: "0 0 * * *"
1818

1919
jobs:
2020
tests:
21-
timeout-minutes: 720 # 12 hours
21+
timeout-minutes: 720 # 12 hours
2222
runs-on: [self-hosted-ghr-custom, size-s-x64, profile-consensusSpecs]
2323
strategy:
2424
fail-fast: false
@@ -37,10 +37,15 @@ jobs:
3737
steps:
3838
- name: Checkout repository
3939
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
40-
- name: Setup Python
40+
- name: Set up Python
4141
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
4242
with:
43-
python-version: '3.13'
43+
python-version-file: "pyproject.toml"
44+
- name: Install uv ${{ vars.UV_VERSION }}
45+
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
46+
with:
47+
enable-cache: true
48+
version: ${{ vars.UV_VERSION }}
4449
- name: test-${{ matrix.fork }}
4550
run: make test component=pyspec preset=mainnet fork=${{ matrix.fork }}
4651
- name: Prepare test results for upload

.github/workflows/release.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ name: Release
33
on:
44
push:
55
tags:
6-
- 'v*'
6+
- "v*"
77

88
jobs:
99
release:
10-
timeout-minutes: 1440 # 24 hours
10+
timeout-minutes: 1440 # 24 hours
1111
runs-on: [self-hosted-ghr-custom, size-xl-x64, profile-consensusSpecs]
1212
permissions:
1313
contents: write
@@ -19,13 +19,19 @@ jobs:
1919
- name: Checkout repository
2020
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
2121
with:
22-
path: 'consensus-specs'
22+
path: "consensus-specs"
2323

2424
# Setup python
25-
- name: Setup Python
25+
- name: Set up Python
2626
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
2727
with:
28-
python-version: '3.13'
28+
python-version-file: "consensus-specs/pyproject.toml"
29+
30+
- name: Install uv ${{ vars.UV_VERSION }}
31+
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
32+
with:
33+
enable-cache: true
34+
version: ${{ vars.UV_VERSION }}
2935

3036
# Check the tag matches the version
3137
- name: Version check

.github/workflows/run-tests.yml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ jobs:
1818
steps:
1919
- name: Checkout repository
2020
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
21-
- name: Setup python
21+
- name: Set up Python
2222
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
2323
with:
24-
python-version: '3.13'
25-
cache: 'pip'
24+
python-version-file: "pyproject.toml"
25+
- name: Install uv ${{ vars.UV_VERSION }}
26+
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
27+
with:
28+
enable-cache: true
29+
version: ${{ vars.UV_VERSION }}
2630
- name: Run linter for pyspec
2731
run: |
2832
make lint
@@ -45,11 +49,10 @@ jobs:
4549
steps:
4650
- name: Checkout repository
4751
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
48-
- name: Setup python
52+
- name: Set up Python
4953
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
5054
with:
51-
python-version: '3.13'
52-
cache: 'pip'
55+
python-version-file: "pyproject.toml"
5356
- name: Check fork comments
5457
run: python3 scripts/check_fork_comments.py
5558

@@ -58,11 +61,15 @@ jobs:
5861
steps:
5962
- name: Checkout repository
6063
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
61-
- name: Setup python
64+
- name: Set up Python
6265
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
6366
with:
64-
python-version: '3.13'
65-
cache: 'pip'
67+
python-version-file: "pyproject.toml"
68+
- name: Install uv ${{ vars.UV_VERSION }}
69+
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
70+
with:
71+
enable-cache: true
72+
version: ${{ vars.UV_VERSION }}
6673
- name: Run framework tests
6774
run: make test component=fw
6875
- name: Prepare test results for upload
@@ -94,11 +101,15 @@ jobs:
94101
steps:
95102
- name: Checkout repository
96103
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
97-
- name: Setup python
104+
- name: Set up Python
98105
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
99106
with:
100-
python-version: '3.13'
101-
cache: 'pip'
107+
python-version-file: "pyproject.toml"
108+
- name: Install uv ${{ vars.UV_VERSION }}
109+
uses: astral-sh/setup-uv@d0cc045d04ccac9d8b7881df0226f9e82c39688e # v6.8.0
110+
with:
111+
enable-cache: true
112+
version: ${{ vars.UV_VERSION }}
102113
- name: Run pyspec tests for ${{ matrix.fork }}
103114
run: make test component=pyspec preset=minimal fork=${{ matrix.fork }}
104115
- name: Prepare test results for upload

Makefile

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ALL_EXECUTABLE_SPEC_NAMES = \
1818

1919
# A list of fake targets.
2020
.PHONY: \
21+
_sync \
2122
clean \
2223
coverage \
2324
help \
@@ -173,7 +174,7 @@ help-verbose:
173174
@echo "$(BOLD)make clean$(NORM)"
174175
@echo ""
175176
@echo " Removes all untracked files. This includes:"
176-
@echo " - Virtual environment (venv/)"
177+
@echo " - Virtual environment (.venv/)"
177178
@echo " - Build artifacts"
178179
@echo " - Cache files"
179180
@echo ""
@@ -187,19 +188,18 @@ help-verbose:
187188
# Virtual Environment
188189
###############################################################################
189190

190-
VENV = venv
191-
PYTHON_VENV = $(VENV)/bin/python3
192-
PIP_VENV = $(VENV)/bin/pip3
193-
CODESPELL_VENV = $(VENV)/bin/codespell
194-
MDFORMAT_VENV = $(VENV)/bin/mdformat
195-
MKDOCS_VENV = $(VENV)/bin/mkdocs
191+
VENV = .venv
192+
UV_RUN = uv run
196193

197-
# Make a virtual environment.
198-
$(VENV):
199-
@python3 scripts/check_python_version.py
200-
@echo "Creating virtual environment"
201-
@python3 -m venv $(VENV)
202-
@$(PIP_VENV) install --quiet --upgrade uv
194+
# Sync dependencies using uv.
195+
_sync: MAYBE_VERBOSE := $(if $(filter true,$(verbose)),--verbose)
196+
_sync: pyproject.toml
197+
@command -v uv >/dev/null 2>&1 || { \
198+
echo "Error: uv is required but not installed."; \
199+
echo "Install with: curl -LsSf https://astral.sh/uv/install.sh | sh"; \
200+
exit 1; \
201+
}
202+
@uv sync --all-extras $(MAYBE_VERBOSE)
203203

204204
###############################################################################
205205
# Specification
@@ -210,14 +210,8 @@ PYSPEC_DIR = $(TEST_LIBS_DIR)/pyspec
210210

211211
# Create the pyspec for all phases.
212212
_pyspec: MAYBE_VERBOSE := $(if $(filter true,$(verbose)),--verbose)
213-
_pyspec: $(VENV) setup.py pyproject.toml
214-
@python3 scripts/check_python_version.py
215-
@$(PYTHON_VENV) -m uv pip install $(MAYBE_VERBOSE) --reinstall-package=eth2spec .[docs,lint,test,generator]
216-
@for dir in $(ALL_EXECUTABLE_SPEC_NAMES); do \
217-
mkdir -p "./tests/core/pyspec/eth2spec/$$dir"; \
218-
cp "./build/lib/eth2spec/$$dir/mainnet.py" "./tests/core/pyspec/eth2spec/$$dir/mainnet.py"; \
219-
cp "./build/lib/eth2spec/$$dir/minimal.py" "./tests/core/pyspec/eth2spec/$$dir/minimal.py"; \
220-
done
213+
_pyspec: _sync
214+
@$(UV_RUN) python -m pysetup.generate_specs --all-forks $(MAYBE_VERBOSE)
221215

222216
###############################################################################
223217
# Testing
@@ -237,7 +231,7 @@ test: MAYBE_ETH2SPEC := $(if $(filter fw,$(component)),,$(PYSPEC_DIR)/eth2spec)
237231
test: MAYBE_INFRA := $(if $(filter pyspec,$(component)),,$(CURDIR)/tests/infra)
238232
test: _pyspec
239233
@mkdir -p $(TEST_REPORT_DIR)
240-
@$(PYTHON_VENV) -m pytest \
234+
@$(UV_RUN) pytest \
241235
$(MAYBE_PARALLEL) \
242236
--capture=no \
243237
$(MAYBE_TEST) \
@@ -263,7 +257,7 @@ COVERAGE_SCOPE := $(foreach S,$(ALL_EXECUTABLE_SPEC_NAMES), --cov=eth2spec.$S.$(
263257
_test_with_coverage: MAYBE_TEST := $(if $(k),-k=$(k))
264258
_test_with_coverage: MAYBE_FORK := $(if $(fork),--fork=$(fork))
265259
_test_with_coverage: _pyspec
266-
@$(PYTHON_VENV) -m pytest \
260+
@$(UV_RUN) pytest \
267261
-n auto \
268262
$(MAYBE_TEST) \
269263
$(MAYBE_FORK) \
@@ -300,27 +294,25 @@ _copy_docs:
300294

301295
# Start a local documentation server.
302296
serve_docs: _pyspec _copy_docs
303-
@$(MKDOCS_VENV) build
304-
@$(MKDOCS_VENV) serve
297+
@$(UV_RUN) mkdocs build
298+
@$(UV_RUN) mkdocs serve
305299

306300
###############################################################################
307301
# Checks
308302
###############################################################################
309303

310-
MYPY_CONFIG = $(CURDIR)/mypy.ini
311-
PYLINT_CONFIG = $(CURDIR)/pylint.ini
312-
313-
PYLINT_SCOPE := $(foreach S,$(ALL_EXECUTABLE_SPEC_NAMES), $(PYSPEC_DIR)/eth2spec/$S)
314-
MYPY_SCOPE := $(foreach S,$(ALL_EXECUTABLE_SPEC_NAMES), -p eth2spec.$S)
315304
MARKDOWN_FILES := $(shell find $(CURDIR) -name '*.md')
305+
MYPY_PACKAGE_BASE := $(subst /,.,$(PYSPEC_DIR:$(CURDIR)/%=%))
306+
MYPY_SCOPE := $(foreach S,$(ALL_EXECUTABLE_SPEC_NAMES), -p $(MYPY_PACKAGE_BASE).eth2spec.$S)
316307

317308
# Check for mistakes.
318309
lint: _pyspec
319-
@$(MDFORMAT_VENV) --number --wrap=80 $(MARKDOWN_FILES)
320-
@$(CODESPELL_VENV) . --skip "./.git,$(VENV),$(PYSPEC_DIR)/.mypy_cache" -I .codespell-whitelist
321-
@$(PYTHON_VENV) -m ruff check --fix --quiet $(CURDIR)/tests $(CURDIR)/pysetup $(CURDIR)/setup.py
322-
@$(PYTHON_VENV) -m ruff format --quiet $(CURDIR)/tests $(CURDIR)/pysetup $(CURDIR)/setup.py
323-
@$(PYTHON_VENV) -m mypy --config-file $(MYPY_CONFIG) $(MYPY_SCOPE)
310+
@uv --quiet lock --check
311+
@$(UV_RUN) mdformat --number --wrap=80 $(MARKDOWN_FILES)
312+
@$(UV_RUN) codespell . --skip "./.git,$(VENV),$(PYSPEC_DIR)/.mypy_cache" -I .codespell-whitelist
313+
@$(UV_RUN) ruff check --fix --quiet $(CURDIR)/tests $(CURDIR)/pysetup $(CURDIR)/setup.py
314+
@$(UV_RUN) ruff format --quiet $(CURDIR)/tests $(CURDIR)/pysetup $(CURDIR)/setup.py
315+
@$(UV_RUN) mypy $(MYPY_SCOPE)
324316

325317
###############################################################################
326318
# Generators
@@ -338,7 +330,7 @@ reftests: MAYBE_TESTS := $(if $(k),--cases $(subst ${COMMA}, ,$(k)))
338330
reftests: MAYBE_FORKS := $(if $(fork),--forks $(subst ${COMMA}, ,$(fork)))
339331
reftests: MAYBE_PRESETS := $(if $(preset),--presets $(subst ${COMMA}, ,$(preset)))
340332
reftests: _pyspec
341-
@$(PYTHON_VENV) -m tests.generators.main \
333+
@$(UV_RUN) python -m tests.generators.main \
342334
--output $(TEST_VECTOR_DIR) \
343335
$(MAYBE_VERBOSE) \
344336
$(MAYBE_THREADS) \
@@ -354,7 +346,7 @@ comptests: MAYBE_FORKS := $(if $(fork),--forks $(subst ${COMMA}, ,$(fork)))
354346
comptests: MAYBE_PRESETS := $(if $(preset),--presets $(subst ${COMMA}, ,$(preset)))
355347
comptests: MAYBE_SEED := $(if $(seed),--fc-gen-seed $(seed))
356348
comptests: _pyspec
357-
@$(PYTHON_VENV) -m tests.generators.compliance_runners.fork_choice.test_gen \
349+
@$(UV_RUN) python -m tests.generators.compliance_runners.fork_choice.test_gen \
358350
--output $(COMP_TEST_VECTOR_DIR) \
359351
--fc-gen-config $(FC_GEN_CONFIG) \
360352
$(MAYBE_THREADS) \

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ reference tests are available
6161

6262
## Contributors
6363

64+
### Prerequisites
65+
66+
This project uses `uv` ([docs.astral.sh/uv](https://docs.astral.sh/uv/)) to
67+
manage its dependencies and virtual environment. `uv` can
68+
[download Python](https://docs.astral.sh/uv/guides/install-python/#installing-a-specific-version)
69+
for your target platform if one of the required versions (3.10-3.13) is not
70+
available natively.
71+
72+
`uv` can be installed via curl (recommended over a pip-install as it can
73+
self-update and manage Python versions):
74+
75+
```console
76+
curl -LsSf https://astral.sh/uv/install.sh | sh
77+
```
78+
6479
### Installation and usage
6580

6681
Clone the repository with:

mypy.ini

Lines changed: 0 additions & 11 deletions
This file was deleted.

pylint.ini

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)