Skip to content

Commit

Permalink
Refactor, add config object
Browse files Browse the repository at this point in the history
  • Loading branch information
cidrblock committed Sep 6, 2023
1 parent 24b02a4 commit 6442480
Show file tree
Hide file tree
Showing 11 changed files with 411 additions and 367 deletions.
2 changes: 2 additions & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
bindep
bindir
bthornto
caplog
fileh
levelname
levelno
netcommon
pip4a
reqs
uninstallation
19 changes: 0 additions & 19 deletions src/pip4a/app.py

This file was deleted.

2 changes: 2 additions & 0 deletions src/pip4a/arg_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def parse() -> argparse.Namespace:
description="valid subcommands",
help="additional help",
dest="subcommand",
required=True,
)

parent_parser = argparse.ArgumentParser(add_help=False)
Expand All @@ -45,6 +46,7 @@ def parse() -> argparse.Namespace:
"-v",
"--verbose",
action="store_true",
default=False,
help="Increase output verbosity.",
)
parent_parser.add_argument(
Expand Down
144 changes: 0 additions & 144 deletions src/pip4a/base.py

This file was deleted.

26 changes: 12 additions & 14 deletions src/pip4a/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
from pathlib import Path
from typing import TYPE_CHECKING

from .app import App
from .arg_parser import parse
from .config import Config
from .installer import Installer
from .logger import ColoredFormatter, ExitOnExceptionHandler
from .uninstaller import UnInstaller
from .utils import get_galaxy


if TYPE_CHECKING:
Expand All @@ -27,7 +26,7 @@ class Cli:
def __init__(self: Cli) -> None:
"""Initialize the CLI and parse CLI args."""
self.args: Namespace
self.app: App
self.config: Config

def parse_args(self: Cli) -> None:
"""Parse the command line arguments."""
Expand All @@ -43,6 +42,7 @@ def init_logger(self: Cli) -> None:
)
ch.setFormatter(cf)
logger.addHandler(ch)

if self.args.verbose:
logger.setLevel(logging.DEBUG)
else:
Expand Down Expand Up @@ -92,23 +92,21 @@ def ensure_isolated(self: Cli) -> None:
def run(self: Cli) -> None:
"""Run the application."""
logger = logging.getLogger("pip4a")
collection_name, dependencies = get_galaxy()

self.app = App(
args=self.args,
collection_name=collection_name,
collection_dependencies=dependencies,
)
if "," in self.app.args.collection_specifier:
self.config = Config(args=self.args)

if "," in self.config.args.collection_specifier:
err = "Multiple optional dependencies are not supported at this time."
logger.critical(err)

if self.app.args.subcommand == "install":
installer = Installer(self.app)
if self.config.args.subcommand == "install":
self.config.init(create_venv=True)
installer = Installer(self.config)
installer.run()

if self.app.args.subcommand == "uninstall":
uninstaller = UnInstaller(self.app)
if self.config.args.subcommand == "uninstall":
self.config.init()
uninstaller = UnInstaller(self.config)
uninstaller.run()


Expand Down
Loading

0 comments on commit 6442480

Please sign in to comment.