Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion invenio_cli/cli/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""Invenio module to ease the creation and management of applications."""

import click
from click_default_group import DefaultGroup

from ..commands import AssetsCommands
from .utils import pass_cli_config, run_steps
Expand Down
24 changes: 17 additions & 7 deletions invenio_cli/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,26 +45,35 @@ def invenio_cli(ctx):
help='Check development requirements.')
def check_requirements(development):
"""Checks the system fulfills the pre-requirements."""
try:
# the 'check-requirements' command should probably be available
# from outside the project directory as well
cli_config = CLIConfig()
except FileNotFoundError:
cli_config = None

click.secho("Checking pre-requirements...", fg="green")
steps = RequirementsCommands.check(development)
steps = RequirementsCommands(cli_config).check(development)
on_fail = "Pre requisites not met."
on_success = "All requisites are fulfilled."

run_steps(steps, on_fail, on_success)


@invenio_cli.command()
def shell():
@pass_cli_config
def shell(cli_config):
"""Shell command."""
Commands.shell()
Commands(cli_config).shell()


@invenio_cli.command()
@pass_cli_config
@click.option('--debug/--no-debug', '-d/', default=False, is_flag=True,
help='Enable Flask development mode (default: disabled).')
def pyshell(debug):
def pyshell(cli_config, debug):
"""Python shell command."""
Commands.pyshell(debug=debug)
Commands(cli_config).pyshell(debug=debug)


@invenio_cli.command()
Expand Down Expand Up @@ -151,9 +160,10 @@ def destroy(cli_config):
@click.option('--script', required=True,
help='The path of custom migration script.'
)
def upgrade(script):
@pass_cli_config
def upgrade(cli_config, script):
"""Upgrades the current instance to a newer version."""
steps = UpgradeCommands.upgrade(script)
steps = UpgradeCommands(cli_config).upgrade(script)
on_fail = "Upgrade failed."
on_success = "Upgrade sucessfull."

Expand Down
12 changes: 7 additions & 5 deletions invenio_cli/cli/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def lock(cli_config, pre, dev):
f"Include dev-packages: {dev}.",
fg="green"
)
steps = PackagesCommands.lock(pre, dev)
steps = PackagesCommands(cli_config).lock(pre, dev)
on_fail = "Failed to lock dependencies."
on_success = "Dependencies locked successfully."

Expand All @@ -49,7 +49,7 @@ def install(cli_config, packages, skip_build):
if len(packages) < 1:
raise click.UsageError("You must specify at least one package.")

steps = PackagesCommands.install_packages(packages)
steps = PackagesCommands(cli_config).install_packages(packages)

on_fail = f"Failed to install packages {packages}."
on_success = f"Packages {packages} installed successfully."
Expand All @@ -67,8 +67,9 @@ def install(cli_config, packages, skip_build):
@pass_cli_config
def outdated(cli_config):
"""Show outdated Python dependencies."""
steps = PackagesCommands.outdated_packages()
steps = PackagesCommands(cli_config).outdated_packages()

# TODO poetry still exits with 0, even if there's outdated packages
on_fail = "Some of the packages need to be updated."
on_success = "All packages are up to date."

Expand All @@ -80,15 +81,16 @@ def outdated(cli_config):
@pass_cli_config
def update(cli_config, version=None):
"""Update all or some Python python packages."""
pkg_commands = PackagesCommands(cli_config)
if version:
db = cli_config.get_db_type()
es = f"elasticsearch{cli_config.get_es_version()}"
package = f"invenio-app-rdm[{db},{es}]~="
steps = PackagesCommands.update_package_new_version(package, version)
steps = pkg_commands.update_package_new_version(package, version)
on_fail = f"Failed to update version {version}"
on_success = f"Version {version} installed successfully."
else:
steps = PackagesCommands.update_packages()
steps = pkg_commands.update_packages()
on_fail = "Failed to update packages."
on_success = "Packages installed successfully."

Expand Down
2 changes: 1 addition & 1 deletion invenio_cli/cli/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import click

from ..commands import Commands, ServicesCommands
from ..commands import ServicesCommands
from .utils import pass_cli_config, run_steps


Expand Down
11 changes: 6 additions & 5 deletions invenio_cli/commands/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@


import subprocess
from functools import partial
from pathlib import Path

import click
from pynpm import NPMPackage

from ..helpers import env
from ..helpers.packaging import get_packaging_backend
from ..helpers.process import ProcessResponse, run_interactive
from .local import LocalCommands
from .steps import CommandStep, FunctionStep
from .steps import FunctionStep


class AssetsCommands(LocalCommands):
Expand Down Expand Up @@ -79,7 +79,7 @@ def _npm_install_command(path):
)
else:
return ProcessResponse(
error=f"Unable to install dependent packages. "
error="Unable to install dependent packages. "
"Got error code {status_code}",
status_code=status_code
)
Expand Down Expand Up @@ -125,8 +125,9 @@ def _assets_link(assets_pkg, module_pkg):
def watch_assets(self):
"""High-level command to watch assets for changes."""
# Commands
prefix = ['pipenv', 'run']
watch_cmd = prefix + ['invenio', 'webpack', 'run', 'start']
watch_cmd = get_packaging_backend(self.cli_config).run_command(
"invenio", "webpack", "run", "start"
)

with env(FLASK_ENV='development'):
# Collect into statics/ and assets/ folder
Expand Down
16 changes: 9 additions & 7 deletions invenio_cli/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""Invenio module to ease the creation and management of applications."""

from ..helpers.env import env
from ..helpers.packaging import get_packaging_backend
from ..helpers.process import run_interactive
from .steps import CommandStep

Expand All @@ -22,17 +23,17 @@ def __init__(self, cli_config):
"""
self.cli_config = cli_config

@classmethod
def shell(cls):
def shell(self):
"""Start a shell in the virtual environment."""
command = ['pipenv', 'shell', ]
command = get_packaging_backend(self.cli_config).shell_command()
return run_interactive(command, env={'PIPENV_VERBOSITY': "-1"})

@classmethod
def pyshell(cls, debug=False):
def pyshell(self, debug=False):
"""Start a Python shell."""
with env(FLASK_ENV='development' if debug else 'production'):
command = ['pipenv', 'run', 'invenio', 'shell']
command = get_packaging_backend(self.cli_config).run_command(
"invenio", "shell"
)
return run_interactive(command, env={'PIPENV_VERBOSITY': "-1"})

def destroy(self):
Expand All @@ -41,9 +42,10 @@ def destroy(self):
NOTE: This function has no knowledge of the existence of services.
Refer to services.py to destroy services' containers.
"""
command = get_packaging_backend(self.cli_config).remove_venv_command()
steps = [
CommandStep(
cmd=['pipenv', '--rm'],
cmd=command,
env={'PIPENV_VERBOSITY': "-1"},
message="Destroying virtual environment"
)
Expand Down
9 changes: 5 additions & 4 deletions invenio_cli/commands/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from ..helpers.docker_helper import DockerHelper
from .packages import PackagesCommands
from .services import ServicesCommands
from .services_health import HEALTHCHECKS
from .steps import FunctionStep


Expand All @@ -23,6 +22,7 @@ def __init__(self, cli_config, docker_helper=None):
DockerHelper(cli_config.get_project_shortname(), local=False)

super(ContainersCommands, self).__init__(cli_config, docker_helper)
self.pkg_commands = PackagesCommands(cli_config)

def build(self, pull=True, cache=True):
"""Return the steps to build images.
Expand All @@ -32,7 +32,7 @@ def build(self, pull=True, cache=True):
"""
steps = [
FunctionStep(
func=PackagesCommands.is_locked,
func=self.pkg_commands.is_locked,
message="Checking if dependencies are locked."
),
FunctionStep(
Expand Down Expand Up @@ -81,7 +81,8 @@ def _cleanup(self, project_shortname="/opt/var/instance/"):
},
message="Purging queues..."
),
FunctionStep(func=self.cli_config.update_services_setup,
FunctionStep(
func=self.cli_config.update_services_setup,
args={"is_setup": False},
message="Updating service setup status (False)..."
)
Expand Down Expand Up @@ -227,7 +228,7 @@ def start(self, lock=False, build=False, setup=False, demo_data=True,

if lock:
# FIXME: Should this params be accepted? sensible defaults?
steps.extend(PackagesCommands.lock(pre=True, dev=True))
steps.extend(self.pkg_commands.lock(pre=True, dev=True))

if build:
steps.extend(self.build())
Expand Down
25 changes: 14 additions & 11 deletions invenio_cli/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

"""Invenio module to ease the creation and management of applications."""

from ..helpers import env, filesystem
from ..helpers import filesystem
from ..helpers.packaging import get_packaging_backend
from ..helpers.process import run_cmd
from .local import LocalCommands
from .packages import PackagesCommands
from .steps import CommandStep, FunctionStep
from .steps import FunctionStep


class InstallCommands(LocalCommands):
Expand All @@ -20,16 +21,17 @@ class InstallCommands(LocalCommands):
def __init__(self, cli_config):
"""Constructor."""
super(InstallCommands, self).__init__(cli_config)
self.pkg_commands = PackagesCommands(cli_config)

def install_py_dependencies(self, pre, dev=False):
"""Install Python dependencies."""
# If not locked, lock. Then install.
steps = []

if PackagesCommands.is_locked().status_code > 0:
steps.extend(PackagesCommands.lock(pre, dev))
if self.pkg_commands.is_locked().status_code > 0:
steps.extend(self.pkg_commands.lock(pre, dev))

steps.extend(PackagesCommands.install_locked_dependencies(pre, dev))
steps.extend(self.pkg_commands.install_locked_dependencies(pre, dev))

return steps

Expand All @@ -38,10 +40,11 @@ def update_instance_path(self):
# FIXME: Transform into steps.
# Currently not possible because the second step (update instance
# path) requires the ouptut of the previous step
result = run_cmd(
['pipenv', 'run', 'invenio', 'shell', '--no-term-title',
'-c', '"print(app.instance_path, end=\'\')"']
command = get_packaging_backend(self.cli_config).run_command(
'invenio', 'shell', '--no-term-title', '-c',
'"print(app.instance_path, end=\'\')"',
)
result = run_cmd(command)
if result.status_code == 0:
self.cli_config.update_instance_path(result.output.strip())
result.output = "Instance path updated successfully."
Expand All @@ -67,21 +70,21 @@ def install(self, pre, dev=False, flask_env='production'):
FunctionStep(
func=self.symlink_project_file_or_folder,
args={"target": 'invenio.cfg'},
message=f"Symlinking 'invenio.cfg'..."
message="Symlinking 'invenio.cfg'..."
)
)
steps.append(
FunctionStep(
func=self.symlink_project_file_or_folder,
args={"target": 'templates'},
message=f"Symlinking 'templates'..."
message="Symlinking 'templates'..."
)
)
steps.append(
FunctionStep(
func=self.symlink_project_file_or_folder,
args={"target": 'app_data'},
message=f"Symlinking 'app_data'..."
message="Symlinking 'app_data'..."
)
)
steps.append(
Expand Down
29 changes: 17 additions & 12 deletions invenio_cli/commands/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
from distutils.dir_util import copy_tree
from os import environ
from pathlib import Path
from subprocess import Popen as popen
from subprocess import Popen

import click

from ..helpers import env, filesystem
from ..helpers.packaging import get_packaging_backend
from ..helpers.process import ProcessResponse, run_interactive
from .commands import Commands
from .services import ServicesCommands
Expand Down Expand Up @@ -68,7 +69,7 @@ def update_statics_and_assets(self, force, flask_env='production'):
Needed here (parent) because is used by Assets and Install commands.
"""
# Commands
prefix = ['pipenv', 'run']
prefix = get_packaging_backend(self.cli_config).run_command()
collect_cmd = prefix + ['invenio', 'collect', '--verbose']
clean_create_cmd = prefix + ['invenio', 'webpack', 'clean', 'create']
create_cmd = prefix + ['invenio', 'webpack', 'create']
Expand Down Expand Up @@ -119,22 +120,26 @@ def signal_handler(sig, frame):
ServicesCommands(self.cli_config).ensure_containers_running()

click.secho("Starting celery worker...", fg="green")
worker = popen([
'pipenv', 'run', 'celery', '--app',
'invenio_app.celery', 'worker', '--beat', '--events',
'--loglevel', 'INFO'
])
command = get_packaging_backend(self.cli_config).run_command(
'celery', '--app', 'invenio_app.celery', 'worker',
'--beat', '--events', '--loglevel', 'INFO',
)
worker = Popen(command)

click.secho("Starting up local (development) server...", fg='green')
run_env = environ.copy()
run_env['FLASK_ENV'] = 'development' if debug else 'production'
run_env['INVENIO_SITE_UI_URL'] = f"https://{host}:{port}"
run_env['INVENIO_SITE_API_URL'] = f"https://{host}:{port}/api"
server = popen([
'pipenv', 'run', 'invenio', 'run', '--cert',
'docker/nginx/test.crt', '--key', 'docker/nginx/test.key',
'--host', host, '--port', port
], env=run_env)

command = get_packaging_backend(self.cli_config).run_command(
'invenio', 'run',
'--cert', 'docker/nginx/test.crt',
'--key', 'docker/nginx/test.key',
'--host', host,
'--port', port
)
server = Popen(command, env=run_env)

click.secho(
f'Instance running!\nVisit https://{host}:{port}',
Expand Down
Loading