Skip to content

Commit b365eac

Browse files
committed
feat: linting, formating and CI updates
1 parent 5f281ac commit b365eac

13 files changed

Lines changed: 113 additions & 66 deletions

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
branches:
55
- main
66
tags:
7-
- '**'
7+
- "**"
88
release:
99
types:
1010
- published

.github/workflows/python_lint_and_test.yaml

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ jobs:
2020
uses: actions/setup-python@v5
2121
with:
2222
python-version: ${{ matrix.python-version }}
23-
cache: 'pip'
24-
cache-dependency-path: '**/requirements.txt'
23+
cache: "pip"
24+
cache-dependency-path: "**/requirements.txt"
2525
# architecture: x64
2626
- name: Install dependencies
2727
run: |
@@ -32,16 +32,8 @@ jobs:
3232
- name: Run python style and linting tools
3333
run: |
3434
err=0
35-
echo autoflake:
36-
autoflake --check-diff . || err=$?
37-
echo black:
38-
black --check . || err=$?
39-
echo docformatter:
40-
docformatter . || err=$?
41-
echo flake8:
42-
flake8 . || err=$?
43-
echo isort:
44-
isort --check . || err=$?
35+
echo pre-commit:
36+
pre-commit run --all-files --hook-stage pre-commit|| err=$?
4537
exit $err
4638
- name: Run tests with coverage
4739
run: |

.github/workflows/requirements.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
autoflake
2-
black
31
coverage[toml]
4-
docformatter
5-
flake8
6-
isort
2+
pre-commit
3+

README.md

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# `logilica-cli`
22

33
`logilica-cli` is a command-line tool which provides CLI access to the Logilica
4-
UI. The tool currently provides two subcommands. The first exports charts and
4+
UI. The tool currently provides two subcommands. The first exports charts and
55
text from Logilica reports and makes them available in a variety of formats,
6-
including HTML, Markdown, and as a Google Docs document. The second is used to
6+
including HTML, Markdown, and as a Google Docs document. The second is used to
77
configure Logilica integrations, supporting a "configuration as code" approach.
88

99
The tool is configured via a YAML file which contains tool configuration
10-
options as well as options for exporting data or configuring Logilica. By
10+
options as well as options for exporting data or configuring Logilica. By
1111
default, the file `logica-cli.yaml` in the current directory is used, but an
1212
alternate path can be specified on the command line.
1313

14-
For export, the configuration includes a list of teams. For each team, it
15-
specifies a list of Logilica dashboards and the team's Jira project. For each
14+
For export, the configuration includes a list of teams. For each team, it
15+
specifies a list of Logilica dashboards and the team's Jira project. For each
1616
dashboard, it specifies the name of an output file (which must not conflict
1717
with any other team's dashboards' output files) and possibly other attributes.
1818

@@ -29,32 +29,31 @@ the configuration file.
2929

3030
Credentials for accessing Logilica are provided by command line options or by
3131
the environment variables, `LOGILICA_DOMAIN`, `LOGILICA_EMAIL`, and
32-
`LOGILICA_PASSWORD`. (Note to the Developer Practices Team: the appropriate
32+
`LOGILICA_PASSWORD`. (Note to the Developer Practices Team: the appropriate
3333
values for the bot accounts can be obtained from the Bitwarden vault; users
3434
with admin privileges can also create their own username/password credentials
35-
using the Logilica UI.) For interactive use, OAuth or SSO credentials can be
35+
using the Logilica UI.) For interactive use, OAuth or SSO credentials can be
3636
used. The tool normally runs in "headless" mode; however, in order to enable
3737
the user to perform an SSO login, the tool opens a browser window during the
38-
run. (You should not interact with this window unless it prompts for your SSO
38+
run. (You should not interact with this window unless it prompts for your SSO
3939
credentials; otherwise, you are likely to disrupt the functioning of the tool.)
4040

41-
To run the tool, check out the Git repo and run:
42-
```pip install -r requirements.txt .```
41+
To install the tool, check out the Git repo and run:
42+
43+
```
44+
pip install -r requirements.txt .
45+
playwright install chromium
46+
```
47+
4348
We recommend doing this inside a [virtual environment](https://docs.python.org/3/library/venv.html),
44-
which uses Python 3.12+. (If you are doing development on the tool, you may want
45-
to specify `-e` in the `pip install` command.) After installing the tool, you also
46-
need to install the browser which it uses to interact with the Logilica web UI:
47-
```playwright install chromium``` (For details on debugging the web interactions,
48-
see the `--pwdebug` option in the command help, below, and the
49-
[Playwright documentation](https://playwright.dev/python/docs/running-tests).)
49+
which uses Python 3.12+.
5050

5151
The PDF files containing the downloaded Logilica reports are stored in a
5252
temporary directory which is created if it does not exist; if it was created by
53-
the tool, the directory is deleted after execution is complete. By default,
54-
the directory is named `lwr_downloaded_pdfs`, and it is created in the current
55-
directory, but an alternate path can be specified on the command line.
53+
the tool, the directory is deleted after execution is complete.
5654

5755
Help is available on the command line:
56+
5857
```text
5958
Usage: logilica-cli [OPTIONS] COMMAND [ARGS]...
6059
@@ -80,6 +79,7 @@ Commands:
8079
```
8180

8281
```text
82+
logilica-cli weekly-report --help
8383
Usage: logilica-cli weekly-report [OPTIONS]
8484
8585
Downloads and processes weekly report for teams specified in the
@@ -90,9 +90,11 @@ Options:
9090
Name [env var: LOGILICA_DOMAIN; required]
9191
-t, --downloads-temp-dir DIRECTORY
9292
Path to a directory to receive downloaded
93-
files (will be created if it doesn't exist;
94-
will be deleted if created) [default:
95-
./lwr_downloaded_pdfs]
93+
files (if unspecified, a temporary directory
94+
will be used; otherwise, the specified
95+
directory will be created if it doesn't
96+
exist; if the directory is created by the
97+
tool, it will be deleted after the run)
9698
-I, --input [logilica|local] Input source -- download from Logilica or
9799
use pre-downloaded files [default:
98100
logilica]
@@ -161,7 +163,35 @@ Options:
161163
var: LOGILICA_EMAIL]
162164
--help Show this message and exit.
163165
```
166+
164167
Some dashboards can be quite slow to load into the UI, so, if you are running
165168
the tool interactively and wish to track its progress, add a `-v` to the command
166-
line to see informational messages. (If you are debugging or just nosy, adding
169+
line to see informational messages. (If you are debugging or just nosy, adding
167170
a _second_ `-v` will add debugging messages to the output.)
171+
172+
## Development
173+
174+
If you are doing development on the tool, you may want to specify `-e` in the `pip install` command to install it in editable mode.
175+
This means that you can make changes to the package's source code and those changes will be reflected in your project without having to reinstall the package.
176+
177+
For details on debugging the web interactions, see the `--pwdebug` option in the command help and the [Playwright documentation](https://playwright.dev/python/docs/running-tests).
178+
179+
### Linting and formatting rules
180+
181+
This project uses `pre-commit` to handle linting and formatting. The `pre-commit` tool reads its configuration from [`.pre-commit-config.yaml`](./.pre-commit-config.yaml)` and the configuration options for the individual linters and formatters can be found in the [`pyproject.toml`](./pyproject.toml) file.
182+
The same configuration is used in CI.
183+
184+
To install and execute it locally, follow these steps:
185+
186+
```
187+
pip install pre-commit
188+
pre-commit install
189+
pre-commit run --all-files --hook-stage [pre-commit|manual]
190+
```
191+
192+
If you run `pre-commit` stage, you can check your files, if you run `manual` stage, it will modify your files to correct problems it finds.
193+
194+
### Enabling Red Hat InfoSec plugin
195+
196+
If you are developing locally within Red Hat, you should enable Red Hat InfoSec plugin. You can do that by uncommenting appropriate lines in `.pre-commit-config.yaml` file.
197+
Make sure that you don't commit that change back upstream, as it would break the CI.

logilica_cli/__main__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@
4242
"-o",
4343
"output_dir_path",
4444
type=click.Path(
45-
writable=True, file_okay=False, path_type=pathlib.Path, resolve_path=True
45+
writable=True,
46+
file_okay=False,
47+
path_type=pathlib.Path,
48+
resolve_path=True,
4649
),
4750
default=DEFAULT_OUTPUT_DIR,
4851
show_default=True,

logilica_cli/page_settings.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class SettingsPage:
2626
AVAILABLE_LIST_TIMEOUT = 54000
2727

2828
def __init__(self, page: Page):
29-
3029
self.page = page
3130
# UI elements for public access
3231
self.add_public_repository_dialog_button = page.get_by_role(
@@ -62,7 +61,9 @@ def open_integration_configuration(
6261
"""
6362

6463
logging.debug(
65-
"Opening integration '%s', connector type:'%s'", integration, connector
64+
"Opening integration '%s', connector type:'%s'",
65+
integration,
66+
connector,
6667
)
6768
self.page.locator("div.items-center").filter(has_text=connector).filter(
6869
has_text=integration

logilica_cli/pdf_convert.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ def to_format_multiple(
9292
teams: dict[str, dict[str, Any]],
9393
embed_images: bool = True,
9494
) -> int:
95-
9695
total = 0
9796
for team, dashboards in teams.items():
9897
for dashboard, options in dashboards["team_dashboards"].items():

logilica_cli/pdf_extract.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111

1212
class PDFExtract:
13-
1413
def __init__(self, scale: float = 1.0):
1514
"""Encapsulation of PDF extraction."""
1615

logilica_cli/update_gdoc.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ def upload_doc(doc: str, creds: Credentials, config: dict[str, any]) -> str:
101101
if status:
102102
logging.debug("Uploaded %d%%.", int(status.progress() * 100))
103103
logging.debug(
104-
'File "%s" with ID "%s" has been uploaded.', filename, response.get("id")
104+
'File "%s" with ID "%s" has been uploaded.',
105+
filename,
106+
response.get("id"),
105107
)
106108

107109
except HttpError as error:
@@ -180,7 +182,13 @@ def get_app_credentials_file(config: dict[str, any]) -> Path:
180182

181183

182184
GPP_SIGNATURE = Callable[
183-
[Optional[str], Optional[Union[str, Literal[False]]], Optional[str], bool, bool],
185+
[
186+
Optional[str],
187+
Optional[Union[str, Literal[False]]],
188+
Optional[str],
189+
bool,
190+
bool,
191+
],
184192
Path,
185193
]
186194

logilica_cli/weekly_report.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ def weekly_report(
167167
with LogilicaSession(oauth, logilica_credentials) as page:
168168
dashboard_page = DashboardPage(page=page)
169169
dashboard_page.download_team_dashboards(
170-
teams=configuration["teams"], base_dir_path=downloads_temp_dir
170+
teams=configuration["teams"],
171+
base_dir_path=downloads_temp_dir,
171172
)
172173

173174
if output == "pdf":
@@ -178,7 +179,12 @@ def weekly_report(
178179
download_dir_path=downloads_temp_dir,
179180
scale=scale,
180181
)
181-
if output in ("markdown", "html", "markdown-with-refs", "html-with-refs"):
182+
if output in (
183+
"markdown",
184+
"html",
185+
"markdown-with-refs",
186+
"html-with-refs",
187+
):
182188
o_format = output.removesuffix("-with-refs")
183189
embed_images = not output.endswith("-with-refs")
184190
converter.to_format_multiple(
@@ -188,7 +194,8 @@ def weekly_report(
188194
)
189195
else:
190196
pdf_items = PDFExtract(scale=scale).get_pdf_objects(
191-
teams=configuration["teams"], download_dir_path=downloads_temp_dir
197+
teams=configuration["teams"],
198+
download_dir_path=downloads_temp_dir,
192199
)
193200
if output == "images-only":
194201
converter.to_images(pdf_items=pdf_items)

0 commit comments

Comments
 (0)