Skip to content

Commit

Permalink
feat: introduce CLI dcor develop, editable install of all extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jan 17, 2024
1 parent a32cd50 commit bf18519
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
0.9.0
- feat: perform compatible version check during update
- feat: introduce CLI `dcor develop`, editable install of all extensions
0.8.13
- update incompatible versions
- fix: ckan_uwsgi parser
Expand Down
2 changes: 2 additions & 0 deletions dcor_control/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click

from . import backup
from . import develop
from . import info
from . import inspect
from . import reset
Expand All @@ -13,6 +14,7 @@ def main():


main.add_command(backup.encrypted_database_backup)
main.add_command(develop.develop)
main.add_command(inspect.inspect)
main.add_command(info.status)
main.add_command(reset.reset)
Expand Down
59 changes: 59 additions & 0 deletions dcor_control/cli/develop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import os
import pathlib
import subprocess as sp
import uuid

import click

from ..inspect import reload_supervisord


@click.command()
@click.confirmation_option(
prompt="Are you sure you want migrate all DCOR-related Python packages "
"(CKAN extensions and helpers) to an editable install?")
def develop():
"""Migrate all DCOR CKAN extensions to git-based editable installs"""
for name in [
"ckanext-dc_log_view",
"ckanext-dc_serve",
"ckanext-dc_view",
"ckanext-dcor_depot",
"ckanext-dcor_schemas",
"ckanext-dcor_theme",
"dcor_shared",
"dcor_control",
]:
migrate_to_editable(name)

reload_supervisord()
click.secho('DONE', fg=u'green', bold=True)


def migrate_to_editable(name,
base_url="https://github.com/DCOR-dev/"):
"""Migrate all DCOR CKAN extensions to git-based editable installs"""
# make sure the `/dcor-repos` directory exists
repo_dir = pathlib.Path("/dcor-repos")
repo_dir.mkdir(parents=True, exist_ok=True)
# make sure we can write to it
test_file = repo_dir / f"write-check-{uuid.uuid4()}"
test_file.touch()
test_file.unlink()
# check whether the repository exists
pkg_dir = repo_dir / name
git_dir = pkg_dir / ".git"
wd = os.getcwd()

if not git_dir.is_dir():
# clone the repository
os.chdir(repo_dir)
sp.check_output(f"git clone {base_url}{name}", shell=True)
else:
# update the repository
os.chdir(pkg_dir)
sp.check_output("git pull", shell=True)

os.chdir(wd)
# install in editable mode
sp.check_output(f"pip install -e {pkg_dir}", shell=True)

0 comments on commit bf18519

Please sign in to comment.