Skip to content

Commit

Permalink
Merge branch 'main' into update_relationship_attributes_docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alejsdev authored Sep 3, 2024
2 parents e4eebb0 + 6f6f50c commit a12d320
Show file tree
Hide file tree
Showing 29 changed files with 1,442 additions and 320 deletions.
33 changes: 21 additions & 12 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
docs:
- changed-files:
- any-glob-to-any-file:
- docs/**/*
- docs_src/**/*
- all:
- changed-files:
- any-glob-to-any-file:
- docs/**
- docs_src/**
- all-globs-to-all-files:
- '!sqlmodel/**'
- '!pyproject.toml'

internal:
- changed-files:
- any-glob-to-any-file:
- .github/**/*
- scripts/**/*
- .gitignore
- .pre-commit-config.yaml
- pdm_build.py
- requirements*.txt
- all:
- changed-files:
- any-glob-to-any-file:
- .github/**
- scripts/**
- .gitignore
- .pre-commit-config.yaml
- pdm_build.py
- requirements*.txt
- all-globs-to-all-files:
- '!docs/**'
- '!sqlmodel/**'
- '!pyproject.toml'
1 change: 1 addition & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ jobs:
with:
name: docs-site
path: ./site/**
include-hidden-files: true

# https://github.com/marketplace/actions/alls-green#why
docs-all-green: # This job does nothing and is only used for the branch protection
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Pull Request Labeler and Checker
name: Labels
on:
pull_request_target:
types:
Expand All @@ -19,7 +19,10 @@ jobs:
- uses: actions/labeler@v5
# Run this after labeler applied labels
check-labels:
name: Check labels
needs:
- labeler
permissions:
pull-requests: read
runs-on: ubuntu-latest
steps:
- uses: docker://agilepathway/pull-request-label-checker:latest
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/latest-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ jobs:
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }}
with:
limit-access-to-actor: true
- uses: docker://tiangolo/latest-changes:0.2.0
# - uses: tiangolo/latest-changes@main
- uses: tiangolo/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
latest_changes_file: docs/release-notes.md
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ jobs:
with:
name: coverage-${{ matrix.python-version }}-${{ matrix.pydantic-version }}
path: coverage
include-hidden-files: true

coverage-combine:
needs:
- test
Expand All @@ -86,7 +88,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.12'

- name: Get coverage files
uses: actions/download-artifact@v4
Expand All @@ -100,13 +102,14 @@ jobs:
- run: ls -la coverage
- run: coverage combine coverage
- run: coverage report
- run: coverage html --show-contexts --title "Coverage for ${{ github.sha }}"
- run: coverage html --title "Coverage for ${{ github.sha }}"

- name: Store coverage HTML
uses: actions/upload-artifact@v4
with:
name: coverage-html
path: htmlcov
include-hidden-files: true

# https://github.com/marketplace/actions/alls-green#why
alls-green: # This job does nothing and is only used for the branch protection
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*.pyc
env*
.mypy_cache
.vscode
.idea
Expand All @@ -12,3 +11,4 @@ coverage.xml
site
*.db
.cache
.venv*
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.2
rev: v0.6.2
hooks:
- id: ruff
args:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ As **SQLModel** is based on **Pydantic** and **SQLAlchemy**, it requires them. T

## Installation

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:

<div class="termy">

```console
Expand Down
134 changes: 87 additions & 47 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,43 @@ First, you might want to see the basic ways to [help SQLModel and get help](help

## Developing

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.
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.

### Poetry
### Virtual Environment

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

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>.
### Install Requirements Using `pip`

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

<div class="termy">

```console
$ poetry install
$ pip install -r requirements.txt

---> 100%
```

</div>

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

### Poetry Shell
### Using your Local SQLModel

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:
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.

<div class="termy">

```console
$ poetry shell
```
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.

</div>

That will set up the environment variables needed and start a new shell with them.
That way, you don't have to "install" your local version to be able to test every change.

#### Using your local SQLModel
/// note | "Technical Details"

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.
This only happens when you install using this included `requirements.txt` instead of running `pip install sqlmodel` directly.

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.
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.

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.
///

### Format

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

It will also auto-sort all your imports.

## Docs

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>.

All the documentation is in Markdown format in the directory `./docs`.
## Tests

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

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

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

And those Python files are included/injected in the documentation when generating the site.
</div>

### Docs for tests
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.

Most of the tests actually run against the example source files in the documentation.
## Docs

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

* The documentation is up to date.
* The documentation examples can be run as is.
* Most of the features are covered by the documentation, ensured by test coverage.
### Docs Live

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

<div class="termy">

```console
$ bash scripts/docs-live.sh
$ python ./scripts/docs.py live

<span style="color: green;">[INFO]</span> - Building documentation...
<span style="color: green;">[INFO]</span> - Cleaning site directory
<span style="color: green;">[INFO]</span> - Documentation built in 2.74 seconds
<span style="color: green;">[INFO]</span> - Serving on http://127.0.0.1:8008
<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008
<span style="color: green;">[INFO]</span> Start watching changes
<span style="color: green;">[INFO]</span> Start detecting changes
```

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

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

## Tests
/// tip

There is a script that you can run locally to test all the code and generate coverage reports in HTML:
Alternatively, you can perform the same steps that scripts does manually.

Go into the docs director at `docs/`:

```console
$ cd docs/
```

Then run `mkdocs` in that directory:

```console
$ mkdocs serve --dev-addr 8008
```

///

#### Typer CLI (Optional)

The instructions here show you how to use the script at `./scripts/docs.py` with the `python` program directly.

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.

If you install Typer CLI, you can install completion with:

<div class="termy">

```console
$ bash scripts/test.sh
$ typer --install-completion

zsh completion installed in /home/user/.bashrc.
Completion will take effect once you restart the terminal.
```

</div>

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.
### Docs Structure

The documentation uses <a href="https://www.mkdocs.org/" class="external-link" target="_blank">MkDocs</a>.

## Thanks
And there are extra tools/scripts in place in `./scripts/docs.py`.

Thanks for contributing! ☕
/// tip

You don't need to see the code in `./scripts/docs.py`, you just use it in the command line.

///

All the documentation is in Markdown format in the directory `./docs`.

Many of the tutorials have blocks of code.

In most of the cases, these blocks of code are actual complete applications that can be run as is.

In fact, those blocks of code are not written inside the Markdown, they are Python files in the `./docs_src/` directory.

And those Python files are included/injected in the documentation when generating the site.

### Docs for Tests

Most of the tests actually run against the example source files in the documentation.

This helps to make sure that:

* The documentation is up-to-date.
* The documentation examples can be run as is.
* Most of the features are covered by the documentation, ensured by test coverage.
2 changes: 1 addition & 1 deletion docs/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

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

///

Expand Down
Loading

0 comments on commit a12d320

Please sign in to comment.