Skip to content

Commit 17cbe98

Browse files
authored
docs: improve onboarding (#1775)
1 parent 57e4411 commit 17cbe98

File tree

4 files changed

+204
-57
lines changed

4 files changed

+204
-57
lines changed

Makefile

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

17-
.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/'
20-
21-
.PHONY: install
22-
install: .uv .pre-commit
23-
uv pip install -U wheel
17+
.PHONY: install ## Install the package, dependencies, and pre-commit for local development
18+
install: .uv
2419
uv sync --frozen --group all
25-
uv pip install -v -e .
26-
pre-commit install
20+
uv run pre-commit install --install-hooks
2721

2822
.PHONY: rebuild-lockfiles ## Rebuild lockfiles from scratch, updating all dependencies
2923
rebuild-lockfiles: .uv
3024
uv lock --upgrade
3125

32-
.PHONY: install-rust-coverage
26+
.PHONY: install-rust-coverage ## Install Rust coverage tools
3327
install-rust-coverage:
3428
cargo install rustfilt coverage-prepare
3529
rustup component add llvm-tools-preview
3630

37-
.PHONY: install-pgo
31+
.PHONY: install-pgo ## Install Rust PGO tools
32+
install-pgo:
3833
rustup component add llvm-tools-preview
3934

40-
.PHONY: build-dev
35+
.PHONY: build-dev ## Build the development version of the package
4136
build-dev:
4237
@rm -f python/pydantic_core/*.so
4338
uv run maturin develop --uv
4439

45-
.PHONY: build-prod
40+
.PHONY: build-prod ## Build the production version of the package
4641
build-prod:
4742
@rm -f python/pydantic_core/*.so
4843
uv run maturin develop --uv --release
4944

50-
.PHONY: build-profiling
45+
.PHONY: build-profiling ## Build the profiling version of the package
5146
build-profiling:
5247
@rm -f python/pydantic_core/*.so
5348
uv run maturin develop --uv --profile profiling
5449

55-
.PHONY: build-coverage
50+
.PHONY: build-coverage ## Build the coverage version of the package
5651
build-coverage:
5752
@rm -f python/pydantic_core/*.so
5853
RUSTFLAGS='-C instrument-coverage' uv run maturin develop --uv --release
5954

60-
.PHONY: build-pgo
55+
.PHONY: build-pgo ## Build the PGO version of the package
6156
build-pgo:
6257
@rm -f python/pydantic_core/*.so
6358
$(eval PROFDATA := $(shell mktemp -d))
@@ -69,44 +64,44 @@ build-pgo:
6964
@rm -rf $(PROFDATA)
7065

7166

72-
.PHONY: build-wasm
67+
.PHONY: build-wasm ## Build the WebAssembly version of the package
7368
build-wasm:
7469
@echo 'This requires python 3.12, maturin and emsdk to be installed'
7570
uv run maturin build --release --target wasm32-unknown-emscripten --out dist -i 3.12
7671
ls -lh dist
7772

78-
.PHONY: format
73+
.PHONY: format ## Auto-format rust and python source files
7974
format:
8075
uv run ruff check --fix $(sources)
8176
uv run ruff format $(sources)
8277
cargo fmt
8378

84-
.PHONY: lint-python
79+
.PHONY: lint-python ## Lint python source files
8580
lint-python:
8681
uv run ruff check $(sources)
8782
uv run ruff format --check $(sources)
8883
uv run griffe dump -f -d google -LWARNING -o/dev/null python/pydantic_core
8984
$(mypy-stubtest)
9085

91-
.PHONY: lint-rust
86+
.PHONY: lint-rust ## Lint rust source files
9287
lint-rust:
9388
cargo fmt --version
9489
cargo fmt --all -- --check
9590
cargo clippy --version
9691
cargo clippy --tests -- -D warnings
9792

98-
.PHONY: lint
93+
.PHONY: lint ## Lint rust and python source files
9994
lint: lint-python lint-rust
10095

101-
.PHONY: pyright
96+
.PHONY: pyright ## Perform type-checking with pyright
10297
pyright:
10398
uv run pyright
10499

105-
.PHONY: test
100+
.PHONY: test ## Run all tests
106101
test:
107102
uv run pytest
108103

109-
.PHONY: testcov
104+
.PHONY: testcov ## Run tests and generate a coverage report
110105
testcov: build-coverage
111106
@rm -rf htmlcov
112107
@mkdir -p htmlcov
@@ -115,10 +110,10 @@ testcov: build-coverage
115110
coverage html -d htmlcov/python
116111
coverage-prepare html python/pydantic_core/*.so
117112

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

121-
.PHONY: clean
116+
.PHONY: clean ## Clear local caches and build artifacts
122117
clean:
123118
rm -rf `find . -name __pycache__`
124119
rm -f `find . -type f -name '*.py[co]' `
@@ -133,3 +128,10 @@ clean:
133128
rm -rf build
134129
rm -rf perf.data*
135130
rm -rf python/pydantic_core/*.so
131+
132+
.PHONY: help ## Display this message
133+
help:
134+
@grep -E \
135+
'^.PHONY: .*?## .*$$' $(MAKEFILE_LIST) | \
136+
sort | \
137+
awk 'BEGIN {FS = ".PHONY: |## "}; {printf "\033[36m%-19s\033[0m %s\n", $$2, $$3}'

README.md

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,35 +69,52 @@ 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. **[Rust](https://rustup.rs/)** - Rust stable (or nightly for coverage)
76+
2. **[uv](https://docs.astral.sh/uv/getting-started/installation/)** - Fast Python package manager (will install Python 3.9+ automatically)
77+
3. **[git](https://git-scm.com/)** - For version control
78+
4. **[make](https://www.gnu.org/software/make/)** - For running development commands (or use `nmake` on Windows)
79+
80+
### Quick Start
7581

7682
```bash
77-
# clone this repo or your fork
83+
# Clone the repository (or from your fork)
7884
git clone [email protected]:pydantic/pydantic-core.git
7985
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
86+
87+
# Install all dependencies using uv, setup pre-commit hooks, and build the development version
8488
make install
8589
```
8690

87-
That should be it, the example shown above should now run.
91+
Verify your installation by running:
92+
93+
```bash
94+
make
95+
```
96+
97+
This runs a full development cycle: formatting, building, linting, and testing
98+
99+
### Development Commands
100+
101+
Run `make help` to see all available commands, or use these common ones:
102+
103+
```bash
104+
make build-dev # to build the package during development
105+
make build-prod # to perform an optimised build for benchmarking
106+
make test # to run the tests
107+
make testcov # to run the tests and generate a coverage report
108+
make lint # to run the linter
109+
make format # to format python and rust code
110+
make all # to run to run build-dev + format + lint + test
111+
```
88112

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.
113+
### Useful Resources
92114

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`
115+
* [`python/pydantic_core/_pydantic_core.pyi`](./python/pydantic_core/_pydantic_core.pyi) - Python API types
116+
* [`python/pydantic_core/core_schema.py`](./python/pydantic_core/core_schema.py) - Core schema definitions
117+
* [`tests/`](./tests) - Comprehensive usage examples
101118

102119
## Profiling
103120

pyproject.toml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ authors = [
1414
{ name = 'David Montague', email = '[email protected]' },
1515
{ name = 'David Hewitt', email = '[email protected]' },
1616
{ name = 'Sydney Runkle', email = '[email protected]' },
17-
{ name = 'Victorien Plot', email='[email protected]' },
17+
{ name = 'Victorien Plot', email = '[email protected]' },
1818
]
1919
classifiers = [
2020
'Development Status :: 3 - Alpha',
@@ -39,9 +39,7 @@ classifiers = [
3939
'Operating System :: MacOS',
4040
'Typing :: Typed',
4141
]
42-
dependencies = [
43-
'typing-extensions>=4.14.1',
44-
]
42+
dependencies = ['typing-extensions>=4.14.1']
4543
dynamic = ['readme', 'version']
4644

4745
[project.urls]
@@ -55,26 +53,33 @@ testing = [
5553
{ include-group = "dev" },
5654
'coverage',
5755
'dirty-equals',
58-
'inline-snapshot',
56+
'exceptiongroup; python_version < "3.11"',
5957
'hypothesis',
58+
'inline-snapshot',
59+
# numpy doesn't offer prebuilt wheels for all versions and platforms we test in CI e.g. aarch64 musllinux
60+
'numpy; python_version < "3.13" and implementation_name == "cpython" and platform_machine == "x86_64"',
6061
# pandas doesn't offer prebuilt wheels for all versions and platforms we test in CI e.g. aarch64 musllinux
6162
'pandas; python_version < "3.13" and implementation_name == "cpython" and platform_machine == "x86_64"',
6263
'pytest',
6364
# pytest-examples currently depends on aiohttp via black; we don't want to build it on platforms like aarch64 musllinux in CI
6465
'pytest-examples; implementation_name == "cpython" and platform_machine == "x86_64"',
65-
'pytest-speed',
6666
'pytest-mock',
6767
'pytest-pretty',
6868
'pytest-run-parallel',
69+
'pytest-speed',
6970
'pytest-timeout',
7071
'python-dateutil',
71-
# numpy doesn't offer prebuilt wheels for all versions and platforms we test in CI e.g. aarch64 musllinux
72-
'numpy; python_version < "3.13" and implementation_name == "cpython" and platform_machine == "x86_64"',
73-
'exceptiongroup; python_version < "3.11"',
74-
'tzdata',
7572
'typing-inspection>=0.4.1',
73+
'tzdata',
74+
]
75+
linting = [
76+
{ include-group = "dev" },
77+
'griffe',
78+
'mypy',
79+
'pre-commit',
80+
'pyright',
81+
'ruff',
7682
]
77-
linting = [{ include-group = "dev" }, 'griffe', 'pyright', 'ruff', 'mypy']
7883
wasm = [{ include-group = "dev" }, 'ruff']
7984
codspeed = [
8085
# codspeed is only run on CI, with latest version of CPython

0 commit comments

Comments
 (0)