Skip to content

Commit

Permalink
Precommit update
Browse files Browse the repository at this point in the history
  • Loading branch information
aboucaud committed Apr 9, 2024
1 parent 0730202 commit 42b6979
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 24 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check_style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
env:
SKIP: no-commit-to-branch
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/action@v2.0.0
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/action@v3.0.1
11 changes: 5 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.6.0
hooks:
- id: check-merge-conflict
- id: check-yaml
Expand All @@ -12,22 +12,21 @@ repos:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.13.2
hooks:
- id: isort
args: [--profile, black]
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
rev: v3.15.2
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 7.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-typing-imports==1.7.0]
args: ['--ignore=E501,E203,E731,W503']
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 24.3.0
hooks:
- id: black
1 change: 1 addition & 0 deletions galcheat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@
interest or reporting inconsistent values.
"""

from galcheat.helpers import available_surveys, get_survey # noqa
8 changes: 5 additions & 3 deletions galcheat/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ def main():
if args.use_rich:
try:
from rich.console import Console

console = Console()
use_rich = True
except ImportError as e:
except ImportError:
print(
"The rich library is not installed by default with galcheat.",
"In order to use rich display, please consider installing it using pip.",
"In order to use rich printing, please consider installing it using pip.",
"`python -m pip install rich`",
"\nDefaulting to classic display...\n"
"\nDefaulting to classic display...\n",
)

if args.survey_name is None:
Expand All @@ -57,6 +58,7 @@ def main():

if use_rich:
from galcheat.rich import display_references, display_survey

for survey in surveys:
console.print("")
console.print(display_survey(survey))
Expand Down
35 changes: 23 additions & 12 deletions galcheat/rich.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,35 @@ def _rich_survey_name(survey):
icon = _SATELLITE
else:
icon = _TELESCOPE

return f"{icon} [b]{survey.name}[/b]"


def display_survey(survey):
from rich.console import Group
from rich.panel import Panel
from rich.text import Text
from rich.console import Group

if not isinstance(survey, Survey):
survey = get_survey(survey)

survey_desc = Text(textwrap.fill(survey.description, 40), no_wrap=False, justify="left")
survey_desc = Text(
textwrap.fill(survey.description, 40), no_wrap=False, justify="left"
)

survey_info = _survey_table(survey)

filters_info = [
_filter_panel(survey.get_filter(filter))
for filter in survey.available_filters
_filter_panel(survey.get_filter(filter)) for filter in survey.available_filters
]

display_info = [survey_desc, "\n", survey_info, "\n", "[b]Filter info:"] + filters_info
display_info = [
survey_desc,
"\n",
survey_info,
"\n",
"[b]Filter info:",
] + filters_info

return Panel(
Group(*display_info),
Expand All @@ -42,6 +49,7 @@ def display_survey(survey):
title_align="center",
)


def _survey_table(survey):
from rich.table import Table

Expand All @@ -61,8 +69,8 @@ def _survey_table(survey):


def _filter_panel(filter):
from rich.table import Table
from rich.panel import Panel
from rich.table import Table

filter_info = Table.grid()
filter_info.add_column(justify="left")
Expand All @@ -82,23 +90,26 @@ def _filter_panel(filter):
title_align="left",
)


def display_references(survey):
from rich.table import Table
from rich.box import HEAVY_HEAD
from rich.table import Table

if not isinstance(survey, Survey):
survey = get_survey(survey)

ref_table = Table(
"Parameter", "Source", "Comments",
"Parameter",
"Source",
"Comments",
title=f"[b]{survey.name} references[/]",
# show_lines=True,
box=HEAVY_HEAD
box=HEAVY_HEAD,
)
for name, param in survey.references.items():
link = param["link"]
source = f"[u cyan link={link}]{link}"
comment = textwrap.fill(param["comment"], 60)
ref_table.add_row(name, source, comment)

return ref_table

0 comments on commit 42b6979

Please sign in to comment.