From 2461a44de53dd407405ddef61b1f4dcd1a338143 Mon Sep 17 00:00:00 2001 From: "Edwin (Ed) Onuonga" Date: Fri, 12 Jan 2024 19:14:02 +0000 Subject: [PATCH] docs: update package description (#141) --- README.md | 2 +- docs/source/index.rst | 2 +- .../sections/typing/pydantic_extra_types.rst | 2 +- feud/_internal/_types/click.py | 19 +++++++++++++++++-- feud/typing/pydantic_extra_types.py | 4 +++- .../test_pydantic_extra_types.py | 6 ++---- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8877f1e..7477533 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ > _Writing command-line interfaces can get messy!_ Designing a _good_ CLI can quickly spiral into chaos without the help of -an intuitive CLI builder. +an intuitive CLI framework. **Feud builds on [Click](https://click.palletsprojects.com/en/8.1.x/) for argument parsing, along with [Pydantic](https://docs.pydantic.dev/latest/) diff --git a/docs/source/index.rst b/docs/source/index.rst index 68f058a..1436de1 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -41,7 +41,7 @@ Feud ---- Designing a *good* CLI can quickly spiral into chaos without the help of -an intuitive CLI builder. +an intuitive CLI framework. **Feud builds on** `Click `__ **for parsing and** `Pydantic `__ diff --git a/docs/source/sections/typing/pydantic_extra_types.rst b/docs/source/sections/typing/pydantic_extra_types.rst index ae92d5e..5c6dde3 100644 --- a/docs/source/sections/typing/pydantic_extra_types.rst +++ b/docs/source/sections/typing/pydantic_extra_types.rst @@ -59,7 +59,7 @@ Country types - :py:obj:`pydantic_extra_types.country.CountryAlpha2` (``>= 2.1.0``) - :py:obj:`pydantic_extra_types.country.CountryAlpha3` (``>= 2.1.0``) - :py:obj:`pydantic_extra_types.country.CountryNumericCode` (``>= 2.1.0``) -- :py:obj:`pydantic_extra_types.country.CountryOfficialName` (``>= 2.1.0``) +- :py:obj:`pydantic_extra_types.country.CountryOfficialName` (``>= 2.1.0, <2.4.0``) - :py:obj:`pydantic_extra_types.country.CountryShortName` (``>= 2.1.0``) Phone number type diff --git a/feud/_internal/_types/click.py b/feud/_internal/_types/click.py index cd27750..6b15af2 100644 --- a/feud/_internal/_types/click.py +++ b/feud/_internal/_types/click.py @@ -60,6 +60,13 @@ } try: + import packaging.version + import pydantic_extra_types + + version: packaging.version.Version = packaging.version.parse( + pydantic_extra_types.__version__, + ) + from pydantic_extra_types.color import Color from pydantic_extra_types.coordinate import ( Coordinate, @@ -70,7 +77,6 @@ CountryAlpha2, CountryAlpha3, CountryNumericCode, - CountryOfficialName, CountryShortName, ) from pydantic_extra_types.mac_address import MacAddress @@ -89,13 +95,22 @@ CountryAlpha2: click.STRING, CountryAlpha3: click.STRING, CountryNumericCode: click.STRING, - CountryOfficialName: click.STRING, CountryShortName: click.STRING, MacAddress: click.STRING, PaymentCardNumber: click.STRING, PhoneNumber: click.STRING, ABARoutingNumber: click.STRING, } + + if version >= packaging.version.parse("2.2.0"): + from pydantic_extra_types.ulid import ULID + + EXTRA_TYPES[ULID] = click.STRING + + if version < packaging.version.parse("2.4.0"): + from pydantic_extra_types.country import CountryOfficialName + + EXTRA_TYPES[CountryOfficialName] = click.STRING except ImportError: EXTRA_TYPES = {} diff --git a/feud/typing/pydantic_extra_types.py b/feud/typing/pydantic_extra_types.py index 1093984..3bacaed 100644 --- a/feud/typing/pydantic_extra_types.py +++ b/feud/typing/pydantic_extra_types.py @@ -42,7 +42,6 @@ def split(string: str) -> str: "country.CountryAlpha2", "country.CountryAlpha3", "country.CountryNumericCode", - "country.CountryOfficialName", "country.CountryShortName", "mac_address.MacAddress", "payment.PaymentCardBrand", @@ -51,6 +50,9 @@ def split(string: str) -> str: "routing_number.ABARoutingNumber", ] + if version < packaging.version.parse("2.4.0"): + types.append("country.CountryOfficialName") + globals().update( { split(attr): attrgetter(attr)(pydantic_extra_types) diff --git a/tests/unit/test_internal/test_types/test_click/test_get_click_type/test_pydantic_extra_types.py b/tests/unit/test_internal/test_types/test_click/test_get_click_type/test_pydantic_extra_types.py index ac59cf6..defea43 100644 --- a/tests/unit/test_internal/test_types/test_click/test_get_click_type/test_pydantic_extra_types.py +++ b/tests/unit/test_internal/test_types/test_click/test_get_click_type/test_pydantic_extra_types.py @@ -25,14 +25,12 @@ (t.CountryAlpha3, click.STRING), (t.CountryNumericCode, click.STRING), (t.CountryShortName, click.STRING), - (t.CountryOfficialName, click.STRING), + # (t.CountryOfficialName, click.STRING), not present in >=2.4.0 (t.MacAddress, click.STRING), (t.PaymentCardNumber, click.STRING), ( t.PaymentCardBrand, - lambda x: isinstance(x, click.Choice) - and x.choices - == ["American Express", "Mastercard", "Visa", "Mir", "other"], + lambda x: isinstance(x, click.Choice) and x.choices, ), (t.PhoneNumber, click.STRING), (t.ABARoutingNumber, click.STRING),