Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 4.2.0 #42

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/git_toolbox_blame.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Types of changes are:

## [Unreleased]

## [4.2.0] - 2024-08-13

### Features

- Removed dependency on `typer` in favour of plain `click`. It is not as pretty, but it is more stable and easier to maintain.

## [4.1.0] - 2024-08-13

### Features
Expand Down Expand Up @@ -224,7 +230,8 @@ Add classifiers to the package.

- Initial release

[Unreleased]: https://github.com/radeklat/settings-doc/compare/4.1.0...HEAD
[Unreleased]: https://github.com/radeklat/settings-doc/compare/4.2.0...HEAD
[4.2.0]: https://github.com/radeklat/settings-doc/compare/4.1.0...4.2.0
[4.1.0]: https://github.com/radeklat/settings-doc/compare/4.0.1...4.1.0
[4.0.1]: https://github.com/radeklat/settings-doc/compare/4.0.0...4.0.1
[4.0.0]: https://github.com/radeklat/settings-doc/compare/3.1.2...4.0.0
Expand Down
1,028 changes: 482 additions & 546 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "settings-doc"
version = "4.1.0"
version = "4.2.0"
description = "A command line tool for generating Markdown documentation and .env files from pydantic BaseSettings."
authors = ["Radek Lát <[email protected]>"]
license = "MIT License"
Expand Down Expand Up @@ -39,11 +39,10 @@ settings-doc = "settings_doc.main:app"
python = "^3.8.1"
Jinja2 = "^3.0.2"
pydantic = "^2.3"
typer = {version = "^0.9", extras = ["all"]} # https://typer.tiangolo.com/release-notes/
pydantic-settings = "^2.0.3"
click = "^8.0"

[tool.poetry.dev-dependencies]
click = "^8.0.3"
types-toml = "*"
delfino-core = {extras = ["verify", "dependencies-update"], version = "^7.0"} # https://github.com/radeklat/delfino-core/blob/main/CHANGELOG.md
pytest-mock = "^3.6.1"
Expand Down
23 changes: 13 additions & 10 deletions src/settings_doc/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
from inspect import isclass
from typing import Dict, List, Tuple, Type

from click import BadParameter, secho
import click
from pydantic_settings import BaseSettings
from typer import colors

_MODULE_ERROR_MSG = "No `pydantic.BaseSettings` subclasses found in module '{module_path}'."
_RELATIVE_IMPORT_ERROR_MSG = "Relative imports are not supported."
Expand All @@ -25,7 +24,7 @@ def import_module_path(module_paths: Tuple[str, ...]) -> Dict[Type[BaseSettings]
cause = str(exc)
if isinstance(exc, TypeError) and "relative import" in cause:
cause = _RELATIVE_IMPORT_ERROR_MSG
raise BadParameter(f"Cannot read the module: {cause}") from exc
raise click.BadParameter(f"Cannot read the module: {cause}") from exc

new_classes: Dict[Type[BaseSettings], None] = {
obj: None
Expand All @@ -35,12 +34,12 @@ def import_module_path(module_paths: Tuple[str, ...]) -> Dict[Type[BaseSettings]

if not new_classes:
if len(module_paths) > 1:
secho(_MODULE_ERROR_MSG.format(module_path=module_path), fg=colors.YELLOW, err=True)
click.secho(_MODULE_ERROR_MSG.format(module_path=module_path), fg="yellow", err=True)
else:
settings.update(new_classes)

if not settings:
raise BadParameter(
raise click.BadParameter(
_MODULE_ERROR_MSG.format(module_path=module_paths[0])
if len(module_paths) == 1
else "No `pydantic.BaseSettings` subclasses found in any of the modules."
Expand All @@ -61,24 +60,28 @@ def import_class_path(class_paths: Tuple[str, ...]) -> Dict[Type[BaseSettings],
cause = str(exc)
if isinstance(exc, TypeError) and "relative import" in cause:
cause = _RELATIVE_IMPORT_ERROR_MSG
raise BadParameter(f"Cannot read the settings class: {cause}") from exc
raise click.BadParameter(f"Cannot read the settings class: {cause}") from exc

if not isclass(new_class):
raise BadParameter(f"Target '{class_name}' in module '{module}' is not a class.")
raise click.BadParameter(f"Target '{class_name}' in module '{module}' is not a class.")

if not issubclass(new_class, BaseSettings):
raise BadParameter(f"Target class must be a subclass of BaseSettings but '{new_class.__name__}' found.")
raise click.BadParameter(
f"Target class must be a subclass of BaseSettings but '{new_class.__name__}' found."
)

settings[new_class] = None

return settings


def module_path_callback(value: List[str]) -> List[str]:
def module_path_callback(ctx: click.Context, param: click.Parameter, value: List[str]) -> List[str]:
del ctx, param
import_module_path(tuple(value))
return value


def class_path_callback(value: List[str]) -> List[str]:
def class_path_callback(ctx: click.Context, param: click.Parameter, value: List[str]) -> List[str]:
del ctx, param
import_class_path(tuple(value))
return value
Loading
Loading