Skip to content

Commit

Permalink
Add django-enable cli utility (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky committed Dec 27, 2020
1 parent 462d8ea commit 751b8b9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions app_enabler/cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
from subprocess import CalledProcessError

Expand All @@ -13,6 +14,10 @@
@click.pass_context
def cli(context, verbose):
"""Click entrypoint."""
# this is needed when calling as CLI utility to put the current directory
# in the python path as it's not done automatically
if os.getcwd() not in sys.path:
sys.path.insert(0, os.getcwd())
context.ensure_object(dict)
context.obj["verbose"] = verbose

Expand Down
1 change: 1 addition & 0 deletions changes/20.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add CLI utility
12 changes: 9 additions & 3 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ Sample execution flow

.. code-block:: bash
python -mapp_enabler install djangocms-blog~=1.2.1
django-enabler install djangocms-blog~=1.2.1
python manage.py migrate
After this the django application is configured and functional.

Additional configuration steps might be required according to the application
features and support level and must be documented by the application itself.

Alternatively you can execute the module itself:

.. code-block:: bash
python -mapp_enabler install djangocms-blog~=1.2.1
.. _enable_cmd:

Expand All @@ -55,7 +61,7 @@ Example:

.. code-block:: bash
python -mapp_enabler enabler djangocms_blog
django-enabler enable djangocms_blog
See :ref:`limitations` for limitations and caveats.
Expand All @@ -74,7 +80,7 @@ Installation is executed via the ``install`` command which a

.. code-block:: bash
python -mapp_enabler install djangocms-blog~=1.2.0
django-enabler install djangocms-blog~=1.2.0
.. note:: ``django-app-enabler`` is not intended as a replacement (or sidekick) of existing package / dependencies manager.
The installation step is only intended as a convenience command for those not sticking to any specific workflow.
Expand Down
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ app_enabler = *.html *.png *.gif *js *jpg *jpeg *svg *py *mo *po
docs =
django<3.1

[options.entry_points]
console_scripts =
django-enabler = app_enabler.__main__:execute

[upload]
repository = https://upload.pypi.org/legacy/

Expand Down
12 changes: 12 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
import sys
from subprocess import CalledProcessError
from unittest.mock import call, patch

Expand All @@ -20,6 +22,16 @@ def test_cli_install_wrong_dir(blog_package):
assert install_fun.call_args_list == [call("djangocms-blog", verbose=True, pip_options="")]


def test_cli_sys_path(project_dir, blog_package):
"""Running install command from the wrong directory raise an error."""
with patch("app_enabler.cli.enable_fun"):
# not using working_directory context manager to skip setting the sys.path (which is what we want to test)
os.chdir(str(project_dir))
runner = CliRunner()
runner.invoke(cli, ["enable", "djangocms-blog"])
assert str(project_dir) == sys.path[0]


def test_cli_install(project_dir, blog_package):
"""Running install command calls the business functions with the correct arguments."""
with patch("app_enabler.cli.enable_fun") as enable_fun, patch(
Expand Down

0 comments on commit 751b8b9

Please sign in to comment.