diff --git a/developers_chamber/bin/pydev.py b/developers_chamber/bin/pydev.py index ee6ce4c..c3bdb3e 100644 --- a/developers_chamber/bin/pydev.py +++ b/developers_chamber/bin/pydev.py @@ -7,6 +7,7 @@ import click_completion import coloredlogs from dotenv import load_dotenv +from developers_chamber.utils import INSTALLED_MODULES for config_path in (Path.home(), Path.cwd()): if (config_path / ".pydev").exists() and (config_path / ".pydev").is_dir(): @@ -23,33 +24,28 @@ from developers_chamber.scripts.bitbucket import * from developers_chamber.scripts.docker import * -try: +if "aws" in INSTALLED_MODULES: from developers_chamber.scripts.ecs import * -except ImportError: - pass -from developers_chamber.scripts.git import * +if "git" in INSTALLED_MODULES: + from developers_chamber.scripts.git import * + from developers_chamber.scripts.gitlab import * -try: + +if "jira" in INSTALLED_MODULES: from developers_chamber.scripts.jira import * -except ImportError: - pass -from developers_chamber.scripts.project import * -try: +if "qa" in INSTALLED_MODULES: from developers_chamber.scripts.qa import * -except ImportError: - pass + from developers_chamber.scripts.sh import * -try: +if "slack" in INSTALLED_MODULES: from developers_chamber.scripts.slack import * -except ImportError: - pass -try: + +if "toggle" in INSTALLED_MODULES: from developers_chamber.scripts.toggle import * -except ImportError: - pass + from developers_chamber.scripts.version import * from developers_chamber.scripts.init_aliasses import * diff --git a/developers_chamber/project_utils.py b/developers_chamber/project_utils.py index bb9a9f4..107dc7a 100644 --- a/developers_chamber/project_utils.py +++ b/developers_chamber/project_utils.py @@ -12,11 +12,11 @@ from python_hosts.exception import UnableToWriteHosts from python_hosts.hosts import Hosts, HostsEntry -from developers_chamber.git_utils import get_current_branch_name from developers_chamber.utils import ( call_command, call_compose_command, pretty_time_delta, + INSTALLED_MODULES, ) LOGGER = logging.getLogger() @@ -25,7 +25,12 @@ ISSUE_KEY_PATTERN = re.compile(r"(?P[A-Z][A-Z]+-\d+).*") -try: +if ( + "jira" in INSTALLED_MODULES + and "git" in INSTALLED_MODULES + and "toggle" in INSTALLED_MODULES +): + from developers_chamber.git_utils import get_current_branch_name from developers_chamber.jira_utils import ( clean_issue_key, get_issue_fields, @@ -46,19 +51,21 @@ def _get_timer_comment(timer): return "Toggl #{}".format(timer["id"]) def start_task( - jira_url, - jira_username, - jira_api_key, - jira_project_key, - toggl_api_key, - toggl_workspace_id, - toggl_project_id, - issue_key, + jira_url, + jira_username, + jira_api_key, + jira_project_key, + toggl_api_key, + toggl_workspace_id, + toggl_project_id, + issue_key, ): running_timer = get_running_timer_data(toggl_api_key) if running_timer: # Do not stop timer if toggl workspace or project is invalid - check_workspace_and_project(toggl_api_key, toggl_workspace_id, toggl_project_id) + check_workspace_and_project( + toggl_api_key, toggl_workspace_id, toggl_project_id + ) if confirm("Timer is already running do you want to log it?"): stop_task(jira_url, jira_username, jira_api_key, toggl_api_key) @@ -67,18 +74,19 @@ def start_task( jira_url, jira_username, jira_api_key, issue_key, jira_project_key ) toggl_description = "{} {}".format(issue_key, issue_data.summary) - start_timer(toggl_api_key, toggl_description, toggl_workspace_id, toggl_project_id) + start_timer( + toggl_api_key, toggl_description, toggl_workspace_id, toggl_project_id + ) return 'Toggle was started with description "{}"'.format(toggl_description) - def create_or_update_pull_request( - jira_url, - jira_username, - jira_api_key, - bitbucket_username, - bitbucket_password, - bitbucket_destination_branch_name, - bitbucket_repository_name, + jira_url, + jira_username, + jira_api_key, + bitbucket_username, + bitbucket_password, + bitbucket_destination_branch_name, + bitbucket_repository_name, ): issue_key = clean_issue_key() issue_data = get_issue_fields(jira_url, jira_username, jira_api_key, issue_key) @@ -126,9 +134,9 @@ def sync_timer_to_jira( ): def get_timer_worklog(timer, issue_data): for worklog in issue_data.worklog.worklogs: - if hasattr(worklog, "comment") and worklog.comment == _get_timer_comment( - timer - ): + if hasattr( + worklog, "comment" + ) and worklog.comment == _get_timer_comment(timer): return worklog return None @@ -180,9 +188,6 @@ def get_timer_worklog(timer, issue_data): time_spend=timedelta(seconds=timer_seconds), comment=_get_timer_comment(timer), ) -except ImportError: - pass - def get_command_output(command): @@ -347,5 +352,3 @@ def compose_install( compose_run(project_name, compose_files, [container_name], command) compose_stop(project_name, compose_files, None) - - diff --git a/developers_chamber/scripts/project.py b/developers_chamber/scripts/project.py index 49a7a78..55af3cf 100644 --- a/developers_chamber/scripts/project.py +++ b/developers_chamber/scripts/project.py @@ -23,11 +23,9 @@ from developers_chamber.project_utils import ( copy_containers_dirs as copy_containers_dirs_func, ) -from developers_chamber.project_utils import ( - docker_clean, - set_hosts -) +from developers_chamber.project_utils import docker_clean, set_hosts from developers_chamber.scripts import cli +from developers_chamber.utils import INSTALLED_MODULES default_project_name = os.environ.get("PROJECT_DOCKER_COMPOSE_PROJECT_NAME") default_compose_files = ( @@ -459,7 +457,11 @@ def clean(all): docker_clean(all) -try: +if ( + "jira" in INSTALLED_MODULES + and "git" in INSTALLED_MODULES + and "toggle" in INSTALLED_MODULES +): from developers_chamber.jira_utils import get_branch_name from developers_chamber.bitbucket_utils import get_commit_builds from developers_chamber.project_utils import ( @@ -475,9 +477,10 @@ def clean(all): def task(): """Helpers to work with project task in Jira and Toggle""" - @task.command() - @click.option("--jira-url", help="Jira URL", type=str, required=True, default=jira_url) + @click.option( + "--jira-url", help="Jira URL", type=str, required=True, default=jira_url + ) @click.option( "--jira-username", help="Jira username", @@ -549,9 +552,10 @@ def start( ) ) - @task.command() - @click.option("--jira-url", help="Jira URL", type=str, required=True, default=jira_url) + @click.option( + "--jira-url", help="Jira URL", type=str, required=True, default=jira_url + ) @click.option( "--jira-username", help="Jira username", @@ -579,9 +583,10 @@ def stop(jira_url, jira_username, jira_api_key, toggl_api_key): """ click.echo(stop_task(jira_url, jira_username, jira_api_key, toggl_api_key)) - @task.command() - @click.option("--jira-url", help="Jira URL", type=str, required=True, default=jira_url) + @click.option( + "--jira-url", help="Jira URL", type=str, required=True, default=jira_url + ) @click.option( "--jira-username", help="Jira username", @@ -612,7 +617,12 @@ def stop(jira_url, jira_username, jira_api_key, toggl_api_key): ) @click.option("--issue-key", "-i", help="key of the task", type=str, required=True) def create_branch_from_issue( - jira_url, jira_username, jira_api_key, project_key, source_branch_name, issue_key + jira_url, + jira_username, + jira_api_key, + project_key, + source_branch_name, + issue_key, ): """ Create a new git branch from the source branch with name generated from the Jira issue. @@ -628,7 +638,6 @@ def create_branch_from_issue( ) ) - @task.command() @click.option( "--jira-url", "-u", help="Jira URL", type=str, required=True, default=jira_url @@ -704,9 +713,10 @@ def create_or_update_pull_request( ) ) - @task.command() - @click.option("--jira-url", help="Jira URL", type=str, required=True, default=jira_url) + @click.option( + "--jira-url", help="Jira URL", type=str, required=True, default=jira_url + ) @click.option( "--jira-username", help="Jira username", @@ -783,7 +793,6 @@ def sync_timer_log_to_issues( ) click.echo("Issue times were synchronized with the timer") - @task.command() @click.option( "--bitbucket-username", @@ -828,5 +837,3 @@ def print_last_commit_build( click.echo(" URL: {}\n".format(build_data["url"])) else: click.echo("Builds weren't found") -except ImportError: - pass \ No newline at end of file diff --git a/developers_chamber/utils.py b/developers_chamber/utils.py index 17d7501..dca9ad3 100644 --- a/developers_chamber/utils.py +++ b/developers_chamber/utils.py @@ -129,3 +129,23 @@ def _is_repo_clean(self): or self._get_unstaged() or self._get_repo().untracked_files ) + + +modules = { + "git": ["git"], + "jira": ["jira", "unidecode"], + "aws": ["boto3"], + "qa": ["isort", "flake8"], + "toggle": ["toggl"], + "slack": ["slack_sdk"], +} + +INSTALLED_MODULES = [] + +for module, requirements in modules.items(): + try: + for requirement in requirements: + __import__(requirement) + INSTALLED_MODULES.append(module) + except ModuleNotFoundError: + pass diff --git a/setup.py b/setup.py index 3657a9c..cccedb0 100644 --- a/setup.py +++ b/setup.py @@ -1,48 +1,52 @@ from setuptools import find_packages, setup setup( - name='developers-chamber', - version='0.1.8', - description='A small plugin which help with development, deployment, git', - keywords='django, skripts, easy live, git, bitbucket, Jira', - author='Druids team', - author_email='matllubos@gmail.com', - url='https://github.com/druids/django-project-info', - license='MIT', - package_dir={'developers_chamber': 'developers_chamber'}, + name="developers-chamber", + version="0.1.9", + description="A small plugin which help with development, deployment, git", + keywords="django, skripts, easy live, git, bitbucket, Jira", + author="Druids team", + author_email="matllubos@gmail.com", + url="https://github.com/druids/django-project-info", + license="MIT", + package_dir={"developers_chamber": "developers_chamber"}, include_package_data=True, packages=find_packages(), install_requires=[ - 'gitpython==3.1.30', - 'click>=8.1', - 'requests>=2.23.0', - 'python-dotenv==0.14.0', - 'python-hosts==0.4.6', - 'coloredlogs==10.0', - 'click-completion==0.5.2', - 'toml>=0.10.2', + "click>=8.1", + "requests>=2.23.0", + "python-dotenv==0.14.0", + "python-hosts==0.4.6", + "coloredlogs==10.0", + "click-completion==0.5.2", + "toml>=0.10.2", ], extras_require={ - 'slack': [ - 'slack-sdk==3.21.3', + "slack": [ + "slack-sdk==3.21.3", ], - 'aws': [ - 'boto3<2', + "aws": [ + "boto3<2", ], - 'qa': [ - 'isort==5.12.0', - 'flake8>=7.0.0', + "qa": [ + "isort==5.12.0", + "flake8>=7.0.0", ], - 'jira': [ - 'jira==2.0.0', - 'unidecode==1.1.1', + "jira": [ + "jira==2.0.0", + "unidecode==1.1.1", ], - 'toggle': [ - 'TogglPy==0.1.2', + "toggle": [ + "TogglPy==0.1.2", + ], + "git": [ + "gitpython==3.1.30", + ], + }, + entry_points={ + "console_scripts": [ + "pydev=developers_chamber.bin.pydev:cli", ] }, - entry_points={'console_scripts': [ - 'pydev=developers_chamber.bin.pydev:cli', - ]}, zip_safe=False, )