diff --git a/HISTORY.md b/HISTORY.md index 2a9f7824..213e5efe 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -10,6 +10,7 @@ - `pathlib.Path` is now supported by default. ([#81](https://github.com/python-attrs/cattrs/issues/81)) - Add `cbor2` serialization library to the `cattr.preconf` package. +- Add optional dependencies for `cattrs.preconf` third-party libraries. ([#337](https://github.com/python-attrs/cattrs/pull/337)) ## 22.2.0 (2022-10-03) diff --git a/docs/preconf.md b/docs/preconf.md index d0e7db2f..945e7642 100644 --- a/docs/preconf.md +++ b/docs/preconf.md @@ -42,6 +42,17 @@ All preconf converters now have `loads` and `dumps` methods, which combine un/st Particular libraries may have additional constraints documented below. +Third-party libraries can be specified as optional (extra) dependencies on `cattrs` during installation. +Optional install targets should match the name of the {mod}`cattrs.preconf` modules. + +```console +# Using pip +pip install cattrs[ujson] + +# Using poetry +poetry add --extras tomlkit cattrs +``` + ## Standard Library _json_ Found at {mod}`cattrs.preconf.json`. diff --git a/poetry.lock b/poetry.lock index 7199c712..71e8b1d7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry and should not be changed by hand. +# This file is automatically @generated by Poetry 1.4.0 and should not be changed by hand. [[package]] name = "alabaster" @@ -106,8 +106,8 @@ uvloop = ["uvloop (>=0.15.2)"] name = "cbor2" version = "5.4.6" description = "CBOR (de)serializer with extensive tag support" -category = "dev" -optional = false +category = "main" +optional = true python-versions = ">=3.7" files = [ {file = "cbor2-5.4.6-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:309fffbb7f561d67f02095d4b9657b73c9220558701c997e9bfcfbca2696e927"}, @@ -286,8 +286,8 @@ files = [ name = "dnspython" version = "2.1.0" description = "DNS toolkit" -category = "dev" -optional = false +category = "main" +optional = true python-versions = ">=3.6" files = [ {file = "dnspython-2.1.0-py3-none-any.whl", hash = "sha256:95d12f6ef0317118d2a1a6fc49aac65ffec7eb8087474158f42f26a639135216"}, @@ -704,8 +704,8 @@ files = [ name = "msgpack" version = "1.0.4" description = "MessagePack serializer" -category = "dev" -optional = false +category = "main" +optional = true python-versions = "*" files = [ {file = "msgpack-1.0.4-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:4ab251d229d10498e9a2f3b1e68ef64cb393394ec477e3370c457f9430ce9250"}, @@ -805,8 +805,8 @@ testing = ["beautifulsoup4", "coverage[toml]", "pytest (>=6,<7)", "pytest-cov", name = "orjson" version = "3.8.5" description = "Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy" -category = "dev" -optional = false +category = "main" +optional = true python-versions = ">=3.7" files = [ {file = "orjson-3.8.5-cp310-cp310-macosx_10_7_x86_64.whl", hash = "sha256:143639b9898b094883481fac37733231da1c2ae3aec78a1dd8d3b58c9c9fceef"}, @@ -1019,8 +1019,8 @@ plugins = ["importlib-metadata"] name = "pymongo" version = "4.3.3" description = "Python driver for MongoDB " -category = "dev" -optional = false +category = "main" +optional = true python-versions = ">=3.7" files = [ {file = "pymongo-4.3.3-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:74731c9e423c93cbe791f60c27030b6af6a948cef67deca079da6cd1bb583a8e"}, @@ -1199,7 +1199,7 @@ files = [ name = "pyyaml" version = "6.0" description = "YAML parser and emitter for Python" -category = "dev" +category = "main" optional = false python-versions = ">=3.6" files = [ @@ -1499,8 +1499,8 @@ files = [ name = "tomlkit" version = "0.11.6" description = "Style preserving TOML library" -category = "dev" -optional = false +category = "main" +optional = true python-versions = ">=3.6" files = [ {file = "tomlkit-0.11.6-py3-none-any.whl", hash = "sha256:07de26b0d8cfc18f871aec595fda24d95b08fef89d147caa861939f37230bf4b"}, @@ -1584,8 +1584,8 @@ files = [ name = "ujson" version = "5.7.0" description = "Ultra fast JSON encoder and decoder for Python" -category = "dev" -optional = false +category = "main" +optional = true python-versions = ">=3.7" files = [ {file = "ujson-5.7.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:5eba5e69e4361ac3a311cf44fa71bc619361b6e0626768a494771aacd1c2f09b"}, @@ -1710,7 +1710,16 @@ files = [ docs = ["furo", "jaraco.packaging (>=9)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] testing = ["flake8 (<5)", "func-timeout", "jaraco.functools", "jaraco.itertools", "more-itertools", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=1.3)", "pytest-flake8", "pytest-mypy (>=0.9.1)"] +[extras] +bson = ["pymongo"] +cbor2 = ["cbor2"] +msgpack = ["msgpack"] +orjson = ["orjson"] +pyyaml = ["PyYAML"] +tomlkit = ["tomlkit"] +ujson = ["ujson"] + [metadata] lock-version = "2.0" python-versions = ">= 3.7" -content-hash = "36e87de5c0e5f5132dd57bb68b48a1b6ab9b4fa174dc921be904fb692e332c77" +content-hash = "dbfdd84b826b04d90a9360116cf5bf568c48e7450ec31847bd748fb2cac7e1c8" diff --git a/pyproject.toml b/pyproject.toml index 45afe235..8f64b1a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,9 +25,24 @@ python = ">= 3.7" attrs = ">= 20" typing_extensions = { version = "*", python = "< 3.8" } exceptiongroup = { version = "*", python = "< 3.11" } +ujson = { version = "^5.4.0", optional = true } +orjson = { version = "^3.5.2", markers = "implementation_name == 'cpython'", optional = true } +msgpack = { version = "^1.0.2", optional = true } +PyYAML = { version = "^6.0", optional = true } +tomlkit = { version = "^0.11.4", python = "<4", optional = true } +cbor2 = { version = "^5.4.6", optional = true } +pymongo = { version = "^4.2.0", optional = true } + +[tool.poetry.extras] +ujson = ["ujson"] +orjson = ["orjson"] +msgpack = ["msgpack"] +pyyaml = ["PyYAML"] +tomlkit = ["tomlkit"] +cbor2 = ["cbor2"] +bson = ["pymongo"] [tool.poetry.group.dev.dependencies] -pymongo = "^4.2.0" flake8 = {version = "^5.0.4", python = "^3.8"} tox = "^3.26.0" Sphinx = "^5.3.0" @@ -38,17 +53,11 @@ pendulum = "^2.1.2" isort = { version = "5.10.1", python = "<4" } black = "^22.8.0" immutables = "^0.18" -ujson = "^5.4.0" -orjson = { version = "^3.5.2", markers = "implementation_name == 'cpython'" } -msgpack = "^1.0.2" -PyYAML = "^6.0" -tomlkit = { version = "^0.11.4", python = "<4" } furo = "^2022.9.29" coverage = "^6.2" urllib3 = { version = "^1.26.12", python = "<4" } sphinx-copybutton = "^0.5.0" myst-parser = "^0.18.1" -cbor2 = "^5.4.6" [tool.poetry.urls] "Changelog" = "https://catt.rs/en/latest/history.html" @@ -77,4 +86,4 @@ build-backend = "poetry.core.masonry.api" [tool.mypy] plugins = "unionize.py" -strict = true \ No newline at end of file +strict = true diff --git a/tox.ini b/tox.ini index 1ff1d541..6a436f57 100644 --- a/tox.ini +++ b/tox.ini @@ -33,7 +33,7 @@ setenv = extras = dev allowlist_externals = poetry commands = - poetry install -v + poetry install -v --all-extras coverage run --source cattrs -m pytest tests {posargs} passenv = CI @@ -44,7 +44,7 @@ setenv = extras = dev allowlist_externals = poetry commands = - poetry install -v + poetry install -v --all-extras coverage run --source cattrs -m pytest tests {posargs} passenv = CI