Skip to content

Commit ffb8965

Browse files
authored
♻️ Update build setup for fastapi-slim, deprecate it, and make it only depend on fastapi (fastapi#14894)
1 parent 93fa935 commit ffb8965

File tree

4 files changed

+101
-13
lines changed

4 files changed

+101
-13
lines changed

.github/workflows/test-redistribute.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ on:
1212
jobs:
1313
test-redistribute:
1414
runs-on: ubuntu-latest
15-
strategy:
16-
matrix:
17-
package:
18-
- fastapi
19-
- fastapi-slim
2015
steps:
2116
- name: Dump GitHub context
2217
env:
@@ -30,8 +25,6 @@ jobs:
3025
- name: Install build dependencies
3126
run: pip install build
3227
- name: Build source distribution
33-
env:
34-
TIANGOLO_BUILD_PACKAGE: ${{ matrix.package }}
3528
run: python -m build --sdist
3629
- name: Decompress source distribution
3730
run: |
@@ -41,8 +34,6 @@ jobs:
4134
run: |
4235
cd dist/fastapi*/
4336
pip install --group tests --editable .[all]
44-
env:
45-
TIANGOLO_BUILD_PACKAGE: ${{ matrix.package }}
4637
- name: Run source distribution tests
4738
run: |
4839
cd dist/fastapi*/

fastapi-slim/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<p align="center">
2+
<a href="https://fastapi.tiangolo.com"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" alt="FastAPI"></a>
3+
</p>
4+
<p align="center">
5+
<em>FastAPI framework, high performance, easy to learn, fast to code, ready for production</em>
6+
</p>
7+
<p align="center">
8+
<a href="https://github.com/fastapi/fastapi/actions?query=workflow%3ATest+event%3Apush+branch%3Amaster" target="_blank">
9+
<img src="https://github.com/fastapi/fastapi/actions/workflows/test.yml/badge.svg?event=push&branch=master" alt="Test">
10+
</a>
11+
<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/fastapi" target="_blank">
12+
<img src="https://coverage-badge.samuelcolvin.workers.dev/fastapi/fastapi.svg" alt="Coverage">
13+
</a>
14+
<a href="https://pypi.org/project/fastapi" target="_blank">
15+
<img src="https://img.shields.io/pypi/v/fastapi?color=%2334D058&label=pypi%20package" alt="Package version">
16+
</a>
17+
<a href="https://pypi.org/project/fastapi" target="_blank">
18+
<img src="https://img.shields.io/pypi/pyversions/fastapi.svg?color=%2334D058" alt="Supported Python versions">
19+
</a>
20+
</p>
21+
22+
---
23+
24+
**Documentation**: <a href="https://fastapi.tiangolo.com" target="_blank">https://fastapi.tiangolo.com</a>
25+
26+
**Source Code**: <a href="https://github.com/fastapi/fastapi" target="_blank">https://github.com/fastapi/fastapi</a>
27+
28+
---
29+
30+
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python based on standard Python type hints.
31+
32+
## `fastapi-slim`
33+
34+
⚠️ Do not install this package. ⚠️
35+
36+
This package, `fastapi-slim`, does nothing other than depend on `fastapi`.
37+
38+
All the functionality has been integrated into `fastapi`.
39+
40+
The only reason this package exists is as a migration path for old projects that used to depend on `fastapi-slim`, so that they can get the latest version of `fastapi`.
41+
42+
You **should not** install this package.
43+
44+
Install instead:
45+
46+
```bash
47+
pip install fastapi
48+
```
49+
50+
This package is deprecated and will stop receiving any updates and published versions.
51+
52+
## License
53+
54+
This project is licensed under the terms of the MIT license.

pdm_build.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,38 @@
33

44
from pdm.backend.hooks import Context
55

6-
TIANGOLO_BUILD_PACKAGE = os.getenv("TIANGOLO_BUILD_PACKAGE", "fastapi")
6+
TIANGOLO_BUILD_PACKAGE = os.getenv("TIANGOLO_BUILD_PACKAGE", "typer")
77

88

99
def pdm_build_initialize(context: Context) -> None:
1010
metadata = context.config.metadata
11+
# Get main version
12+
version = metadata["version"]
1113
# Get custom config for the current package, from the env var
12-
config: dict[str, Any] = context.config.data["tool"]["tiangolo"][
14+
all_configs_config: dict[str, Any] = context.config.data["tool"]["tiangolo"][
1315
"_internal-slim-build"
14-
]["packages"].get(TIANGOLO_BUILD_PACKAGE)
15-
if not config:
16+
]["packages"]
17+
18+
if TIANGOLO_BUILD_PACKAGE not in all_configs_config:
1619
return
20+
21+
config = all_configs_config[TIANGOLO_BUILD_PACKAGE]
1722
project_config: dict[str, Any] = config["project"]
1823
# Override main [project] configs with custom configs for this package
1924
for key, value in project_config.items():
2025
metadata[key] = value
26+
# Get custom build config for the current package
27+
build_config: dict[str, Any] = (
28+
config.get("tool", {}).get("pdm", {}).get("build", {})
29+
)
30+
# Override PDM build config with custom build config for this package
31+
for key, value in build_config.items():
32+
context.config.build_config[key] = value
33+
# Get main dependencies
34+
dependencies: list[str] = metadata.get("dependencies", [])
35+
# Sync versions in dependencies
36+
new_dependencies = []
37+
for dep in dependencies:
38+
new_dep = f"{dep}>={version}"
39+
new_dependencies.append(new_dep)
40+
metadata["dependencies"] = new_dependencies

pyproject.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,29 @@ source-includes = [
202202

203203
[tool.tiangolo._internal-slim-build.packages.fastapi-slim.project]
204204
name = "fastapi-slim"
205+
readme = "fastapi-slim/README.md"
206+
dependencies = [
207+
"fastapi",
208+
]
209+
optional-dependencies = {}
210+
scripts = {}
211+
212+
[tool.tiangolo._internal-slim-build.packages.fastapi-slim.tool.pdm.build]
213+
# excludes needs to explicitly exclude the top level python packages,
214+
# otherwise PDM includes them by default
215+
# A "*" glob pattern can't be used here because in PDM internals, the patterns are put
216+
# in a set (unordered, order varies) and each excluded file is assigned one of the
217+
# glob patterns that matches, as the set is unordered, the matched pattern could be "*"
218+
# independent of the order here. And then the internal code would give it a lower score
219+
# than the one for a default included file.
220+
# By not using "*" and explicitly excluding the top level packages, they get a higher
221+
# score than the default inclusion
222+
excludes = ["fastapi", "tests", "pdm_build.py"]
223+
# source-includes needs to explicitly define some value because PDM will check the
224+
# truthy value of the list, and if empty, will include some defaults, including "tests",
225+
# an empty string doesn't match anything, but makes the list truthy, so that PDM
226+
# doesn't override it during the build.
227+
source-includes = [""]
205228

206229
[tool.mypy]
207230
plugins = ["pydantic.mypy"]

0 commit comments

Comments
 (0)