Skip to content

Commit

Permalink
Merge pull request #223 from BrianPugh/optim
Browse files Browse the repository at this point in the history
lazily call _default_version; it can be quite slow to call so often.
  • Loading branch information
BrianPugh authored Aug 27, 2024
2 parents 34df4c7 + 2f8ba13 commit d311432
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cyclopts/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class App:
kw_only=True,
)

version: Union[None, str, Callable[..., str]] = field(factory=_default_version, kw_only=True)
version: Union[None, str, Callable[..., str]] = field(default=_default_version, kw_only=True)
# This can ONLY ever be a Tuple[str, ...]
_version_flags: Union[str, Iterable[str]] = field(
default=["--version"],
Expand Down
5 changes: 2 additions & 3 deletions tests/test_app_name_derivation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ def test_app_name_derivation_main_module(mocker, mock_get_root_module_name):
mocker.patch("cyclopts.core.sys.argv", ["__main__.py"])
app = App()

mock_get_root_module_name.assert_called()
assert app.name == ("mock_module_name",)
mock_get_root_module_name.assert_called()


def test_app_name_derivation_not_main_module(mocker, mock_get_root_module_name):
def test_app_name_derivation_not_main_module(mocker):
mocker.patch("cyclopts.core.sys.argv", ["my-script.py"])
app = App()

mock_get_root_module_name.assert_called()
assert app.name == ("my-script.py",)

0 comments on commit d311432

Please sign in to comment.