Skip to content

Commit 5e1c583

Browse files
committed
docs: improve onboarding
Onboarding was not very user-friendly and could be way easier. New contributors were hitting walls trying to get the project running locally. What got fixed: - Made `make install` actually work reliably in one shot - Added `make help` with proper descriptions to all targets so people know what commands exist - Rewrote the README setup section to be way clearer
1 parent 1b3815c commit 5e1c583

File tree

2 files changed

+62
-42
lines changed

2 files changed

+62
-42
lines changed

Makefile

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,49 @@ USE_MATURIN = $(shell [ "$$VIRTUAL_ENV" != "" ] && (which maturin))
1515
@uv -V || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'
1616

1717
.PHONY: .pre-commit ## Check that pre-commit is installed
18-
.pre-commit:
19-
@pre-commit -V || echo 'Please install pre-commit: https://pre-commit.com/'
18+
.pre-commit: .uv
19+
@uv run pre-commit -V || uv pip install pre-commit
2020

21-
.PHONY: install
21+
.PHONY: install ## Install the package, dependencies, and pre-commit for local development
2222
install: .uv .pre-commit
23-
uv pip install -U wheel
2423
uv sync --frozen --group all
25-
uv pip install -v -e .
26-
pre-commit install
24+
uv pip install pre-commit
25+
uv run pre-commit install --install-hooks
2726

2827
.PHONY: rebuild-lockfiles ## Rebuild lockfiles from scratch, updating all dependencies
2928
rebuild-lockfiles: .uv
3029
uv lock --upgrade
3130

32-
.PHONY: install-rust-coverage
31+
.PHONY: install-rust-coverage ## Install Rust coverage tools
3332
install-rust-coverage:
3433
cargo install rustfilt coverage-prepare
3534
rustup component add llvm-tools-preview
3635

37-
.PHONY: install-pgo
36+
.PHONY: install-pgo ## Install Rust PGO tools
37+
install-pgo:
3838
rustup component add llvm-tools-preview
3939

40-
.PHONY: build-dev
40+
.PHONY: build-dev ## Build the development version of the package
4141
build-dev:
4242
@rm -f python/pydantic_core/*.so
4343
uv run maturin develop --uv
4444

45-
.PHONY: build-prod
45+
.PHONY: build-prod ## Build the production version of the package
4646
build-prod:
4747
@rm -f python/pydantic_core/*.so
4848
uv run maturin develop --uv --release
4949

50-
.PHONY: build-profiling
50+
.PHONY: build-profiling ## Build the profiling version of the package
5151
build-profiling:
5252
@rm -f python/pydantic_core/*.so
5353
uv run maturin develop --uv --profile profiling
5454

55-
.PHONY: build-coverage
55+
.PHONY: build-coverage ## Build the coverage version of the package
5656
build-coverage:
5757
@rm -f python/pydantic_core/*.so
5858
RUSTFLAGS='-C instrument-coverage' uv run maturin develop --uv --release
5959

60-
.PHONY: build-pgo
60+
.PHONY: build-pgo ## Build the PGO version of the package
6161
build-pgo:
6262
@rm -f python/pydantic_core/*.so
6363
$(eval PROFDATA := $(shell mktemp -d))
@@ -69,44 +69,44 @@ build-pgo:
6969
@rm -rf $(PROFDATA)
7070

7171

72-
.PHONY: build-wasm
72+
.PHONY: build-wasm ## Build the WebAssembly version of the package
7373
build-wasm:
7474
@echo 'This requires python 3.12, maturin and emsdk to be installed'
7575
uv run maturin build --release --target wasm32-unknown-emscripten --out dist -i 3.12
7676
ls -lh dist
7777

78-
.PHONY: format
78+
.PHONY: format ## Auto-format rust and python source files
7979
format:
8080
uv run ruff check --fix $(sources)
8181
uv run ruff format $(sources)
8282
cargo fmt
8383

84-
.PHONY: lint-python
84+
.PHONY: lint-python ## Lint python source files
8585
lint-python:
8686
uv run ruff check $(sources)
8787
uv run ruff format --check $(sources)
8888
uv run griffe dump -f -d google -LWARNING -o/dev/null python/pydantic_core
8989
$(mypy-stubtest)
9090

91-
.PHONY: lint-rust
91+
.PHONY: lint-rust ## Lint rust source files
9292
lint-rust:
9393
cargo fmt --version
9494
cargo fmt --all -- --check
9595
cargo clippy --version
9696
cargo clippy --tests -- -D warnings
9797

98-
.PHONY: lint
98+
.PHONY: lint ## Lint rust and python source files
9999
lint: lint-python lint-rust
100100

101-
.PHONY: pyright
101+
.PHONY: pyright ## Perform type-checking with pyright
102102
pyright:
103103
uv run pyright
104104

105-
.PHONY: test
105+
.PHONY: test ## Run all tests
106106
test:
107107
uv run pytest
108108

109-
.PHONY: testcov
109+
.PHONY: testcov ## Run tests and generate a coverage report
110110
testcov: build-coverage
111111
@rm -rf htmlcov
112112
@mkdir -p htmlcov
@@ -115,10 +115,10 @@ testcov: build-coverage
115115
coverage html -d htmlcov/python
116116
coverage-prepare html python/pydantic_core/*.so
117117

118-
.PHONY: all
118+
.PHONY: all ## Run the standard set of checks performed in CI
119119
all: format build-dev lint test
120120

121-
.PHONY: clean
121+
.PHONY: clean ## Clear local caches and build artifacts
122122
clean:
123123
rm -rf `find . -name __pycache__`
124124
rm -f `find . -type f -name '*.py[co]' `
@@ -133,3 +133,10 @@ clean:
133133
rm -rf build
134134
rm -rf perf.data*
135135
rm -rf python/pydantic_core/*.so
136+
137+
.PHONY: help ## Display this message
138+
help:
139+
@grep -E \
140+
'^.PHONY: .*?## .*$$' $(MAKEFILE_LIST) | \
141+
sort | \
142+
awk 'BEGIN {FS = ".PHONY: |## "}; {printf "\033[36m%-19s\033[0m %s\n", $$2, $$3}'

README.md

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,35 +69,48 @@ except ValidationError as e:
6969

7070
## Getting Started
7171

72-
You'll need rust stable [installed](https://rustup.rs/), or rust nightly if you want to generate accurate coverage.
72+
### Prerequisites
7373

74-
With rust and python 3.9+ installed, compiling pydantic-core should be possible with roughly the following:
74+
You'll need:
75+
1. **[uv](https://docs.astral.sh/uv/getting-started/installation/)** - Fast Python package manager
76+
2. **[Rust](https://rustup.rs/)** - Rust stable (or nightly for coverage)
77+
3. **Python 3.9+**
78+
79+
### Quick Start
7580

7681
```bash
77-
# clone this repo or your fork
82+
# Clone the repository
7883
git clone [email protected]:pydantic/pydantic-core.git
7984
cd pydantic-core
80-
# create a new virtual env
81-
python3 -m venv env
82-
source env/bin/activate
83-
# install dependencies and install pydantic-core
85+
86+
# One command to set up everything!
8487
make install
8588
```
8689

87-
That should be it, the example shown above should now run.
90+
That's it! 🎉 The `make install` command will:
91+
- Install all dependencies using uv
92+
- Set up pre-commit hooks
93+
- Build the development version
94+
- Make the example above ready to run
95+
96+
### Development Commands
97+
98+
Run `make help` to see all available commands, or use these common ones:
99+
100+
```bash
101+
make build-dev # Build for development
102+
make test # Run tests
103+
make lint # Check code style
104+
make format # Auto-format code
105+
make testcov # Run tests with coverage
106+
make all # Run format + build + lint + test
107+
```
88108

89-
You might find it useful to look at [`python/pydantic_core/_pydantic_core.pyi`](./python/pydantic_core/_pydantic_core.pyi) and
90-
[`python/pydantic_core/core_schema.py`](./python/pydantic_core/core_schema.py) for more information on the python API,
91-
beyond that, [`tests/`](./tests) provide a large number of examples of usage.
109+
### Useful Resources
92110

93-
If you want to contribute to pydantic-core, you'll want to use some other make commands:
94-
* `make build-dev` to build the package during development
95-
* `make build-prod` to perform an optimised build for benchmarking
96-
* `make test` to run the tests
97-
* `make testcov` to run the tests and generate a coverage report
98-
* `make lint` to run the linter
99-
* `make format` to format python and rust code
100-
* `make` to run `format build-dev lint test`
111+
* [`python/pydantic_core/_pydantic_core.pyi`](./python/pydantic_core/_pydantic_core.pyi) - Python API types
112+
* [`python/pydantic_core/core_schema.py`](./python/pydantic_core/core_schema.py) - Core schema definitions
113+
* [`tests/`](./tests) - Comprehensive usage examples
101114

102115
## Profiling
103116

0 commit comments

Comments
 (0)