Skip to content

Commit a12d320

Browse files
authored
Merge branch 'main' into update_relationship_attributes_docs
2 parents e4eebb0 + 6f6f50c commit a12d320

29 files changed

+1442
-320
lines changed

.github/labeler.yml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
docs:
2-
- changed-files:
3-
- any-glob-to-any-file:
4-
- docs/**/*
5-
- docs_src/**/*
2+
- all:
3+
- changed-files:
4+
- any-glob-to-any-file:
5+
- docs/**
6+
- docs_src/**
7+
- all-globs-to-all-files:
8+
- '!sqlmodel/**'
9+
- '!pyproject.toml'
610

711
internal:
8-
- changed-files:
9-
- any-glob-to-any-file:
10-
- .github/**/*
11-
- scripts/**/*
12-
- .gitignore
13-
- .pre-commit-config.yaml
14-
- pdm_build.py
15-
- requirements*.txt
12+
- all:
13+
- changed-files:
14+
- any-glob-to-any-file:
15+
- .github/**
16+
- scripts/**
17+
- .gitignore
18+
- .pre-commit-config.yaml
19+
- pdm_build.py
20+
- requirements*.txt
21+
- all-globs-to-all-files:
22+
- '!docs/**'
23+
- '!sqlmodel/**'
24+
- '!pyproject.toml'

.github/workflows/build-docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ jobs:
7777
with:
7878
name: docs-site
7979
path: ./site/**
80+
include-hidden-files: true
8081

8182
# https://github.com/marketplace/actions/alls-green#why
8283
docs-all-green: # This job does nothing and is only used for the branch protection

.github/workflows/labeler.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Pull Request Labeler and Checker
1+
name: Labels
22
on:
33
pull_request_target:
44
types:
@@ -19,7 +19,10 @@ jobs:
1919
- uses: actions/labeler@v5
2020
# Run this after labeler applied labels
2121
check-labels:
22-
name: Check labels
22+
needs:
23+
- labeler
24+
permissions:
25+
pull-requests: read
2326
runs-on: ubuntu-latest
2427
steps:
2528
- uses: docker://agilepathway/pull-request-label-checker:latest

.github/workflows/latest-changes.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ jobs:
3030
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }}
3131
with:
3232
limit-access-to-actor: true
33-
- uses: docker://tiangolo/latest-changes:0.2.0
34-
# - uses: tiangolo/latest-changes@main
33+
- uses: tiangolo/[email protected]
3534
with:
3635
token: ${{ secrets.GITHUB_TOKEN }}
3736
latest_changes_file: docs/release-notes.md

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ jobs:
7676
with:
7777
name: coverage-${{ matrix.python-version }}-${{ matrix.pydantic-version }}
7878
path: coverage
79+
include-hidden-files: true
80+
7981
coverage-combine:
8082
needs:
8183
- test
@@ -86,7 +88,7 @@ jobs:
8688

8789
- uses: actions/setup-python@v5
8890
with:
89-
python-version: '3.8'
91+
python-version: '3.12'
9092

9193
- name: Get coverage files
9294
uses: actions/download-artifact@v4
@@ -100,13 +102,14 @@ jobs:
100102
- run: ls -la coverage
101103
- run: coverage combine coverage
102104
- run: coverage report
103-
- run: coverage html --show-contexts --title "Coverage for ${{ github.sha }}"
105+
- run: coverage html --title "Coverage for ${{ github.sha }}"
104106

105107
- name: Store coverage HTML
106108
uses: actions/upload-artifact@v4
107109
with:
108110
name: coverage-html
109111
path: htmlcov
112+
include-hidden-files: true
110113

111114
# https://github.com/marketplace/actions/alls-green#why
112115
alls-green: # This job does nothing and is only used for the branch protection

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
*.pyc
2-
env*
32
.mypy_cache
43
.vscode
54
.idea
@@ -12,3 +11,4 @@ coverage.xml
1211
site
1312
*.db
1413
.cache
14+
.venv*

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414
- id: end-of-file-fixer
1515
- id: trailing-whitespace
1616
- repo: https://github.com/astral-sh/ruff-pre-commit
17-
rev: v0.5.2
17+
rev: v0.6.2
1818
hooks:
1919
- id: ruff
2020
args:

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ As **SQLModel** is based on **Pydantic** and **SQLAlchemy**, it requires them. T
6565

6666
## Installation
6767

68+
Make sure you create a <a href="https://sqlmodel.tiangolo.com/virtual-environments/" class="external-link" target="_blank">virtual environment</a>, activate it, and then install SQLModel, for example with:
69+
6870
<div class="termy">
6971

7072
```console

docs/contributing.md

Lines changed: 87 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,43 @@ First, you might want to see the basic ways to [help SQLModel and get help](help
44

55
## Developing
66

7-
If you already cloned the repository and you know that you need to deep dive in the code, here are some guidelines to set up your environment.
7+
If you already cloned the <a href="https://github.com/fastapi/sqlmodel" class="external-link" target="_blank">sqlmodel repository</a> and you want to deep dive in the code, here are some guidelines to set up your environment.
88

9-
### Poetry
9+
### Virtual Environment
1010

11-
**SQLModel** uses <a href="https://python-poetry.org/" class="external-link" target="_blank">Poetry</a> to build, package, and publish the project.
11+
Follow the instructions to create and activate a [virtual environment](virtual-environments.md){.internal-link target=_blank} for the internal code of `sqlmodel`.
1212

13-
You can learn how to install it in the <a href="https://python-poetry.org/docs/#installation" class="external-link" target="_blank">Poetry docs</a>.
13+
### Install Requirements Using `pip`
1414

15-
After having Poetry available, you can install the development dependencies:
15+
After activating the environment, install the required packages:
1616

1717
<div class="termy">
1818

1919
```console
20-
$ poetry install
20+
$ pip install -r requirements.txt
2121

2222
---> 100%
2323
```
2424

2525
</div>
2626

27-
It will also create a virtual environment automatically and will install all the dependencies and your local SQLModel in it.
27+
It will install all the dependencies and your local SQLModel in your local environment.
2828

29-
### Poetry Shell
29+
### Using your Local SQLModel
3030

31-
To use your current environment, and to have access to all the tools in it (for example `pytest` for the tests) enter into a Poetry Shell:
31+
If you create a Python file that imports and uses SQLModel, and run it with the Python from your local environment, it will use your cloned local SQLModel source code.
3232

33-
<div class="termy">
34-
35-
```console
36-
$ poetry shell
37-
```
33+
And if you update that local SQLModel source code when you run that Python file again, it will use the fresh version of SQLModel you just edited.
3834

39-
</div>
40-
41-
That will set up the environment variables needed and start a new shell with them.
35+
That way, you don't have to "install" your local version to be able to test every change.
4236

43-
#### Using your local SQLModel
37+
/// note | "Technical Details"
4438

45-
If you create a Python file that imports and uses SQLModel, and run it with the Python from your local Poetry environment, it will use your local SQLModel source code.
39+
This only happens when you install using this included `requirements.txt` instead of running `pip install sqlmodel` directly.
4640

47-
And if you update that local SQLModel source code, when you run that Python file again, it will use the fresh version of SQLModel you just edited.
41+
That is because inside the `requirements.txt` file, the local version of SQLModel is marked to be installed in "editable" mode, with the `-e` option.
4842

49-
Poetry takes care of making that work. But of course, it will only work in the current Poetry environment, if you install standard SQLModel in another environment (not from the source in the GitHub repo), that will use the standard SQLModel, not your custom version.
43+
///
5044

5145
### Format
5246

@@ -62,41 +56,36 @@ $ bash scripts/format.sh
6256

6357
It will also auto-sort all your imports.
6458

65-
## Docs
66-
67-
The documentation uses <a href="https://www.mkdocs.org/" class="external-link" target="_blank">MkDocs</a> with <a href="https://squidfunk.github.io/mkdocs-material/" class="external-link" target="_blank">Material for MkDocs</a>.
68-
69-
All the documentation is in Markdown format in the directory `./docs`.
59+
## Tests
7060

71-
Many of the tutorials have blocks of code.
61+
There is a script that you can run locally to test all the code and generate coverage reports in HTML:
7262

73-
In most of the cases, these blocks of code are actual complete applications that can be run as is.
63+
<div class="termy">
7464

75-
In fact, those blocks of code are not written inside the Markdown, they are Python files in the `./docs_src/` directory.
65+
```console
66+
$ bash scripts/test-cov-html.sh
67+
```
7668

77-
And those Python files are included/injected in the documentation when generating the site.
69+
</div>
7870

79-
### Docs for tests
71+
This command generates a directory `./htmlcov/`, if you open the file `./htmlcov/index.html` in your browser, you can explore interactively the regions of code that are covered by the tests, and notice if there is any region missing.
8072

81-
Most of the tests actually run against the example source files in the documentation.
73+
## Docs
8274

83-
This helps making sure that:
75+
First, make sure you set up your environment as described above, that will install all the requirements.
8476

85-
* The documentation is up to date.
86-
* The documentation examples can be run as is.
87-
* Most of the features are covered by the documentation, ensured by test coverage.
77+
### Docs Live
8878

8979
During local development, there is a script that builds the site and checks for any changes, live-reloading:
9080

9181
<div class="termy">
9282

9383
```console
94-
$ bash scripts/docs-live.sh
84+
$ python ./scripts/docs.py live
9585

96-
<span style="color: green;">[INFO]</span> - Building documentation...
97-
<span style="color: green;">[INFO]</span> - Cleaning site directory
98-
<span style="color: green;">[INFO]</span> - Documentation built in 2.74 seconds
99-
<span style="color: green;">[INFO]</span> - Serving on http://127.0.0.1:8008
86+
<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008
87+
<span style="color: green;">[INFO]</span> Start watching changes
88+
<span style="color: green;">[INFO]</span> Start detecting changes
10089
```
10190

10291
</div>
@@ -105,20 +94,71 @@ It will serve the documentation on `http://127.0.0.1:8008`.
10594

10695
That way, you can edit the documentation/source files and see the changes live.
10796

108-
## Tests
97+
/// tip
10998

110-
There is a script that you can run locally to test all the code and generate coverage reports in HTML:
99+
Alternatively, you can perform the same steps that scripts does manually.
100+
101+
Go into the docs director at `docs/`:
102+
103+
```console
104+
$ cd docs/
105+
```
106+
107+
Then run `mkdocs` in that directory:
108+
109+
```console
110+
$ mkdocs serve --dev-addr 8008
111+
```
112+
113+
///
114+
115+
#### Typer CLI (Optional)
116+
117+
The instructions here show you how to use the script at `./scripts/docs.py` with the `python` program directly.
118+
119+
But you can also use <a href="https://typer.tiangolo.com/typer-cli/" class="external-link" target="_blank">Typer CLI</a>, and you will get autocompletion in your terminal for the commands after installing completion.
120+
121+
If you install Typer CLI, you can install completion with:
111122

112123
<div class="termy">
113124

114125
```console
115-
$ bash scripts/test.sh
126+
$ typer --install-completion
127+
128+
zsh completion installed in /home/user/.bashrc.
129+
Completion will take effect once you restart the terminal.
116130
```
117131

118132
</div>
119133

120-
This command generates a directory `./htmlcov/`, if you open the file `./htmlcov/index.html` in your browser, you can explore interactively the regions of code that are covered by the tests, and notice if there is any region missing.
134+
### Docs Structure
135+
136+
The documentation uses <a href="https://www.mkdocs.org/" class="external-link" target="_blank">MkDocs</a>.
121137

122-
## Thanks
138+
And there are extra tools/scripts in place in `./scripts/docs.py`.
123139

124-
Thanks for contributing! ☕
140+
/// tip
141+
142+
You don't need to see the code in `./scripts/docs.py`, you just use it in the command line.
143+
144+
///
145+
146+
All the documentation is in Markdown format in the directory `./docs`.
147+
148+
Many of the tutorials have blocks of code.
149+
150+
In most of the cases, these blocks of code are actual complete applications that can be run as is.
151+
152+
In fact, those blocks of code are not written inside the Markdown, they are Python files in the `./docs_src/` directory.
153+
154+
And those Python files are included/injected in the documentation when generating the site.
155+
156+
### Docs for Tests
157+
158+
Most of the tests actually run against the example source files in the documentation.
159+
160+
This helps to make sure that:
161+
162+
* The documentation is up-to-date.
163+
* The documentation examples can be run as is.
164+
* Most of the features are covered by the documentation, ensured by test coverage.

docs/databases.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Are you a seasoned developer and already know everything about databases? 🤓
66

7-
Then you can skip to the [Tutorial - User Guide: First Steps](tutorial/index.md){.internal-link target=_blank} right away.
7+
Then you can skip to the next sections right away.
88

99
///
1010

0 commit comments

Comments
 (0)