Skip to content

Commit

Permalink
Merge pull request #133 from KyleKing/poetry-update
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing authored Jun 13, 2024
2 parents e10240d + 35f42fb commit 59c4921
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 56 deletions.
8 changes: 4 additions & 4 deletions .calcipy_packaging.lock
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@
"version": "3.27.0"
},
"corallium": {
"datetime": "2024-06-07T09:07:04.610944+00:00",
"datetime": "2024-06-07T11:56:42.609084+00:00",
"domain": "https://pypi.org/pypi/{name}/json",
"latest_datetime": "2024-06-07T09:07:04.610944+00:00",
"latest_version": "1.0.3",
"latest_datetime": "2024-06-07T11:56:42.609084+00:00",
"latest_version": "2.0.0",
"name": "corallium",
"version": "1.0.3"
"version": "2.0.0"
},
"coverage": {
"datetime": "2024-05-28T14:03:57.019159+00:00",
Expand Down
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.4
_commit: 1.10.6
_src_path: gh:KyleKing/calcipy_template
author_email: [email protected]
author_name: Kyle King
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ repos:
# Note: this version must be the same as the hook revision
- "[email protected]"
- "prettier-plugin-sh"
exclude: \.copier-answers\.yml|tests/.*/cassettes/.*\.yaml
exclude: \.copier-answers\.yml|tests/.*/cassettes/.*\.yaml|__snapshots__/.*\.json
types_or: [html, javascript, json, shell, yaml]
stages: ["pre-commit"]
- repo: https://github.com/adrienverge/yamllint.git
Expand All @@ -85,7 +85,7 @@ repos:
exclude: poetry\.lock
stages: ["pre-commit"]
- repo: https://github.com/KyleKing/calcipy
rev: 2.1.0
rev: 3.0.1
hooks:
- id: copier-forbidden-files
- id: lint-fix
Expand Down
2 changes: 1 addition & 1 deletion calcipy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from beartype.roar import BeartypeDecorHintPep585DeprecationWarning
from typing_extensions import Self

__version__ = '3.0.0'
__version__ = '3.0.1'
__pkg_name__ = 'calcipy'


Expand Down
12 changes: 11 additions & 1 deletion calcipy/tasks/executable_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from pathlib import Path

from beartype import beartype
from beartype.typing import Optional
from invoke.context import Context
from invoke.runners import Result

from calcipy.invoke_helpers import run

Expand Down Expand Up @@ -45,10 +47,18 @@ def python_m() -> str:
See the online documentation for your system: https://microsoft.github.io/pyright/#/installation
"""

_EXECUTABLE_CACHE: dict[str, Optional[Result]] = {}
"""Runtime cache of executables."""


@beartype
def check_installed(ctx: Context, executable: str, message: str) -> None:
"""If the required executable isn't present, raise a clear user error."""
res = run(ctx, f'which {executable}', warn=True, hide=True)
if executable in _EXECUTABLE_CACHE:
res = _EXECUTABLE_CACHE[executable]
else:
res = run(ctx, f'which {executable}', warn=True, hide=True)
_EXECUTABLE_CACHE[executable] = res

if not res or res.exited == 1:
raise RuntimeError(message)
19 changes: 5 additions & 14 deletions calcipy/tasks/types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Types CLI."""

from beartype import beartype
from corallium.file_helpers import read_package_name
from invoke.context import Context

from calcipy.cli import task
Expand All @@ -10,27 +8,20 @@
from .executable_utils import PYRIGHT_MESSAGE, check_installed, python_dir


@beartype
def _inner_task(ctx: Context, *, command: str, cli_args: str = '') -> None:
"""Shared task logic."""
pkg_name = read_package_name()
run(ctx, f'{command} {pkg_name} {cli_args}'.strip())


@task()
def basedpyright(ctx: Context) -> None:
"""Run basedpyright."""
_inner_task(ctx, command=f'{python_dir()}/basedpyright')
"""Run basedpyright using the config in `pyproject.toml`."""
run(ctx, f'{python_dir()}/basedpyright')


@task()
def pyright(ctx: Context) -> None:
"""Run pyright."""
"""Run pyright using the config in `pyproject.toml`."""
check_installed(ctx, executable='pyright', message=PYRIGHT_MESSAGE)
_inner_task(ctx, command='pyright')
run(ctx, 'pyright')


@task()
def mypy(ctx: Context) -> None:
"""Run mypy."""
_inner_task(ctx, command=f'{python_dir()}/mypy')
run(ctx, f'{python_dir()}/mypy')
13 changes: 13 additions & 0 deletions docs/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
## Unreleased

## 3.0.1 (2024-06-12)

### Fix

- don't pass arguments to pyright CLI

### Perf

- cache known executables

## 3.0.0 (2024-06-07)

### Fix

- finish migration from autopep8 to ruff
- resolve remaining ruff errors manually
- use all-caps LOGGER from corallium
- require lock before install-extras
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ poetry config pypi-token.pypi ...
| `calcipy/tasks/cl.py` | 28 | 5 | 0 | 75.0% |
| `calcipy/tasks/defaults.py` | 20 | 0 | 0 | 89.3% |
| `calcipy/tasks/doc.py` | 45 | 0 | 8 | 90.5% |
| `calcipy/tasks/executable_utils.py` | 27 | 0 | 0 | 87.2% |
| `calcipy/tasks/executable_utils.py` | 34 | 0 | 0 | 89.6% |
| `calcipy/tasks/lint.py` | 44 | 2 | 0 | 82.9% |
| `calcipy/tasks/nox.py` | 8 | 0 | 0 | 100.0% |
| `calcipy/tasks/pack.py` | 42 | 11 | 0 | 64.1% |
| `calcipy/tasks/stale.py` | 6 | 0 | 0 | 100.0% |
| `calcipy/tasks/tags.py` | 18 | 1 | 0 | 91.7% |
| `calcipy/tasks/test.py` | 45 | 1 | 2 | 89.2% |
| `calcipy/tasks/types.py` | 20 | 0 | 0 | 89.3% |
| **Totals** | 1019 | 76 | 262 | 86.5% |
| `calcipy/tasks/types.py` | 14 | 0 | 0 | 90.0% |
| **Totals** | 1020 | 76 | 262 | 86.5% |

Generated on: 2024-06-07
Generated on: 2024-06-12
<!-- {cte} -->
8 changes: 4 additions & 4 deletions poetry.lock

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

12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ build-backend = "poetry.core.masonry.api"
requires = ["poetry-core"]

[tool.commitizen]
version = "3.0.0"
version = "3.0.1"
version_files = ["calcipy/__init__.py:^__version", "pyproject.toml:^version"]

[tool.mypy]
check_untyped_defs = true
disallow_any_generics = true
enable_error_code = ["ignore-without-code", "possibly-undefined", "redundant-expr", "truthy-bool"]
extra_checks = true
files = ["calcipy", "tests"]
no_implicit_reexport = true
plugins = [
"pydantic.mypy", # Most settings are from: https://pydantic-docs.helpmanual.io/mypy_plugin
Expand All @@ -20,6 +23,7 @@ strict_equality = true
warn_no_return = true
warn_redundant_casts = true
warn_unreachable = true
warn_unused_configs = true
warn_unused_ignores = true

[tool.poetry]
Expand All @@ -46,7 +50,7 @@ maintainers = []
name = "calcipy"
readme = "docs/README.md"
repository = "https://github.com/kyleking/calcipy"
version = "3.0.0"
version = "3.0.1"

[tool.poetry.dependencies]
python = "^3.9.13"
Expand All @@ -55,7 +59,7 @@ basedpyright = {optional = true, version = ">=1.6.0"} # types
beartype = ">=0.18.2"
bidict = {optional = true, version = ">=0.22.1"} # stale
commitizen = {optional = true, version = ">=3.22.0"} # doc
corallium = ">=1.0.3"
corallium = ">=2.0.0"
griffe = {optional = true, version = ">=0.45.2"} # experimental
httpx = {optional = true, version = ">=0.24.1"} # stale
invoke = ">=2.2.0"
Expand Down Expand Up @@ -169,7 +173,7 @@ init_typed = true
warn_required_dynamic_aliases = true

[tool.pyright]
include = ["calcipy"]
include = ["calcipy", "tests"]
pythonVersion = "3.9"

[tool.ruff]
Expand Down
15 changes: 10 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import pytest
from beartype import beartype
from beartype.typing import Dict
from beartype.typing import Dict, Union
from invoke.context import MockContext

from .configuration import TEST_TMP_CACHE, clear_test_cache


@pytest.fixture(scope='module')
def vcr_config() -> Dict:
def vcr_config() -> Dict[str, Union[str, bool, list[str]]]:
"""Global configuration (https://github.com/kiwicom/pytest-recording) for `pytest-recording` (vcr).
Returns
Expand All @@ -20,8 +20,13 @@ def vcr_config() -> Dict:
"""
return {
# VCR-py configuration
# Docs: https://vcrpy.readthedocs.io/en/latest/advanced.html
'filter_headers': ['authorization'],
'ignore_localhost': True,
'ignore_localhost': False,
# Pytest-Recording CLI Options
'allowed_hosts': '',
'block_network': True,
'record_mode': 'once',
}

Expand All @@ -46,10 +51,10 @@ def ctx() -> MockContext:
Adapted from:
https://github.com/pyinvoke/invocations/blob/8a277c304dd7aaad03888ee42d811c468e7fb37d/tests/conftest.py#L5-L11
https://github.com/pyinvoke/invocations/blob/4e3578e9c49dbbff2ec00ef3c8d37810fba511fa/tests/conftest.py#L13-L19
Documentation: https://docs.pyinvoke.org/en/stable/concepts/testing.html
"""
MockContext.run_command = property(lambda self: self.run.call_args[0][0])
MockContext.run_command = property(lambda self: self.run.call_args[0][0]) # type: ignore[attr-defined]
return MockContext(run=True)
2 changes: 1 addition & 1 deletion tests/noxfile/test_noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def test__installable_dev_dependencies(monkeypatch):
def stubbed_read_pyproject() -> Dict:
def stubbed_read_pyproject() -> Dict: # type: ignore[type-arg]
return {
'tool': {
'poetry': {
Expand Down
18 changes: 7 additions & 11 deletions tests/tasks/test_tags.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# mypy: disable_error_code=type-arg

from pathlib import Path
from unittest.mock import call

import pytest
from beartype import beartype
from beartype.typing import Callable, Dict, List
from beartype.typing import Callable, Dict

from calcipy.tasks.tags import collect_code_tags
from tests.configuration import APP_DIR, TEST_DATA_DIR
Expand All @@ -29,7 +30,7 @@ def _check_output(kwargs: Dict) -> None:


@pytest.mark.parametrize(
('task', 'kwargs', 'commands', 'validator'),
('task', 'kwargs', 'validator'),
[
(collect_code_tags, {
'base_dir': APP_DIR.as_posix(),
Expand All @@ -38,25 +39,20 @@ def _check_output(kwargs: Dict) -> None:
'tag_order': 'FIXME,TODO',
'regex': '',
'ignore_patterns': '*.py,*.yaml,docs/docs/*.md',
}, [], _check_no_write),
}, _check_no_write),
(collect_code_tags, {
'base_dir': APP_DIR.as_posix(),
'doc_sub_dir': TEST_DATA_DIR.as_posix(),
'filename': 'test_tags.md.rej',
}, [], _check_output),
}, _check_output),
],
ids=[
'Check that no code tags were matched and no file was created',
'Check that no code tags were matched and no file was created',
],
)
@beartype
def test_tags(ctx, task, kwargs: Dict, commands: List[str], validator: Callable[[Dict], None]):
def test_tags(ctx, task, kwargs: Dict, validator: Callable[[Dict], None]):
task(ctx, **kwargs)

ctx.run.assert_has_calls([
call(cmd) if isinstance(cmd, str) else cmd
for cmd in commands
])

validator(kwargs)
6 changes: 3 additions & 3 deletions tests/tasks/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
[
(pyright, {}, [
call('which pyright', warn=True, hide=True),
'pyright calcipy',
'pyright',
]),
(mypy, {}, [f'{python_dir()}/mypy calcipy']),
(basedpyright, {}, [f'{python_dir()}/basedpyright calcipy']),
(mypy, {}, [f'{python_dir()}/mypy']),
(basedpyright, {}, [f'{python_dir()}/basedpyright']),
],
)
def test_types(ctx, task, kwargs, commands):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_scripts.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from calcipy.scripts import start_program # noqa: F401 # Smoke test the scripts import
from calcipy.scripts import start # noqa: F401 # Smoke test the scripts import

0 comments on commit 59c4921

Please sign in to comment.