diff --git a/docs/why.rst b/docs/why.rst index 659f26f..6fddac8 100644 --- a/docs/why.rst +++ b/docs/why.rst @@ -8,7 +8,7 @@ There are number of packages out there that solve a similar problem. Here are ju * `flask-apispec `_ * `Flasgger `_ -These are all great projects, and one might work better for your use case. Flask-Rebar solves a similar problem with its own its own twist on the approach: +These are all great projects, and one might work better for your use case. Flask-Rebar solves a similar problem with its own twist on the approach: Marshmallow for validation *and* marshaling ------------------------------------------- @@ -23,7 +23,7 @@ Swagger as a side effect Some approaches generate code *from* a Swagger specification, or generate Swagger from docstrings. Flask-Rebar aims to make Swagger (a.k.a. OpenAPI) a byproduct of writing application code with Marshmallow and Flask. -This is really nice if you prefer the rich validation/transformation functionality of Marshmallow over Swagger's limited. +This is really nice if you prefer the rich validation/transformation functionality of Marshmallow over Swagger's more limited set. It also alleviates the need to manually keep an API's documentation in sync with the actual application code - the schemas used by the application are the same schemas used to generate Swagger. diff --git a/flask_rebar/rebar.py b/flask_rebar/rebar.py index c5a4acd..dfaf46f 100644 --- a/flask_rebar/rebar.py +++ b/flask_rebar/rebar.py @@ -32,7 +32,12 @@ TypeVar, Union, ) -from typing_extensions import ParamSpec + +if sys.version_info >= (3, 10): + from typing import ParamSpec +else: + from typing_extensions import ParamSpec + from werkzeug.datastructures import Headers from werkzeug.exceptions import HTTPException from werkzeug.routing import RequestRedirect diff --git a/flask_rebar/swagger_generation/marshmallow_to_swagger.py b/flask_rebar/swagger_generation/marshmallow_to_swagger.py index bcf751f..6c3c55c 100644 --- a/flask_rebar/swagger_generation/marshmallow_to_swagger.py +++ b/flask_rebar/swagger_generation/marshmallow_to_swagger.py @@ -27,7 +27,12 @@ TypeVar, Union, ) -from typing_extensions import ParamSpec + +if sys.version_info >= (3, 10): + from typing import ParamSpec +else: + from typing_extensions import ParamSpec + import marshmallow as m from marshmallow import Schema from marshmallow.validate import Range diff --git a/flask_rebar/utils/deprecation.py b/flask_rebar/utils/deprecation.py index 92dfc1e..565634f 100644 --- a/flask_rebar/utils/deprecation.py +++ b/flask_rebar/utils/deprecation.py @@ -9,9 +9,14 @@ """ from __future__ import annotations import functools +import sys import warnings from typing import Any, Callable, Dict, NamedTuple, Optional, Tuple, TypeVar, Union -from typing_extensions import ParamSpec + +if sys.version_info >= (3, 10): + from typing import ParamSpec +else: + from typing_extensions import ParamSpec from werkzeug.local import LocalProxy as module_property # noqa diff --git a/setup.py b/setup.py index 9926389..5a8a9ad 100644 --- a/setup.py +++ b/setup.py @@ -22,6 +22,13 @@ "types-setuptools==68.0.0.3", ] +install_requires = [ + "Flask>=1.0,<4", + "marshmallow>=3.0,<4", + "typing-extensions>=4.8,<5;python_version<'3.10'", + "Werkzeug>=2.2,<4", +] + if __name__ == "__main__": setup( name="flask-rebar", @@ -36,7 +43,7 @@ package_data={"flask_rebar": ["py.typed"]}, include_package_data=True, extras_require={"dev": development, "enum": ["marshmallow-enum~=1.5"]}, - install_requires=["Flask>=1.0,<4", "marshmallow>=3.0,<4"], + install_requires=install_requires, url="https://github.com/plangrid/flask-rebar", classifiers=[ "Environment :: Web Environment", diff --git a/tests/test_validation.py b/tests/test_validation.py index 8715f84..53e1b2e 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -8,10 +8,10 @@ :license: MIT, see LICENSE for details. """ from datetime import datetime +from importlib.metadata import version from unittest import TestCase from pytest import mark -from marshmallow import __version_info__ as MARSHMALLOW_VERSION from marshmallow import Schema from marshmallow import ValidationError from marshmallow import fields @@ -26,6 +26,8 @@ from flask_rebar.validation import QueryParamList from tests.test_rebar import create_rebar_app +MARSHMALLOW_VERSION = tuple(int(x) for x in version("marshmallow").split(".")) + class NoRequireOnDumpMixinSchema(Schema): optional = fields.Str()