fix: add command for wutta make-appdir
This commit is contained in:
parent
45ea5c5bdc
commit
c1108e3102
6
docs/api/wuttjamaican.cli.make_appdir.rst
Normal file
6
docs/api/wuttjamaican.cli.make_appdir.rst
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
``wuttjamaican.cli.make_appdir``
|
||||||
|
================================
|
||||||
|
|
||||||
|
.. automodule:: wuttjamaican.cli.make_appdir
|
||||||
|
:members:
|
|
@ -66,6 +66,7 @@ Contents
|
||||||
api/wuttjamaican.auth
|
api/wuttjamaican.auth
|
||||||
api/wuttjamaican.cli
|
api/wuttjamaican.cli
|
||||||
api/wuttjamaican.cli.base
|
api/wuttjamaican.cli.base
|
||||||
|
api/wuttjamaican.cli.make_appdir
|
||||||
api/wuttjamaican.cli.make_uuid
|
api/wuttjamaican.cli.make_uuid
|
||||||
api/wuttjamaican.conf
|
api/wuttjamaican.conf
|
||||||
api/wuttjamaican.db
|
api/wuttjamaican.db
|
||||||
|
|
|
@ -29,6 +29,18 @@ Defined in: :mod:`wuttjamaican.cli`
|
||||||
.. program-output:: wutta --help
|
.. 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:
|
||||||
|
|
||||||
``wutta make-uuid``
|
``wutta make-uuid``
|
||||||
|
|
|
@ -34,6 +34,7 @@ This (``wuttjamaican.cli``) namespace exposes the following:
|
||||||
from .base import wutta_typer, make_typer
|
from .base import wutta_typer, make_typer
|
||||||
|
|
||||||
# nb. must bring in all modules for discovery to work
|
# nb. must bring in all modules for discovery to work
|
||||||
|
from . import make_appdir
|
||||||
from . import make_uuid
|
from . import make_uuid
|
||||||
|
|
||||||
# discover more commands, installed via other packages
|
# discover more commands, installed via other packages
|
||||||
|
|
54
src/wuttjamaican/cli/make_appdir.py
Normal file
54
src/wuttjamaican/cli/make_appdir.py
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
"""
|
||||||
|
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")
|
25
tests/cli/test_make_appdir.py
Normal file
25
tests/cli/test_make_appdir.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue