Skip to content

Commit

Permalink
Merge pull request #22 from CrowdJustice/add-install-command
Browse files Browse the repository at this point in the history
Add install command
  • Loading branch information
phil-bell authored Mar 4, 2022
2 parents a3e4a83 + b1deee7 commit ae1657b
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 18 deletions.
83 changes: 69 additions & 14 deletions legl_dev/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3
import os
from typing import Optional

import pkg_resources
import typer
Expand All @@ -12,7 +13,7 @@
os.environ["DOCKER_BUILDKIT"] = "1"


@app.command(help="Start the dev enviroment")
@app.command(help="Start the dev environment")
def start():
steps = Steps()
steps.add(
Expand All @@ -23,7 +24,7 @@ def start():
steps.run()


@app.command(help="Rebuild the local enviroment")
@app.command(help="Rebuild the local environment")
def build(
cache: bool = typer.Option(True, help="Drop the database and create a fresh one"),
) -> None:
Expand Down Expand Up @@ -112,7 +113,7 @@ def pytest(
Command(
command=(
f"docker compose "
"exec backend pytest "
"run --rm backend pytest "
"--html=unit_test_results.html "
f"{extra_args} /code/{path}"
)
Expand Down Expand Up @@ -175,8 +176,7 @@ def migrate(
steps.add(
Command(
command=(
f"docker compose "
"exec backend python manage.py makemigrations --merge"
f"docker compose exec backend python manage.py makemigrations --merge"
)
),
)
Expand All @@ -185,8 +185,7 @@ def migrate(
(
Command(
command=(
f"docker compose "
"exec backend python manage.py makemigrations"
f"docker compose exec backend python manage.py makemigrations"
)
)
),
Expand Down Expand Up @@ -244,14 +243,70 @@ def gitclean():
@app.command(help="Run JS unit tests")
def jstest():

steps = Steps(
steps=[
Command(command=(f"yarn run test")),
steps = Steps(steps=[Command(command=(f"yarn run test"))])
steps.run()


@app.command(help="Install packages to the dev environment")
def install(
package: Optional[str] = typer.Argument(
default="", help="Name of the package you would like to install"
),
pip: bool = typer.Option(default=False, help="Install package using pip"),
yarn: bool = typer.Option(default=False, help="Install package using yarn"),
self: bool = typer.Option(
default=False,
help="Reinstall legl-dev, can be used with --upgrade to on update current install",
),
version: str = typer.Option(
default="main", help="specify version of legl-dev to install"
),
upgrade: bool = typer.Option(
default=False, help="upgrade existing package instead of installing"
),
):
steps = Steps()
if pip:
steps.add(
[
Command(
command=(
f"docker exec backend pip install {'--upgrade' if upgrade else ''} {package}"
)
),
Command(
command=(
f"docker exec backend pip freeze | grep {package} >> requirements.txt"
),
shell=True,
),
]
)

if yarn:
steps.add(
Command(
command="open js-test-results/index.html",
),
]
)
command=(
f"docker exec frontend yarn {'up' if upgrade else 'add'} {package}"
)
)
)

if self:
if upgrade:
steps.add(Command(command=f"pip install --upgrade legl-dev"))
else:
steps.add(
[
Command(command=("pip uninstall legl-dev -y")),
Command(
command=(
f"pip install git+https://github.com/CrowdJustice/legl-dev.git@{version}"
)
),
]
)

steps.run()


Expand Down
148 changes: 146 additions & 2 deletions legl_dev/tests/test_main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from unittest import mock

from legl_dev.main import start
from legl_dev import main


@mock.patch("legl_dev.command.run")
def test_standard_start(run):
start()
main.start()
calls = [
mock.call(
["docker", "compose", "up"],
Expand All @@ -15,3 +15,147 @@ def test_standard_start(run):
),
]
run.assert_has_calls(calls)


@mock.patch("legl_dev.command.run")
def test_install_pip(run):
main.install(
package="example",
pip=True,
yarn=False,
self=False,
version="main",
upgrade=False,
)
calls = [
mock.call(
["docker", "exec", "backend", "pip", "install", "example"],
universal_newlines=True,
shell=False,
check=True,
),
mock.call(
"docker exec backend pip freeze | grep example >> requirements.txt",
universal_newlines=True,
shell=True,
check=True,
),
]
run.assert_has_calls(calls)


@mock.patch("legl_dev.command.run")
def test_install_pip_upgrade(run):
main.install(
package="example",
pip=True,
yarn=False,
self=False,
version="main",
upgrade=True,
)
calls = [
mock.call(
["docker", "exec", "backend", "pip", "install", "--upgrade", "example"],
universal_newlines=True,
shell=False,
check=True,
),
mock.call(
"docker exec backend pip freeze | grep example >> requirements.txt",
universal_newlines=True,
shell=True,
check=True,
),
]
run.assert_has_calls(calls)


@mock.patch("legl_dev.command.run")
def test_install_yarn(run):
main.install(
package="example",
pip=False,
yarn=True,
self=False,
version="main",
upgrade=False,
)
calls = [
mock.call(
["docker", "exec", "frontend", "yarn", "add", "example"],
universal_newlines=True,
shell=False,
check=True,
),
]
run.assert_has_calls(calls)


@mock.patch("legl_dev.command.run")
def test_install_yarn_upgrade(run):
main.install(
package="example",
pip=False,
yarn=True,
self=False,
version="main",
upgrade=True,
)
calls = [
mock.call(
["docker", "exec", "frontend", "yarn", "up", "example"],
universal_newlines=True,
shell=False,
check=True,
),
]
run.assert_has_calls(calls)


@mock.patch("legl_dev.command.run")
def test_install_self(run):
main.install(
package="example",
pip=False,
yarn=False,
self=True,
version="main",
upgrade=False,
)
calls = [
mock.call(
["pip", "uninstall", "legl-dev", "-y"],
universal_newlines=True,
shell=False,
check=True,
),
mock.call(
["pip", "install", "git+https://github.com/CrowdJustice/legl-dev.git@main"],
universal_newlines=True,
shell=False,
check=True,
),
]
run.assert_has_calls(calls)


@mock.patch("legl_dev.command.run")
def test_install_self_upgrade(run):
main.install(
package="example",
pip=False,
yarn=False,
self=True,
version="main",
upgrade=True,
)
calls = [
mock.call(
["pip", "install", "--upgrade", "legl-dev"],
universal_newlines=True,
shell=False,
check=True,
),
]
run.assert_has_calls(calls)
6 changes: 4 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
from setuptools import setup

version = "1.1.0"

packages = ["legl_dev"]

package_data = {"": ["*"]}
Expand All @@ -11,9 +13,9 @@

setup_kwargs = {
"name": "legl-dev",
"version": "1.0.7",
"version": version,
"description": "",
"long_description": '# `legl-dev`\n\n**Usage**:\n\n```console\n$ legl-dev [OPTIONS] COMMAND [ARGS]...\n```\n\n**Options**:\n\n* `--install-completion`: Install completion for the current shell.\n* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.\n* `--help`: Show this message and exit.\n\n**Commands**:\n\n* `build`: Rebuild the local enviroment\n* `cypress`: Open Cpyress e2e tests\n* `factories`: Clean out and create new factories\n* `format`: Format the code with black and prettier\n* `gitclean`: Cleans out git branches\n* `jstest`: Run JS unit tests\n* `migrate`: Create and run migrations\n* `pytest`: Run the local pytest unit tests\n* `start`: Start the dev enviroment\n* `update`: Update dependancies\n\n## `legl-dev build`\n\nRebuild the local enviroment\n\n**Usage**:\n\n```console\n$ legl-dev build [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--create-db / --no-create-db`: Drop the database and create a fresh one [default: False]\n* `--help`: Show this message and exit.\n\n## `legl-dev cypress`\n\nOpen Cpyress e2e tests\n\n**Usage**:\n\n```console\n$ legl-dev cypress [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: True]\n* `--help`: Show this message and exit.\n\n## `legl-dev factories`\n\nClean out and create new factories\n\n**Usage**:\n\n```console\n$ legl-dev factories [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--help`: Show this message and exit.\n\n## `legl-dev format`\n\nFormat the code with black and prettier\n\n**Usage**:\n\n```console\n$ legl-dev format [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--push / --no-push`: Also push the changes to the repo [default: False]\n* `--help`: Show this message and exit.\n\n## `legl-dev gitclean`\n\nCleans out git branches\n\n**Usage**:\n\n```console\n$ legl-dev gitclean [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--help`: Show this message and exit.\n\n## `legl-dev jstest`\n\nRun JS unit tests\n\n**Usage**:\n\n```console\n$ legl-dev jstest [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: True]\n* `--help`: Show this message and exit.\n\n## `legl-dev migrate`\n\nCreate and run migrations\n\n**Usage**:\n\n```console\n$ legl-dev migrate [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--merge / --no-merge`: Run a migration merge first [default: False]\n* `--help`: Show this message and exit.\n\n## `legl-dev pytest`\n\nRun the local pytest unit tests\n\n**Usage**:\n\n```console\n$ legl-dev pytest [OPTIONS] [PATH]\n```\n\n**Arguments**:\n\n* `[PATH]`: path for specific test in the format "<file path>::<class name>::<function name>" [default: ]\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--full-diff / --no-full-diff`: Show full diff in errors [default: False]\n* `--create-db / --no-create-db`: Recreates the test database [default: False]\n* `--last-failed / --no-last-failed`: Run the last failed tests [default: False]\n* `--warnings / --no-warnings`: Toggle warnings in output [default: True]\n* `--gui / --no-gui`: Toggle the output gui [default: True]\n* `--help`: Show this message and exit.\n\n## `legl-dev start`\n\nStart the dev enviroment\n\n**Usage**:\n\n```console\n$ legl-dev start [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: True]\n* `--help`: Show this message and exit.\n\n## `legl-dev update`\n\nUpdate dependancies\n\n**Usage**:\n\n```console\n$ legl-dev update [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--help`: Show this message and exit.\n',
"long_description": '# `legl-dev`\n\n**Usage**:\n\n```console\n$ legl-dev [OPTIONS] COMMAND [ARGS]...\n```\n\n**Options**:\n\n* `--install-completion`: Install completion for the current shell.\n* `--show-completion`: Show completion for the current shell, to copy it or customize the installation.\n* `--help`: Show this message and exit.\n\n**Commands**:\n\n* `build`: Rebuild the local environment\n* `cypress`: Open Cpyress e2e tests\n* `factories`: Clean out and create new factories\n* `format`: Format the code with black and prettier\n* `gitclean`: Cleans out git branches\n* `jstest`: Run JS unit tests\n* `migrate`: Create and run migrations\n* `pytest`: Run the local pytest unit tests\n* `start`: Start the dev environment\n* `update`: Update dependancies\n\n## `legl-dev build`\n\nRebuild the local environment\n\n**Usage**:\n\n```console\n$ legl-dev build [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--create-db / --no-create-db`: Drop the database and create a fresh one [default: False]\n* `--help`: Show this message and exit.\n\n## `legl-dev cypress`\n\nOpen Cpyress e2e tests\n\n**Usage**:\n\n```console\n$ legl-dev cypress [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: True]\n* `--help`: Show this message and exit.\n\n## `legl-dev factories`\n\nClean out and create new factories\n\n**Usage**:\n\n```console\n$ legl-dev factories [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--help`: Show this message and exit.\n\n## `legl-dev format`\n\nFormat the code with black and prettier\n\n**Usage**:\n\n```console\n$ legl-dev format [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--push / --no-push`: Also push the changes to the repo [default: False]\n* `--help`: Show this message and exit.\n\n## `legl-dev gitclean`\n\nCleans out git branches\n\n**Usage**:\n\n```console\n$ legl-dev gitclean [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--help`: Show this message and exit.\n\n## `legl-dev jstest`\n\nRun JS unit tests\n\n**Usage**:\n\n```console\n$ legl-dev jstest [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: True]\n* `--help`: Show this message and exit.\n\n## `legl-dev migrate`\n\nCreate and run migrations\n\n**Usage**:\n\n```console\n$ legl-dev migrate [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--merge / --no-merge`: Run a migration merge first [default: False]\n* `--help`: Show this message and exit.\n\n## `legl-dev pytest`\n\nRun the local pytest unit tests\n\n**Usage**:\n\n```console\n$ legl-dev pytest [OPTIONS] [PATH]\n```\n\n**Arguments**:\n\n* `[PATH]`: path for specific test in the format "<file path>::<class name>::<function name>" [default: ]\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--full-diff / --no-full-diff`: Show full diff in errors [default: False]\n* `--create-db / --no-create-db`: Recreates the test database [default: False]\n* `--last-failed / --no-last-failed`: Run the last failed tests [default: False]\n* `--warnings / --no-warnings`: Toggle warnings in output [default: True]\n* `--gui / --no-gui`: Toggle the output gui [default: True]\n* `--help`: Show this message and exit.\n\n## `legl-dev start`\n\nStart the dev environment\n\n**Usage**:\n\n```console\n$ legl-dev start [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: True]\n* `--help`: Show this message and exit.\n\n## `legl-dev update`\n\nUpdate dependancies\n\n**Usage**:\n\n```console\n$ legl-dev update [OPTIONS]\n```\n\n**Options**:\n\n* `--verbose / --no-verbose`: Run the command in verbose mode [default: False]\n* `--help`: Show this message and exit.\n',
"author": "phil-bell",
"author_email": "[email protected]",
"maintainer": None,
Expand Down

0 comments on commit ae1657b

Please sign in to comment.