Skip to content

Commit c36a442

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 c36a442

File tree

2 files changed

+63
-42
lines changed

2 files changed

+63
-42
lines changed

Makefile

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,50 @@ 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
2323
uv pip install -U wheel
2424
uv sync --frozen --group all
25-
uv pip install -v -e .
26-
pre-commit install
25+
uv pip install pre-commit
26+
uv run pre-commit install --install-hooks
2727

2828
.PHONY: rebuild-lockfiles ## Rebuild lockfiles from scratch, updating all dependencies
2929
rebuild-lockfiles: .uv
3030
uv lock --upgrade
3131

32-
.PHONY: install-rust-coverage
32+
.PHONY: install-rust-coverage ## Install Rust coverage tools
3333
install-rust-coverage:
3434
cargo install rustfilt coverage-prepare
3535
rustup component add llvm-tools-preview
3636

37-
.PHONY: install-pgo
37+
.PHONY: install-pgo ## Install Rust PGO tools
38+
install-pgo:
3839
rustup component add llvm-tools-preview
3940

40-
.PHONY: build-dev
41+
.PHONY: build-dev ## Build the development version of the package
4142
build-dev:
4243
@rm -f python/pydantic_core/*.so
4344
uv run maturin develop --uv
4445

45-
.PHONY: build-prod
46+
.PHONY: build-prod ## Build the production version of the package
4647
build-prod:
4748
@rm -f python/pydantic_core/*.so
4849
uv run maturin develop --uv --release
4950

50-
.PHONY: build-profiling
51+
.PHONY: build-profiling ## Build the profiling version of the package
5152
build-profiling:
5253
@rm -f python/pydantic_core/*.so
5354
uv run maturin develop --uv --profile profiling
5455

55-
.PHONY: build-coverage
56+
.PHONY: build-coverage ## Build the coverage version of the package
5657
build-coverage:
5758
@rm -f python/pydantic_core/*.so
5859
RUSTFLAGS='-C instrument-coverage' uv run maturin develop --uv --release
5960

60-
.PHONY: build-pgo
61+
.PHONY: build-pgo ## Build the PGO version of the package
6162
build-pgo:
6263
@rm -f python/pydantic_core/*.so
6364
$(eval PROFDATA := $(shell mktemp -d))
@@ -69,44 +70,44 @@ build-pgo:
6970
@rm -rf $(PROFDATA)
7071

7172

72-
.PHONY: build-wasm
73+
.PHONY: build-wasm ## Build the WebAssembly version of the package
7374
build-wasm:
7475
@echo 'This requires python 3.12, maturin and emsdk to be installed'
7576
uv run maturin build --release --target wasm32-unknown-emscripten --out dist -i 3.12
7677
ls -lh dist
7778

78-
.PHONY: format
79+
.PHONY: format ## Auto-format rust and python source files
7980
format:
8081
uv run ruff check --fix $(sources)
8182
uv run ruff format $(sources)
8283
cargo fmt
8384

84-
.PHONY: lint-python
85+
.PHONY: lint-python ## Lint python source files
8586
lint-python:
8687
uv run ruff check $(sources)
8788
uv run ruff format --check $(sources)
8889
uv run griffe dump -f -d google -LWARNING -o/dev/null python/pydantic_core
8990
$(mypy-stubtest)
9091

91-
.PHONY: lint-rust
92+
.PHONY: lint-rust ## Lint rust source files
9293
lint-rust:
9394
cargo fmt --version
9495
cargo fmt --all -- --check
9596
cargo clippy --version
9697
cargo clippy --tests -- -D warnings
9798

98-
.PHONY: lint
99+
.PHONY: lint ## Lint rust and python source files
99100
lint: lint-python lint-rust
100101

101-
.PHONY: pyright
102+
.PHONY: pyright ## Perform type-checking with pyright
102103
pyright:
103104
uv run pyright
104105

105-
.PHONY: test
106+
.PHONY: test ## Run all tests
106107
test:
107108
uv run pytest
108109

109-
.PHONY: testcov
110+
.PHONY: testcov ## Run tests and generate a coverage report
110111
testcov: build-coverage
111112
@rm -rf htmlcov
112113
@mkdir -p htmlcov
@@ -115,10 +116,10 @@ testcov: build-coverage
115116
coverage html -d htmlcov/python
116117
coverage-prepare html python/pydantic_core/*.so
117118

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

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

README.md

Lines changed: 33 additions & 20 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
78-
git clone git@github.com:pydantic/pydantic-core.git
82+
# Clone the repository
83+
git clone https://github.com/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)