Skip to content

Commit

Permalink
fix: specify a unique name when binding new kwargs
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleKing committed Sep 1, 2023
1 parent dd31fdf commit fa82592
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
7 changes: 7 additions & 0 deletions calcipy/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Extend Invoke for Calcipy."""

import sys
from base64 import b64encode
from functools import wraps
from pathlib import Path
from types import ModuleType
Expand Down Expand Up @@ -116,6 +117,12 @@ def wrapper(func: Any) -> Callable: # type: ignore[type-arg] # noqa: CFQ004

def _with_kwargs(**extra_kwargs: Any) -> Callable: # type: ignore[type-arg] # nosem
"""Support building partial tasks."""
if extra_kwargs:
# Set a unique name when 'extra_kwargs' was provided
# https://github.com/pyinvoke/invoke/blob/07b836f2663bb073a7bcef3d6c454e1dc6b867ae/invoke/tasks.py#L81-L104
encoded = b64encode(str(extra_kwargs).encode())
func.__name__ = f'{func.__name__}_{encoded.decode().rstrip("=")}'

@wraps(func) # nosem
def _with_kwargs_inner(*args: Any, **kwargs: Any) -> Any:
return func(*args, **kwargs, **extra_kwargs)
Expand Down
2 changes: 1 addition & 1 deletion calcipy/tasks/_invoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _wrapped_task(ctx: Context, *args: Any, func: Any, show_task_info: bool, **k

def _build_task(task: DeferedTask) -> Task: # type: ignore[type-arg] # pragma: no cover
"""Defer creation of the Task."""
if hasattr(task, TASK_ARGS_ATTR):
if hasattr(task, TASK_ARGS_ATTR) or hasattr(task, TASK_KWARGS_ATTR):
@wraps(task)
def inner(*args: Any, **kwargs: Any) -> Any:
return _wrapped_task(*args, func=task, show_task_info=show_task_info, **kwargs)
Expand Down
9 changes: 3 additions & 6 deletions calcipy/tasks/all_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ def progress(_ctx: Context, *, index: int, total: int) -> None:


@beartype
def with_progress(
items: Any, # PLANNED: TaskList,
offset: int = 0,
) -> TaskList:
def with_progress(items: Any, offset: int = 0) -> TaskList:
"""Inject intermediary 'progress' tasks.
Args:
Expand All @@ -70,7 +67,7 @@ def with_progress(

total = len(task_items) + offset
for idx, item in enumerate(task_items):
tasks.extend([progress.with_kwargs(index=idx + offset, total=total), item])
tasks += [progress.with_kwargs(index=idx + offset, total=total), item]
return tasks


Expand All @@ -89,11 +86,11 @@ def with_progress(
stale.check_for_stale_packages,
]
_OTHER_TASKS = [
test.check,
lint.flake8,
lint.pylint,
pack.check_licenses,
test.step,
test.check, # Expected to fail for calcipy
]


Expand Down
4 changes: 4 additions & 0 deletions docs/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

- drop Python 3.8

### Fix

- specify a unique name when binding new kwargs

## 1.6.4 (2023-08-28)

### Fix
Expand Down
3 changes: 1 addition & 2 deletions docs/docs/CODE_TAG_SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
|---------|----------------------------------------------------------------------------------------------------|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| TODO | If no stale, write out five oldest? | 2023-05-13 | [calcipy/check_for_stale_packages/_check_for_stale_packages.py:209](https://github.com/KyleKing/calcipy/blame/86c37cc4f24911db5562ef6fc8263102dbbcf5c5/calcipy/check_for_stale_packages/_check_for_stale_packages.py#L198) |
| TODO | Consider adding a configuration item for ignore_patterns | 2023-02-19 | [calcipy/file_search.py:82](https://github.com/KyleKing/calcipy/blame/e6bc0415e3bf6a6df5a9d808ce0e89d0f2c5df9e/calcipy/file_search.py#L82) |
| PLANNED | TaskList, | 2023-08-13 | [calcipy/tasks/all_tasks.py:57](https://github.com/KyleKing/calcipy/blame/689c23a8cfc113983cd47a90c655efec3474cec8/calcipy/tasks/all_tasks.py#L57) |
| TODO | Look into running tasks from within other tasks to support '--continue' and more readable logs --> | 2023-02-19 | [docs/docs/MIGRATION.md:112](https://github.com/KyleKing/calcipy/blame/d95eb85ab7f6d45459ed7b3ff2dc99ae3c92fa61/docs/docs/MIGRATION.md#L42) |
| TODO | Capture logging output and check... | 2023-02-19 | [tests/check_for_stale_packages/test_check_for_stale_packages.py:64](https://github.com/KyleKing/calcipy/blame/a8b69e7b04d9b15eabff8897f2de7703898c2afc/tests/check_for_stale_packages/test_check_for_stale_packages.py#L63) |
| TODO | Capture logging output and check... | 2023-02-19 | [tests/check_for_stale_packages/test_check_for_stale_packages.py:88](https://github.com/KyleKing/calcipy/blame/3f42ad855eb7024ff48af35d496633a87d4a14ac/tests/check_for_stale_packages/test_check_for_stale_packages.py#L26) |
| TODO | Is there an easier way to maintain pytest parameter IDs? | 2023-02-17 | [tests/tasks/test_test.py:14](https://github.com/KyleKing/calcipy/blame/785b9d1c3afda6fc5a2e46f2bc7d41ed2614da09/tests/tasks/test_test.py#L11) |
| PLANNED | Convert to hypothesis test! | 2023-02-19 | [tests/test_dot_dict.py:9](https://github.com/KyleKing/calcipy/blame/3f42ad855eb7024ff48af35d496633a87d4a14ac/tests/test_dot_dict.py#L9) |

Found code tags for TODO (6), PLANNED (2)
Found code tags for TODO (6), PLANNED (1)

<!-- calcipy_skip_tags -->
4 changes: 2 additions & 2 deletions docs/docs/DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ poetry config pypi-token.pypi ...
| `calcipy/can_skip.py` | 17 | 1 | 0 | 89.3% |
| `calcipy/check_for_stale_packages/__init__.py` | 4 | 2 | 0 | 50.0% |
| `calcipy/check_for_stale_packages/_check_for_stale_packages.py` | 117 | 8 | 3 | 87.2% |
| `calcipy/cli.py` | 33 | 1 | 36 | 94.9% |
| `calcipy/cli.py` | 37 | 1 | 36 | 93.3% |
| `calcipy/code_tag_collector/__init__.py` | 4 | 2 | 0 | 50.0% |
| `calcipy/code_tag_collector/_collector.py` | 142 | 2 | 0 | 94.0% |
| `calcipy/dot_dict/__init__.py` | 4 | 2 | 0 | 50.0% |
Expand Down Expand Up @@ -79,7 +79,7 @@ poetry config pypi-token.pypi ...
| `calcipy/tasks/tags.py` | 15 | 0 | 0 | 100.0% |
| `calcipy/tasks/test.py` | 45 | 1 | 2 | 89.2% |
| `calcipy/tasks/types.py` | 17 | 0 | 0 | 91.3% |
| **Totals** | 1028 | 66 | 174 | 87.3% |
| **Totals** | 1032 | 66 | 174 | 87.3% |

Generated on: 2023-08-31
<!-- {cte} -->

0 comments on commit fa82592

Please sign in to comment.