From 7f19ab06fe3836169f652b8b42be35e43a444f63 Mon Sep 17 00:00:00 2001 From: Kyle Harrison Date: Sat, 22 May 2021 12:08:08 +0100 Subject: [PATCH] [BUG] Fix installation setup to avoid no module named cli errors (#128) Fix installation setup to avoid no module named cli errors --- .gitignore | 3 +++ README.md | 14 ++++++++------ cli-runner.py | 7 +++++++ docker-compose.yml | 2 +- reviews/__main__.py | 7 +++++++ reviews/cli/__init__.py | 0 cli.py => reviews/cli/main.py | 15 ++++++++------- reviews/controller.py | 6 +++--- reviews/layout/__init__.py | 4 ++-- reviews/layout/helpers.py | 4 ++-- reviews/layout/managers.py | 2 +- reviews/source_control/__init__.py | 4 ++-- reviews/source_control/client.py | 2 +- reviews/tasks.py | 6 +++--- setup.py | 4 ++-- 15 files changed, 50 insertions(+), 30 deletions(-) create mode 100755 cli-runner.py create mode 100644 reviews/__main__.py create mode 100644 reviews/cli/__init__.py rename cli.py => reviews/cli/main.py (74%) diff --git a/.gitignore b/.gitignore index ee5abf2..7e589f0 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,6 @@ ENV/ # editors .vscode/* .idea/* + +# mypy +.mypy_cache/ diff --git a/README.md b/README.md index 1a8f42a..ff4f0bd 100644 --- a/README.md +++ b/README.md @@ -44,28 +44,30 @@ $ python3 -m venv env $ source env/bin/activate (env)$ pip install -r requirements_dev.txt (env)$ pip install -r requirements.txt -(env)$ python cli.py dashboard +(env)$ python -m reviews dashboard ``` -If you wish to keep a copy of Reviews on your host system forever, you can install and run it using: +If you wish to keep a copy of Reviews on your host system, you can install and run it using: ```bash $ export REPOSITORY_CONFIGURATION="apoclyps/reviews" -$ pip install -e . -$ reviews dashboard +$ python -m venv env +$ source env/bin/activate +$ python -m pip install -e . +$ reviews -h ``` You can run the Reviews within Docker: ```bash -docker-compose build cli && docker-compose run --rm cli python cli.py dashboard +docker-compose build cli && docker-compose run --rm cli python -m reviews dashboard ``` To build an image and run that image with all of the necessary dependencies using the following commands: ```bash $ docker-compose build cli -$ docker-compose run --rm cli python cli.py dashboard +$ docker-compose run --rm cli python -m reviews dashboard ``` For instructions on setting up a development enviroment outside of Docker, checkout the [wiki](https://github.com/apoclyps/reviews/wiki/Development-Enviromnent). diff --git a/cli-runner.py b/cli-runner.py new file mode 100755 index 0000000..2010cfb --- /dev/null +++ b/cli-runner.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from reviews.cli.main import main + +if __name__ == "__main__": + main() diff --git a/docker-compose.yml b/docker-compose.yml index 608962c..2ce9a82 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "3.7" services: cli: &cli build: . - command: python cli.py dashboard + command: python -m reviews dashboard working_dir: /usr/src/app/ environment: - DEBUG=true diff --git a/reviews/__main__.py b/reviews/__main__.py new file mode 100644 index 0000000..7fcb13e --- /dev/null +++ b/reviews/__main__.py @@ -0,0 +1,7 @@ +# -*- coding: utf-8 -*- +"""Reviews CLI - Main script.""" + +from .cli.main import main + +if __name__ == "__main__": + main() diff --git a/reviews/cli/__init__.py b/reviews/cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cli.py b/reviews/cli/main.py similarity index 74% rename from cli.py rename to reviews/cli/main.py index f56aa98..15c8a06 100644 --- a/cli.py +++ b/reviews/cli/main.py @@ -2,24 +2,24 @@ import asyncclick as click -from reviews.tasks import render, single_render -from reviews.version import __version__ +from ..tasks import render, single_render +from ..version import __version__ CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"]) @click.group(context_settings=CONTEXT_SETTINGS) @click.version_option(__version__, "-v", "--version", message="version %(version)s") -async def main(): +async def cli() -> None: """Reviews - A terminal UI Dashboard for monitoring code review requests.\n For feature requests or bug reports: https://github.com/apoclyps/reviews/issues """ -@main.command(help="Visualize code review requests as a Dashboard") +@cli.command(help="Visualize code review requests as a Dashboard") @click.option("-r", "--reload/--no-reload", default=True, is_flag=True) -async def dashboard(reload): +async def dashboard(reload: bool) -> None: """ Command:\n reviews dashboard @@ -40,5 +40,6 @@ async def dashboard(reload): single_render() -if __name__ == "__main__": - asyncio.run(main()) +def main() -> None: + """Entry point to CLI""" + asyncio.run(cli()) diff --git a/reviews/controller.py b/reviews/controller.py index 7f8433b..89d7bbc 100644 --- a/reviews/controller.py +++ b/reviews/controller.py @@ -3,9 +3,9 @@ from github.PullRequest import PullRequest as ghPullRequest from rich.table import Table -from reviews import config -from reviews.layout import render_pull_request_table -from reviews.source_control import GithubAPI, Label, PullRequest +from . import config +from .layout import render_pull_request_table +from .source_control import GithubAPI, Label, PullRequest class PullRequestController: diff --git a/reviews/layout/__init__.py b/reviews/layout/__init__.py index cebe143..15090c5 100644 --- a/reviews/layout/__init__.py +++ b/reviews/layout/__init__.py @@ -1,8 +1,8 @@ -from reviews.layout.helpers import ( # NOQA: F401 +from ..layout.helpers import ( # NOQA: F401 generate_layout, generate_log_table, generate_progress_tracker, generate_tree_layout, render_pull_request_table, ) -from reviews.layout.managers import RenderLayoutManager # NOQA: F401 +from ..layout.managers import RenderLayoutManager # NOQA: F401 diff --git a/reviews/layout/helpers.py b/reviews/layout/helpers.py index 7577538..9b380bb 100644 --- a/reviews/layout/helpers.py +++ b/reviews/layout/helpers.py @@ -9,8 +9,8 @@ from rich.table import Table from rich.tree import Tree -from reviews.config import get_label_colour_map -from reviews.source_control import PullRequest +from ..config import get_label_colour_map +from ..source_control import PullRequest def render_pull_request_table( diff --git a/reviews/layout/managers.py b/reviews/layout/managers.py index 6c6c134..a6c296d 100644 --- a/reviews/layout/managers.py +++ b/reviews/layout/managers.py @@ -5,7 +5,7 @@ from rich.panel import Panel from rich.table import Table -from reviews.layout.components import Header +from ..layout.components import Header console = Console() diff --git a/reviews/source_control/__init__.py b/reviews/source_control/__init__.py index bd357a7..3c4b4c7 100644 --- a/reviews/source_control/__init__.py +++ b/reviews/source_control/__init__.py @@ -1,2 +1,2 @@ -from reviews.source_control.client import GithubAPI # NOQA: F401 -from reviews.source_control.models import Label, PullRequest # NOQA: F401 +from ..source_control.client import GithubAPI # NOQA: F401 +from ..source_control.models import Label, PullRequest # NOQA: F401 diff --git a/reviews/source_control/client.py b/reviews/source_control/client.py index 2ef7c94..8e227c4 100644 --- a/reviews/source_control/client.py +++ b/reviews/source_control/client.py @@ -4,7 +4,7 @@ from github.PullRequest import PullRequest from github.Repository import Repository -from reviews import config +from .. import config class GithubAPI: diff --git a/reviews/tasks.py b/reviews/tasks.py index f654a30..ac777e5 100644 --- a/reviews/tasks.py +++ b/reviews/tasks.py @@ -7,9 +7,9 @@ from rich.live import Live from rich.panel import Panel -from reviews import config -from reviews.controller import PullRequestController -from reviews.layout import ( +from . import config +from .controller import PullRequestController +from .layout import ( RenderLayoutManager, generate_layout, generate_log_table, diff --git a/setup.py b/setup.py index e5d8330..fecaaf3 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ def _requires_from_file(filename): setup( name="reviews", - packages=find_namespace_packages(include=["reviews.*"]), + packages=find_namespace_packages(include=["*"]), version="0.1.7", license="MIT", description=( @@ -26,7 +26,7 @@ def _requires_from_file(filename): download_url="https://pypi.org/project/reviews/", keywords=["Reviews", "pull request review"], install_requires=_requires_from_file("requirements.txt"), - entry_points={"console_scripts": ["reviews = cli:main"]}, + entry_points={"console_scripts": ["reviews = reviews.cli.main:main"]}, classifiers=[ "Development Status :: 3 - Alpha", "Environment :: Console",