Skip to content

Commit

Permalink
docs: update package description (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
eonu committed Jan 12, 2024
1 parent 82f530d commit 2461a44
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://click.palletsprojects.com/en/8.1.x/>`__ **for
parsing and** `Pydantic <https://docs.pydantic.dev/latest/>`__
Expand Down
2 changes: 1 addition & 1 deletion docs/source/sections/typing/pydantic_extra_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 17 additions & 2 deletions feud/_internal/_types/click.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -70,7 +77,6 @@
CountryAlpha2,
CountryAlpha3,
CountryNumericCode,
CountryOfficialName,
CountryShortName,
)
from pydantic_extra_types.mac_address import MacAddress
Expand All @@ -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 = {}

Expand Down
4 changes: 3 additions & 1 deletion feud/typing/pydantic_extra_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def split(string: str) -> str:
"country.CountryAlpha2",
"country.CountryAlpha3",
"country.CountryNumericCode",
"country.CountryOfficialName",
"country.CountryShortName",
"mac_address.MacAddress",
"payment.PaymentCardBrand",
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 2461a44

Please sign in to comment.