Skip to content

Commit a284f3b

Browse files
authored
Format CLI output with rich. (#74)
1 parent 42966a3 commit a284f3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+572
-522
lines changed

.conda/meta.yaml

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ source:
1212
build:
1313
noarch: python
1414
number: 0
15+
skip: true # [py36]
1516
script: {{ PYTHON }} setup.py install --single-version-externally-managed --record record.txt
1617
entry_points:
1718
- pytask = _pytask.cli:cli
@@ -24,15 +25,15 @@ requirements:
2425
- setuptools
2526

2627
run:
27-
- python >=3.6
28+
- python
2829

2930
- attrs >=17.4.0
3031
- click
3132
- click-default-group
3233
- networkx
3334
- pluggy
3435
- pony >=0.7.13
35-
- colorama # [win]
36+
- rich
3637

3738
test:
3839
imports:

.github/workflows/continuous-integration-workflow.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
fail-fast: false
2020
matrix:
2121
os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
22-
python-version: ['3.6', '3.7', '3.8', '3.9']
22+
python-version: ['3.7', '3.8', '3.9']
2323

2424
steps:
2525
- uses: actions/checkout@v2

.pre-commit-config.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@ repos:
44
hooks:
55
- id: check-added-large-files
66
args: ['--maxkb=25']
7+
- id: check-case-conflict
78
- id: check-merge-conflict
9+
- id: check-vcs-permalinks
810
- id: check-yaml
911
exclude: meta.yaml
1012
- id: debug-statements
1113
exclude: (debugging\.py)
1214
- id: end-of-file-fixer
15+
- id: fix-byte-order-marker
16+
- id: forbid-new-submodules
17+
- id: mixed-line-ending
18+
- id: no-commit-to-branch
19+
args: [--branch, main]
20+
- id: trailing-whitespace
1321
- repo: https://github.com/pre-commit/pygrep-hooks
1422
rev: v1.8.0 # Use the ref you want to point at
1523
hooks:

README.rst

+7-10
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,14 @@ projects. Its features include:
7777
.. end-features
7878
7979
80-
Why do I need a build system?
81-
-----------------------------
82-
83-
Read the `section in the documentation <https://pytask-dev.readthedocs.io/en/latest/
84-
explanations/why_do_i_need_a_build_system.html>`_ if you do not know or are not
85-
convinced that you need a build system.
86-
87-
8880
Installation
8981
------------
9082

9183
.. start-installation
9284
93-
pytask is available on `PyPI <https://pypi.org/project/pytask>`_ and on `Anaconda.org
94-
<https://anaconda.org/conda-forge/pytask>`_. Install the package with
85+
pytask is available on `PyPI <https://pypi.org/project/pytask>`_ for Python >= 3.6.1 and
86+
on `Anaconda.org <https://anaconda.org/conda-forge/pytask>`_ for Python >= 3.7. Install
87+
the package with
9588

9689
.. code-block:: console
9790
@@ -101,6 +94,10 @@ pytask is available on `PyPI <https://pypi.org/project/pytask>`_ and on `Anacond
10194
10295
$ conda install -c conda-forge pytask
10396
97+
Color support is automatically available on non-Windows platforms. On Windows, please,
98+
use `Windows Terminal <https://github.com/microsoft/terminal>`_ which can be, for
99+
example, installed via the `Microsoft Store <https://aka.ms/terminal>`_.
100+
104101
.. end-installation
105102
106103
Usage

docs/changes.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ chronological order. Releases follow `semantic versioning <https://semver.org/>`
66
all releases are available on `PyPI <https://pypi.org/project/pytask>`_ and
77
`Anaconda.org <https://anaconda.org/conda-forge/pytask>`_.
88

9-
10-
0.0.14 - 2021-xx-xx
9+
0.0.14 - 2021-03-23
1110
-------------------
1211

12+
- :gh:`74` reworks the formatting of the command line output by using ``rich``. Due to
13+
the new dependency, support for pytask with Python <3.6.1 on PyPI and with Python <3.7
14+
on Anaconda will end.
1315
- :gh:`76` fixes :gh:`75` which reports a bug when a closest ancestor cannot be found to
1416
shorten node names in the CLI output. Instead a common ancestor is used.
1517

docs/explanations/index.rst

-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ systems in general as well as its design.
77
.. toctree::
88
:maxdepth: 1
99

10-
why_do_i_need_a_build_system
1110
build_systems
1211
pluggy

docs/explanations/why_do_i_need_a_build_system.rst

-63
This file was deleted.

docs/index.rst

+1-6
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@ Features
1414
:end-before: end-features
1515

1616

17-
Installation
18-
------------
19-
20-
.. include:: ../README.rst
21-
:start-after: start-installation
22-
:end-before: end-installation
17+
To install pytask, follow this :doc:`tutorial <tutorials/how_to_install>`.
2318

2419

2520
Documentation

docs/rtd_environment.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
channels:
22
- conda-forge
3+
- nodefaults
34

45
dependencies:
5-
- python >= 3.6
6+
- python >= 3.7
67
- pip
78
- furo
89
- ipython
@@ -22,6 +23,7 @@ dependencies:
2223
- pluggy
2324
- pony >=0.7.13
2425
- pexpect
26+
- rich
2527

2628
- pip:
2729
- -e ../

docs/tutorials/how_to_install.rst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
How to install pytask
2+
=====================
3+
4+
.. include:: ../../README.rst
5+
:start-after: start-installation
6+
:end-before: end-installation

docs/tutorials/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ project. Start here if you are a new user.
77
.. toctree::
88
:maxdepth: 1
99

10+
how_to_install
1011
how_to_set_up_a_project
1112
how_to_write_a_task
1213
how_to_define_dependencies_products

environment.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ name: pytask
22

33
channels:
44
- conda-forge
5+
- nodefaults
56

67
dependencies:
7-
- python>=3.6
8+
- python >=3.7
89
- pip
910

1011
# Conda
@@ -19,6 +20,7 @@ dependencies:
1920
- networkx
2021
- pluggy
2122
- pony >=0.7.13
23+
- rich
2224

2325
# Misc
2426
- black
@@ -29,8 +31,6 @@ dependencies:
2931
- pytest
3032
- pytest-cov
3133
- tox-conda
32-
- versioneer
33-
- virtualenv=20.0.33
3434

3535
# Documentation
3636
- furo

setup.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
"Operating System :: MacOS :: MacOS X",
4141
"Operating System :: Microsoft :: Windows",
4242
"Operating System :: POSIX",
43-
"Programming Language :: Python :: 3",
44-
"Programming Language :: Python :: 3 :: Only",
4543
"Programming Language :: Python :: 3.6",
4644
"Programming Language :: Python :: 3.7",
4745
"Programming Language :: Python :: 3.8",
@@ -56,9 +54,9 @@
5654
"networkx",
5755
"pluggy",
5856
"pony >= 0.7.13",
59-
"colorama;platform_system=='Windows'",
57+
"rich",
6058
],
61-
python_requires=">=3.6",
59+
python_requires=">=3.6.1",
6260
entry_points={"console_scripts": ["pytask=_pytask.cli:cli"]},
6361
packages=find_packages(where="src"),
6462
package_dir={"": "src"},

src/_pytask/clean.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22
import itertools
33
import shutil
44
import sys
5-
import traceback
65
from pathlib import Path
76

87
import attr
98
import click
109
from _pytask.config import hookimpl
1110
from _pytask.config import IGNORED_TEMPORARY_FILES_AND_FOLDERS
11+
from _pytask.console import console
12+
from _pytask.enums import ColorCode
1213
from _pytask.enums import ExitCode
1314
from _pytask.exceptions import CollectionError
15+
from _pytask.path import find_common_ancestor
16+
from _pytask.path import relative_to
1417
from _pytask.pluginmanager import get_plugin_manager
1518
from _pytask.session import Session
1619
from _pytask.shared import get_first_non_none_value
20+
from rich.traceback import Traceback
1721

1822

1923
_HELP_TEXT_MODE = (
@@ -80,7 +84,7 @@ def clean(**config_from_cli):
8084
except Exception:
8185
session = Session({}, None)
8286
session.exit_code = ExitCode.CONFIGURATION_FAILED
83-
traceback.print_exception(*sys.exc_info())
87+
console.print(Traceback.from_exception(*sys.exc_info()))
8488

8589
else:
8690
try:
@@ -92,38 +96,48 @@ def clean(**config_from_cli):
9296
unknown_paths = _find_all_unknown_paths(
9397
session, known_paths, include_directories
9498
)
99+
common_ancestor = find_common_ancestor(
100+
*unknown_paths, *session.config["paths"]
101+
)
95102

96103
if unknown_paths:
97104
targets = "Files"
98105
if session.config["directories"]:
99106
targets += " and directories"
100-
click.echo(f"\n{targets} which can be removed:\n")
107+
console.print(f"\n{targets} which can be removed:\n")
101108
for path in unknown_paths:
109+
short_path = relative_to(path, common_ancestor)
102110
if session.config["mode"] == "dry-run":
103-
click.echo(f"Would remove {path}")
111+
console.print(f"Would remove {short_path}")
104112
else:
105113
should_be_deleted = session.config[
106114
"mode"
107115
] == "force" or click.confirm(
108-
f"Would you like to remove {path}?"
116+
f"Would you like to remove {short_path}?"
109117
)
110118
if should_be_deleted:
111119
if not session.config["quiet"]:
112-
click.echo(f"Remove {path}")
120+
console.print(f"Remove {short_path}")
113121
if path.is_dir():
114122
shutil.rmtree(path)
115123
else:
116124
path.unlink()
117125
else:
118-
click.echo("\nThere are no files and directories which can be deleted.")
126+
console.print()
127+
console.print(
128+
"There are no files and directories which can be deleted."
129+
)
119130

120-
click.echo("\n" + "=" * config["terminal_width"])
131+
console.print()
132+
console.rule(style=None)
121133

122134
except CollectionError:
123135
session.exit_code = ExitCode.COLLECTION_FAILED
136+
console.rule(style=ColorCode.FAILED)
124137

125138
except Exception:
126-
traceback.print_exception(*sys.exc_info())
139+
console.print(Traceback.from_exception(*sys.exc_info()))
140+
console.rule(style=ColorCode.FAILED)
127141
session.exit_code = ExitCode.FAILED
128142

129143
sys.exit(session.exit_code)

0 commit comments

Comments
 (0)