Skip to content

Commit

Permalink
Remove rich as a dependency (#6)
Browse files Browse the repository at this point in the history
It was only used to make the CLI output pretty but it's not worth the
extra dependency just for that. Keep this simple.
  • Loading branch information
leouieda authored Jan 10, 2022
1 parent 7825684 commit f93fd7c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 36 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ The current implementation is a proof-of-concept and has some limitations:
Of course, all of these could be addressed if there is enough interest.
Issues and PRs are welcome!

## Dependencies

We use the following dependencies (see `setup.cfg` for specific version
constraints):

* [click](https://click.palletsprojects.com) for building the command-line
interface.
* [tomli](https://github.com/hukkin/tomli) to parse the TOML configuration
files.

## Contacting Us

Find out more about how to reach us at
Expand Down
51 changes: 17 additions & 34 deletions dependente/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
Uses click to define a CLI around the ``main`` function.
"""
import sys
import traceback

import click
import rich.console

from .converters import pin_to_oldest
from .parsers import (
Expand Down Expand Up @@ -59,39 +59,33 @@ def main(source, oldest, verbose):
* setup.cfg (install_requires and options.extras_require)
"""
reporter = Reporter(verbose, style="bold blue", style_error="bold red")
reporter = Reporter(verbose)
readers = {"setup.cfg": read_setup_cfg, "pyproject.toml": read_pyproject_toml}
reporter.echo(f":rocket: Extracting dependencies: {source}")
reporter.echo(f"Extracting dependencies: {source}")
try:
sources = parse_sources(source)
dependencies = []
for config_file in sources:
if not sources[config_file]:
continue
reporter.echo(f":mag_right: Parsing {config_file}")
reporter.echo(f"Parsing {config_file}")
config = readers[config_file]()
dependencies_found = parse_requirements(config, sources[config_file])
reporter.echo(f" - {count(dependencies_found)} dependencies found")
reporter.echo(f" - {count(dependencies_found)} dependencies found")
dependencies.extend(dependencies_found)
if oldest:
reporter.echo(
":mantelpiece_clock: Pinning dependencies to their oldest versions"
)
reporter.echo("Pinning dependencies to their oldest versions")
dependencies = pin_to_oldest(dependencies)
reporter.echo(
f":printer: Printing {count(dependencies)} dependencies to the "
"standard output stream",
f"Printing {count(dependencies)} dependencies to standard output",
)
for line in dependencies:
click.echo(line)
reporter.echo(":partying_face: [bold green]Done![/] :partying_face:")
sys.exit(0)
reporter.echo("Done!")
except Exception:
reporter.console.print_exception()
reporter.error(
"\n:fire::fire::fire: Error encountered while processing. "
"See the message and traceback above. :fire::fire::fire:"
)
reporter.error("\nError encountered while processing:\n")
reporter.error(traceback.format_exc())
reporter.error("Oh no! Something went wrong. See the messages above.")
sys.exit(1)


Expand All @@ -105,35 +99,24 @@ def count(dependencies):

class Reporter:
"""
Small wrapper around :class:`rich.console.Console` to control verbosity.
Small wrapper around click.echo to control verbosity.
Use *echo* to print according to verbosity settings and *error* to always
print regardless of settings.
"""

def __init__(self, verbose, style, style_error):
def __init__(self, verbose):
self.verbose = verbose
self.style = style
self.style_error = style_error
self.console = rich.console.Console(stderr=True, highlight=False)

def _print(self, message, style, **kwargs):
"""
Print the message with the given style using rich.
"""
arguments = {"style": style}
arguments.update(kwargs)
self.console.print(message, **arguments)

def echo(self, message, **kwargs):
def echo(self, message):
"""
Print the message if verbosity is enabled.
"""
if self.verbose:
self._print(message, style=self.style, **kwargs)
click.echo(message, err=True)

def error(self, message, **kwargs):
def error(self, message):
"""
Print the message regardless of verbosity settings.
"""
self._print(message, style=self.style_error, **kwargs)
click.echo(message, err=True)
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ dependencies:
- make
# Run-time
- click>=8.0.0,<9.0.0
- rich>=9.6.0,<11.0.0
- tomli>=1.0.0,<3.0.0
# Building (excluding setuptools)
- build
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ include_package_data = True
python_requires = >=3.6
install_requires =
click>=8.0.0,<9.0.0
rich>=9.6.0,<11.0.0
tomli>=1.1.0,<3.0.0

[options.package_data]
Expand Down

0 comments on commit f93fd7c

Please sign in to comment.