-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
403 additions
and
907 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# Answer file maintained by Copier for: https://github.com/KyleKing/calcipy_template | ||
# DO NOT MODIFY THIS FILE. Edit by re-running copier and changing responses to the questions | ||
# Check into version control. | ||
_commit: 1.10.6 | ||
_commit: 2.0.1 | ||
_src_path: gh:KyleKing/calcipy_template | ||
author_email: [email protected] | ||
author_name: Kyle King | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,11 @@ | ||
"""copier_template_tester.""" | ||
|
||
from datetime import datetime, timezone | ||
from enum import Enum | ||
from os import getenv | ||
from warnings import filterwarnings | ||
|
||
from beartype import BeartypeConf | ||
from beartype.claw import beartype_this_package | ||
from beartype.roar import BeartypeDecorHintPep585DeprecationWarning | ||
from typing_extensions import Self | ||
from ._runtime_type_check_setup import configure_runtime_type_checking_mode | ||
|
||
__version__ = '2.1.2' | ||
__pkg_name__ = 'copier_template_tester' | ||
|
||
|
||
class _RuntimeTypeCheckingModes(Enum): | ||
"""Supported global runtime type checking modes.""" | ||
|
||
ERROR = 'ERROR' | ||
WARNING = 'WARNING' | ||
OFF = None | ||
|
||
@classmethod | ||
def from_environment(cls) -> Self: # pragma: no cover | ||
"""Return the configured mode.""" | ||
rtc_mode = getenv('RUNTIME_TYPE_CHECKING_MODE') or None | ||
try: | ||
return cls(rtc_mode) | ||
except ValueError: | ||
modes = [_e.value for _e in cls] | ||
msg = f"'RUNTIME_TYPE_CHECKING_MODE={rtc_mode}' is not an allowed mode from {modes}" | ||
raise ValueError(msg) from None | ||
|
||
|
||
def configure_runtime_type_checking_mode() -> None: # pragma: no cover | ||
"""Optionally configure runtime type checking mode globally.""" | ||
rtc_mode = _RuntimeTypeCheckingModes.from_environment() | ||
|
||
if rtc_mode is not _RuntimeTypeCheckingModes.OFF: | ||
from beartype.roar import BeartypeClawDecorWarning # noqa: PLC0415 | ||
|
||
beartype_this_package(conf=BeartypeConf( | ||
warning_cls_on_decorator_exception=( | ||
None if rtc_mode is _RuntimeTypeCheckingModes.ERROR else BeartypeClawDecorWarning | ||
), | ||
)) | ||
|
||
|
||
_PEP585_DATE = 2025 | ||
if datetime.now(tz=timezone.utc).year <= _PEP585_DATE: # pragma: no cover | ||
filterwarnings('ignore', category=BeartypeDecorHintPep585DeprecationWarning) | ||
configure_runtime_type_checking_mode() | ||
|
||
# ====== Above is the recommended code from calcipy_template and may be updated on new releases ====== | ||
|
||
# == Above code must always be first == |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""Configure runtime typechecking conditionally.""" | ||
|
||
from datetime import datetime, timezone | ||
from enum import Enum | ||
from os import getenv | ||
from warnings import filterwarnings | ||
|
||
from beartype import BeartypeConf | ||
from beartype.claw import beartype_this_package | ||
from beartype.roar import BeartypeDecorHintPep585DeprecationWarning | ||
from typing_extensions import Self | ||
|
||
|
||
class _RuntimeTypeCheckingModes(Enum): | ||
"""Supported global runtime type checking modes.""" | ||
|
||
ERROR = 'ERROR' | ||
WARNING = 'WARNING' | ||
OFF = None | ||
|
||
@classmethod | ||
def from_environment(cls) -> Self: # pragma: no cover | ||
"""Return the configured mode.""" | ||
rtc_mode = getenv('RUNTIME_TYPE_CHECKING_MODE') or None | ||
try: | ||
return cls(rtc_mode) | ||
except ValueError: | ||
modes = [_e.value for _e in cls] | ||
msg = f"'RUNTIME_TYPE_CHECKING_MODE={rtc_mode}' is not from {modes}" | ||
raise ValueError(msg) from None | ||
|
||
|
||
def configure_runtime_type_checking_mode() -> None: # pragma: no cover | ||
"""Optionally configure runtime type checking mode globally.""" | ||
rtc_mode = _RuntimeTypeCheckingModes.from_environment() | ||
|
||
if rtc_mode is not _RuntimeTypeCheckingModes.OFF: | ||
from beartype.roar import BeartypeClawDecorWarning # noqa: PLC0415 | ||
|
||
beartype_this_package( | ||
conf=BeartypeConf( | ||
warning_cls_on_decorator_exception=( | ||
None | ||
if rtc_mode is _RuntimeTypeCheckingModes.ERROR | ||
else BeartypeClawDecorWarning | ||
), | ||
), | ||
) | ||
|
||
|
||
_PEP585_DATE = 2025 | ||
if datetime.now(tz=timezone.utc).year <= _PEP585_DATE: # pragma: no cover | ||
filterwarnings( | ||
'ignore', | ||
category=BeartypeDecorHintPep585DeprecationWarning, | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
## Unreleased | ||
|
||
### Fix | ||
|
||
- **wheel**: don't distribute top-level LICENSE file (#33) | ||
|
||
## 2.1.2 (2024-05-02) | ||
|
||
### Fix | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,51 @@ | ||
"""Generate the code reference pages and navigation. | ||
"""Generate the code reference pages. | ||
Copied from: | ||
https://github.com/pawamoy/copier-pdm/blob/79135565c4c7f756204a5f460e87129649f8b704/project/docs/gen_ref_nav.py | ||
Adapted without navigation from: | ||
https://github.com/pawamoy/copier-pdm/blob/adff9b64887d0b4c9ec0b42de1698b34858a511e/project/scripts/gen_ref_nav.py | ||
""" | ||
|
||
from pathlib import Path | ||
|
||
import mkdocs_gen_files | ||
from corallium.tomllib import tomllib | ||
|
||
|
||
def has_public_code(line: str) -> bool: | ||
"""Determine if a given line contains code that will be documented.""" | ||
for key in ('def', 'async def', 'class'): | ||
starts = line.startswith(f'{key} ') | ||
if starts and not line.startswith(f'{key} _'): | ||
return True | ||
if starts: | ||
break | ||
return False | ||
|
||
|
||
_config = tomllib.loads(Path('pyproject.toml').read_text(encoding='utf-8')) | ||
_pkg_name = _config['tool']['poetry']['name'] | ||
src = Path(_pkg_name) | ||
for path in sorted(src.rglob('*.py')): | ||
for line in path.read_text().split('\n'): | ||
if has_public_code(line): | ||
break | ||
else: | ||
continue # Do not include the file in generated documentation | ||
|
||
nav = mkdocs_gen_files.Nav() | ||
|
||
for path in sorted(Path('copier_template_tester').rglob('*.py')): | ||
module_path = path.with_suffix('') | ||
doc_path = path.with_suffix('.md') | ||
full_doc_path = Path('reference', doc_path) | ||
|
||
parts = tuple(module_path.parts) | ||
|
||
if parts[-1] == '__init__': | ||
parts = parts[:-1] | ||
doc_path = doc_path.with_name('index.md') | ||
full_doc_path = full_doc_path.with_name('index.md') | ||
elif parts[-1] == '__main__': | ||
elif parts[-1].startswith('_'): | ||
continue | ||
|
||
nav[parts] = doc_path.as_posix() | ||
|
||
with mkdocs_gen_files.open(full_doc_path, 'w') as fd: | ||
ident = '.'.join(parts) | ||
fd.write(f'::: {ident}') | ||
|
||
mkdocs_gen_files.set_edit_path(full_doc_path, path) | ||
|
||
# FYI, to add pages manually, use: `nav["package", "module"] = "path/to/file.md"` | ||
|
||
with mkdocs_gen_files.open('reference/SUMMARY.md', 'w') as nav_file: | ||
nav_file.writelines(nav.build_literate_nav()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.