From c1108e3102379bf3496367a0b5c70508837e0deb Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 8 Dec 2024 19:33:06 -0600 Subject: [PATCH] fix: add command for `wutta make-appdir` --- docs/api/wuttjamaican.cli.make_appdir.rst | 6 +++ docs/index.rst | 1 + docs/narr/cli/builtin.rst | 12 +++++ src/wuttjamaican/cli/__init__.py | 1 + src/wuttjamaican/cli/make_appdir.py | 54 +++++++++++++++++++++++ tests/cli/test_make_appdir.py | 25 +++++++++++ 6 files changed, 99 insertions(+) create mode 100644 docs/api/wuttjamaican.cli.make_appdir.rst create mode 100644 src/wuttjamaican/cli/make_appdir.py create mode 100644 tests/cli/test_make_appdir.py diff --git a/docs/api/wuttjamaican.cli.make_appdir.rst b/docs/api/wuttjamaican.cli.make_appdir.rst new file mode 100644 index 0000000..be81983 --- /dev/null +++ b/docs/api/wuttjamaican.cli.make_appdir.rst @@ -0,0 +1,6 @@ + +``wuttjamaican.cli.make_appdir`` +================================ + +.. automodule:: wuttjamaican.cli.make_appdir + :members: diff --git a/docs/index.rst b/docs/index.rst index b7f0445..cd2064f 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -66,6 +66,7 @@ Contents api/wuttjamaican.auth api/wuttjamaican.cli api/wuttjamaican.cli.base + api/wuttjamaican.cli.make_appdir api/wuttjamaican.cli.make_uuid api/wuttjamaican.conf api/wuttjamaican.db diff --git a/docs/narr/cli/builtin.rst b/docs/narr/cli/builtin.rst index 0eafb2b..2eed21d 100644 --- a/docs/narr/cli/builtin.rst +++ b/docs/narr/cli/builtin.rst @@ -29,6 +29,18 @@ Defined in: :mod:`wuttjamaican.cli` .. program-output:: wutta --help +.. _wutta-make-appdir: + +``wutta make-appdir`` +--------------------- + +Make the :term:`app dir` for the current :term:`virtual environment`. + +Defined in: :mod:`wuttjamaican.cli.make_appdir` + +.. program-output:: wutta make-appdir --help + + .. _wutta-make-uuid: ``wutta make-uuid`` diff --git a/src/wuttjamaican/cli/__init__.py b/src/wuttjamaican/cli/__init__.py index b7b0ef3..0650b10 100644 --- a/src/wuttjamaican/cli/__init__.py +++ b/src/wuttjamaican/cli/__init__.py @@ -34,6 +34,7 @@ This (``wuttjamaican.cli``) namespace exposes the following: from .base import wutta_typer, make_typer # nb. must bring in all modules for discovery to work +from . import make_appdir from . import make_uuid # discover more commands, installed via other packages diff --git a/src/wuttjamaican/cli/make_appdir.py b/src/wuttjamaican/cli/make_appdir.py new file mode 100644 index 0000000..c62684c --- /dev/null +++ b/src/wuttjamaican/cli/make_appdir.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8; -*- +################################################################################ +# +# WuttJamaican -- Base package for Wutta Framework +# Copyright © 2023-2024 Lance Edgar +# +# This file is part of Wutta Framework. +# +# Wutta Framework is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# Wutta Framework is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# Wutta Framework. If not, see . +# +################################################################################ +""" +See also: :ref:`wutta-make-appdir` +""" + +import sys +from pathlib import Path + +import typer +from typing_extensions import Annotated + +from .base import wutta_typer + + +@wutta_typer.command() +def make_appdir( + ctx: typer.Context, + appdir_path: Annotated[ + Path, + typer.Option('--path', + help="Path to desired app dir; default is (usually) " + "`app` in the root of virtual environment.")] = None, +): + """ + Make the app dir for virtual environment + + See also https://rattailproject.org/docs/wuttjamaican/glossary.html#term-app-dir + """ + config = ctx.parent.wutta_config + app = config.get_app() + appdir = ctx.params['appdir_path'] or app.get_appdir() + app.make_appdir(appdir) + sys.stdout.write(f"established appdir: {appdir}\n") diff --git a/tests/cli/test_make_appdir.py b/tests/cli/test_make_appdir.py new file mode 100644 index 0000000..0bd7d42 --- /dev/null +++ b/tests/cli/test_make_appdir.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8; -*- + +import os +from unittest.mock import MagicMock, patch + +from wuttjamaican.testing import ConfigTestCase +from wuttjamaican.cli import make_appdir as mod +from wuttjamaican.app import AppHandler + + +here = os.path.dirname(__file__) +example_conf = os.path.join(here, 'example.conf') + + +class TestMakeAppdir(ConfigTestCase): + + def test_basic(self): + appdir = os.path.join(self.tempdir, 'app') + ctx = MagicMock(params={'config_paths': [example_conf], + 'appdir_path': appdir}) + ctx.parent.wutta_config = self.config + + with patch.object(AppHandler, 'make_appdir') as make_appdir: + mod.make_appdir(ctx) + make_appdir.assert_called_once_with(appdir)