Skip to content

Commit

Permalink
build: copier-auto-update
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing committed Jul 5, 2024
1 parent a8d349d commit 6c277a0
Show file tree
Hide file tree
Showing 17 changed files with 403 additions and 907 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ repos:
hooks:
- id: mdformat
additional_dependencies:
- "mdformat-mkdocs[recommended]>=2.1.0"
- "mdformat-mkdocs[recommended]>=3.0.0"
- "mdformat-gfm-alerts>=1.0.1"
args: [--wrap=no]
exclude: _.+\.md|CHANGELOG\.md|CODE_TAG_SUMMARY\.md
Expand All @@ -72,20 +72,14 @@ repos:
exclude: \.copier-answers\.yml|tests/.*/cassettes/.*\.yaml|__snapshots__/.*\.json|tests/data/.*/\.ctt/.*\.ya?ml
types_or: [html, javascript, json, shell, yaml]
stages: ["pre-commit"]
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
exclude: tests/.*/cassettes/.*\.yaml
stages: ["pre-commit"]
- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
hooks:
- id: toml-sort-fix
exclude: poetry\.lock
stages: ["pre-commit"]
- repo: https://github.com/KyleKing/calcipy
rev: 3.0.1
rev: 4.0.0rc2
hooks:
- id: copier-forbidden-files
- id: lint-fix
Expand Down
12 changes: 0 additions & 12 deletions .yamllint.yaml

This file was deleted.

50 changes: 3 additions & 47 deletions copier_template_tester/__init__.py
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 ==
56 changes: 56 additions & 0 deletions copier_template_tester/_runtime_type_check_setup.py
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,
)
1 change: 0 additions & 1 deletion docs/docs/Advanced_Documentation.md

This file was deleted.

4 changes: 4 additions & 0 deletions docs/docs/CHANGELOG.md
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
Expand Down
21 changes: 11 additions & 10 deletions docs/docs/DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ poetry config pypi-token.pypi ...
## Current Status

<!-- {cts} COVERAGE -->
| File | Statements | Missing | Excluded | Coverage |
|-------------------------------------------------|--------------|-----------|------------|------------|
| `copier_template_tester/__init__.py` | 16 | 0 | 24 | 100.0% |
| `copier_template_tester/_config.py` | 14 | 0 | 3 | 100.0% |
| `copier_template_tester/_pre_commit_support.py` | 13 | 0 | 0 | 93.3% |
| `copier_template_tester/_write_output.py` | 76 | 0 | 13 | 96.9% |
| `copier_template_tester/main.py` | 30 | 4 | 20 | 86.7% |
| **Totals** | 149 | 4 | 60 | 95.5% |

Generated on: 2024-06-13
| File | Statements | Missing | Excluded | Coverage |
|-------------------------------------------------------|------------|---------|----------|----------|
| `copier_template_tester/__init__.py` | 4 | 0 | 0 | 100.0% |
| `copier_template_tester/_config.py` | 14 | 0 | 3 | 100.0% |
| `copier_template_tester/_pre_commit_support.py` | 13 | 0 | 0 | 93.3% |
| `copier_template_tester/_runtime_type_check_setup.py` | 13 | 0 | 28 | 100.0% |
| `copier_template_tester/_write_output.py` | 76 | 0 | 13 | 96.9% |
| `copier_template_tester/main.py` | 30 | 4 | 20 | 86.7% |
| **Totals** | 150 | 4 | 64 | 95.5% |

Generated on: 2024-07-05
<!-- {cte} -->
42 changes: 27 additions & 15 deletions docs/gen_ref_nav.py
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())
17 changes: 0 additions & 17 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,9 @@ watch:
- copier_template_tester

plugins:
- build_plantuml:
render: server # or "local"
bin_path: /usr/local/bin/plantuml # ignored when render: server
server: http://www.plantuml.com/plantuml # official plantuml server
output_format: svg
diagram_root: docs/diagrams
output_folder: out
input_folder: src
input_extensions: puml
- gen-files:
scripts:
- docs/gen_ref_nav.py
- git-revision-date-localized:
enable_creation_date: true
fallback_to_build_date: true
strict: false
type: date
- literate-nav:
nav_file: SUMMARY.md
- mkdocstrings:
handlers:
python:
Expand All @@ -51,7 +35,6 @@ plugins:
separate_signature: true
show_category_heading: true
- search
- section-index

markdown_extensions:
- abbr
Expand Down
Loading

0 comments on commit 6c277a0

Please sign in to comment.