Skip to content

Commit adca2ed

Browse files
authored
Merge pull request #171 from thomaxxl/chore/dependency-upgrade-latest
Chore/dependency upgrade latest
2 parents 8a6d634 + 9e5ba91 commit adca2ed

File tree

21 files changed

+282
-41
lines changed

21 files changed

+282
-41
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,28 @@ __A [LIVE DEMO](https://thomaxxl.pythonanywhere.com) is available__, where much
5151

5252
SAFRS can be installed as a [pip package](https://pypi.python.org/pypi/safrs/) or by downloading the latest version from github, for example:
5353

54+
```bash
55+
pip install "safrs[all]"
56+
```
57+
58+
To install only the FastAPI adapter stack:
59+
60+
```bash
61+
pip install "safrs[fastapi]"
62+
```
63+
64+
To install only the Flask adapter stack:
65+
66+
```bash
67+
pip install "safrs[flask]"
68+
```
69+
70+
From source:
71+
5472
```bash
5573
git clone https://github.com/thomaxxl/safrs
5674
cd safrs
57-
pip install .
75+
pip install ".[all]"
5876
```
5977

6078
Once the dependencies are installed, the [examples](examples) can be started, for example

README.rst

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,29 @@ Installation
1717

1818
SAFRS can be installed as a `pip package <https://pypi.python.org/pypi/safrs/>`_ or by downloading the latest version from github, for example:
1919

20+
.. code-block:: bash
21+
22+
pip install "safrs[all]"
23+
24+
FastAPI adapter only:
25+
26+
.. code-block:: bash
27+
28+
pip install "safrs[fastapi]"
29+
30+
Flask adapter only:
31+
32+
.. code-block:: bash
33+
34+
pip install "safrs[flask]"
35+
36+
From source:
37+
2038
.. code-block:: bash
2139
2240
git clone https://github.com/thomaxxl/safrs
2341
cd safrs
24-
pip3 install -r requirements.txt --user
25-
python3 setup.py install --user
42+
pip install ".[all]"
2643
2744
2845
The examples can then be started with
@@ -31,4 +48,3 @@ The examples can then be started with
3148
3249
python3 examples/demo_relationship.py "your-interface-ip"
3350
34-

examples/docker_fastapi_demo/backend/src/northwind_backend/fastapi_app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def create_fastapi_app() -> FastAPI:
2121
title="Northwind SAFRS FastAPI Validation App",
2222
docs_url=None,
2323
redoc_url=None,
24-
openapi_url="/jsonapi.json",
24+
openapi_url="/openapi.json",
2525
)
2626
app.add_middleware(
2727
CORSMiddleware,
@@ -56,7 +56,7 @@ def index() -> RedirectResponse:
5656
@app.get("/docs", include_in_schema=False)
5757
def docs() -> object:
5858
docs_kwargs: dict[str, object] = {
59-
"openapi_url": app.openapi_url or "/jsonapi.json",
59+
"openapi_url": app.openapi_url or "/openapi.json",
6060
"title": f"{app.title} - Swagger UI",
6161
"swagger_ui_parameters": app.swagger_ui_parameters,
6262
}
@@ -83,8 +83,8 @@ def healthz() -> dict[str, object]:
8383
def admin_yaml() -> FileResponse:
8484
return FileResponse(settings.admin_yaml_path, media_type="text/yaml")
8585

86-
@app.get(f"{settings.api_prefix}/jsonapi.json", include_in_schema=False)
87-
def jsonapi_json_alias() -> dict[str, object]:
86+
@app.get(f"{settings.api_prefix}/openapi.json", include_in_schema=False)
87+
def openapi_json_alias() -> dict[str, object]:
8888
return app.openapi()
8989

9090
@app.get(f"{settings.api_prefix}/swagger.json", include_in_schema=False)

examples/docker_fastapi_demo/examples/_shared_fastapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def create_example_app(
3838

3939
api_prefix = f"{example_prefix}/api"
4040
docs_path = f"{example_prefix}/docs"
41-
openapi_path = f"{example_prefix}/jsonapi.json"
41+
openapi_path = f"{example_prefix}/openapi.json"
4242
swagger_alias = f"{example_prefix}/swagger.json"
4343

4444
app = FastAPI(

examples/docker_fastapi_demo/examples/authentication/demo_jwt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
EXAMPLE_PREFIX = "/api_demo_jwt"
2222
API_PREFIX = f"{EXAMPLE_PREFIX}/api"
2323
DOCS_PATH = f"{EXAMPLE_PREFIX}/docs"
24-
OPENAPI_PATH = f"{EXAMPLE_PREFIX}/jsonapi.json"
24+
OPENAPI_PATH = f"{EXAMPLE_PREFIX}/openapi.json"
2525
SWAGGER_ALIAS = f"{EXAMPLE_PREFIX}/swagger.json"
2626
LOGIN_PATH = f"{EXAMPLE_PREFIX}/login"
2727

examples/docker_fastapi_demo/nginx.conf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ server {
4545
proxy_set_header X-Forwarded-Proto $scheme;
4646
}
4747

48-
location /jsonapi.json {
49-
proxy_pass http://127.0.0.1:5656;
50-
proxy_set_header Host $host;
51-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
52-
proxy_set_header X-Forwarded-Proto $scheme;
53-
}
54-
5548
location /swagger.json {
5649
proxy_pass http://127.0.0.1:5656;
5750
proxy_set_header Host $host;

examples/fastapi_nw

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
docker_fastapi_demo/backend

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ classifiers = [ # Optional
3636
"Programming Language :: Python :: 3 :: Only",
3737
]
3838

39-
dependencies = [ "Flask-SQLAlchemy>=3.1.1", "flask_swagger_ui>=5.21.0", "flask-restful-swagger-2>=0.35", "PyYaml>=6.0.3" ]
39+
dependencies = [ "Flask>=3.1.3", "Flask-SQLAlchemy>=3.1.1", "PyYAML>=6.0.3", "SQLAlchemy>=2.0.48" ]
4040

4141
[project.optional-dependencies] # Optional
42-
dev = ["flask_cors>=6.0.2"]
43-
test = ["flask_cors>=6.0.2"]
42+
flask = ["Flask-RESTful>=0.3.10", "flask-restful-swagger-2>=0.35", "flask-swagger-ui>=5.21.0", "Flask-Cors>=6.0.2"]
43+
fastapi = ["fastapi[standard]>=0.135.1"]
44+
all = ["Flask-RESTful>=0.3.10", "flask-restful-swagger-2>=0.35", "flask-swagger-ui>=5.21.0", "Flask-Cors>=6.0.2", "fastapi[standard]>=0.135.1"]
45+
dev = ["Flask-RESTful>=0.3.10", "flask-restful-swagger-2>=0.35", "flask-swagger-ui>=5.21.0", "Flask-Cors>=6.0.2", "fastapi[standard]>=0.135.1"]
46+
test = ["Flask-RESTful>=0.3.10", "flask-restful-swagger-2>=0.35", "flask-swagger-ui>=5.21.0", "Flask-Cors>=6.0.2", "fastapi[standard]>=0.135.1"]
4447

4548
[project.urls] # Optional
4649
"Homepage" = "https://github.com/thomaxxl/safrs"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ typing-extensions>=4.15.0
2323
Werkzeug>=3.1.6
2424
zipp>=3.23.0
2525
fastapi[standard]
26+
flask-cors==6.0.2

safrs/__init__.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,41 @@
33
# The code implements some seemingly awkward constructs and redundant functionality
44
# This is however required for backwards compatibility, we'll get rid of it eventually
55
#
6+
from typing import Any
7+
68
from .safrs_init import DB, log, SAFRS, dict_merge, test_decorator, SAFRSRequest
79
from .errors import ValidationError, GenericError, IntegerOverflowError, UnAuthorizedError, NotFoundError
810
from .json_encoder import DefaultJSONProvider, SAFRSFormattedResponse
9-
from .safrs_api import SAFRSAPI
1011
from .base import SAFRSBase
1112
from .jabase import JABase
1213
from .jsonapi_attr import jsonapi_attr
13-
from .jsonapi import jsonapi_format_response, paginate
14+
from .jsonapi_formatting import jsonapi_format_response, paginate
1415
from .api_methods import search, startswith
15-
from .swagger_doc import jsonapi_rpc
16+
from .api_doc import jsonapi_rpc
1617
from . import tx
1718
from .__about__ import __version__, __description__
1819

20+
_MISSING_FLASK_ADAPTER_DEPS = {"flask_restful", "flask_restful_swagger_2", "flask_swagger_ui"}
21+
22+
23+
def _raise_missing_flask_adapter_error(exc: ModuleNotFoundError) -> None:
24+
raise ModuleNotFoundError(
25+
"Flask adapter dependencies are not installed. Install them with "
26+
"`pip install \"safrs[flask]\"`."
27+
) from exc
28+
29+
30+
try:
31+
from .safrs_api import SAFRSAPI
32+
except ModuleNotFoundError as exc:
33+
if exc.name not in _MISSING_FLASK_ADAPTER_DEPS:
34+
raise
35+
36+
class SAFRSAPI: # type: ignore[no-redef]
37+
def __init__(self, *_args: Any, **_kwargs: Any) -> None:
38+
_raise_missing_flask_adapter_error(exc)
39+
40+
1941
SafrsApi = SAFRSAPI
2042

2143
__all__ = (

0 commit comments

Comments
 (0)