Skip to content

Commit 50105c9

Browse files
authored
Merge pull request #20 from dalager/lint-test-action-improvement
Updating lint/test CI pipeline
2 parents a51a97f + 80c7fa9 commit 50105c9

File tree

10 files changed

+556
-174
lines changed

10 files changed

+556
-174
lines changed

.github/workflows/python-app.yml

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,77 @@ jobs:
1717
python-version: ["3.10", "3.11", "3.12"]
1818

1919
steps:
20+
# 1. Check out the repository
2021
- uses: actions/checkout@v4
22+
23+
# 2. Set up Python environment
2124
- name: Set up Python ${{ matrix.python-version }}
2225
uses: actions/setup-python@v5
2326
with:
2427
python-version: ${{ matrix.python-version }}
25-
- name: Install dependencies
28+
29+
# 3. Cache pip dependencies based on pyproject.toml and setup.cfg (if any)
30+
- name: Cache pip
31+
uses: actions/cache@v3
32+
with:
33+
path: ~/.cache/pip
34+
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml', '**/setup.cfg') }}
35+
restore-keys: |
36+
${{ runner.os }}-pip-
37+
38+
# 4. Install build requirements
39+
- name: Install build requirements
2640
run: |
2741
python -m pip install --upgrade pip setuptools wheel
42+
43+
# 5. Install project dependencies
44+
- name: Install dependencies
45+
run: |
46+
pip install .
47+
48+
# 6. Cache test dependencies
49+
- name: Cache test dependencies
50+
uses: actions/cache@v3
51+
with:
52+
path: ~/.cache/pip
53+
key: ${{ runner.os }}-pip-test-${{ hashFiles('**/pyproject.toml') }}
54+
restore-keys: |
55+
${{ runner.os }}-pip-test-
56+
57+
# 7. Install test and lint dependencies
58+
- name: Install test and lint dependencies
59+
run: |
60+
pip install .[test]
2861
pip install flake8
29-
- name: Lint with flake8
62+
63+
# 8. Lint with flake8 - Errors
64+
- name: Lint with flake8 (Errors)
3065
run: |
31-
# stop the build if there are Python syntax errors or undefined names
3266
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
33-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
67+
continue-on-error: false
68+
69+
# 9. Lint with flake8 - Warnings
70+
- name: Lint with flake8 (Warnings)
71+
run: |
3472
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
73+
continue-on-error: true
74+
75+
# 10. Run tests with pytest
3576
- name: Test with pytest
3677
run: |
37-
pip install .[test]
38-
pytest
78+
pytest --junitxml=reports/junit.xml --cov=graphedexcel --cov-report=xml
79+
80+
# 11. Upload test coverage to Codecov (Optional)
81+
- name: Upload results to Codecov
82+
uses: codecov/codecov-action@v4
83+
with:
84+
token: ${{ secrets.CODECOV_TOKEN }}
85+
fail_ci_if_error: false
86+
87+
# 12. Upload Test Reports (Optional)
88+
- name: Upload Test Report
89+
if: always()
90+
uses: actions/upload-artifact@v3
91+
with:
92+
name: junit-test-report
93+
path: reports/junit.xml

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ python -m graphedexcel <path_to_excel_file>
6464
### Parameters from `--help`
6565

6666
```
67-
usage: graphedexcel [-h] [--remove-unconnected] [--as-directed-graph] [--no-visualize]
68-
[--layout {spring,circular,kamada_kawai,shell,spectral}] [--config CONFIG]
69-
[--output-path OUTPUT_PATH] [--open-image]
67+
usage: graphedexcel [-h] [--as-directed-graph] [--no-visualize]
68+
[--layout {spring,circular,kamada_kawai,shell,spectral}]
69+
[--config CONFIG] [--output-path OUTPUT_PATH]
70+
[--open-image]
7071
path_to_excel
7172
7273
Process an Excel file to build and visualize dependency graphs.
@@ -76,17 +77,18 @@ positional arguments:
7677
7778
options:
7879
-h, --help show this help message and exit
79-
--remove-unconnected, -r
80-
Remove unconnected nodes from the dependency graph.
8180
--as-directed-graph, -d
8281
Treat the dependency graph as directed.
83-
--no-visualize, -n Skip the visualization of the dependency graph.
84-
--layout,-l {spring,circular,kamada_kawai,shell,spectral}
85-
Layout algorithm for graph visualization (default: spring).
86-
--config CONFIG, -c CONFIG
87-
Path to the configuration file for visualization. See README for details.
88-
--output-path OUTPUT_PATH, -o OUTPUT_PATH
89-
Specify the output path for the generated graph image.
82+
--no-visualize, -n Skip the visualization of the dependency
83+
graph.
84+
--layout, -l {spring,circular,kamada_kawai,shell,spectral}
85+
Layout algorithm for graph visualization
86+
(default: spring).
87+
--config, -c CONFIG Path to the configuration file for
88+
visualization. See README for details.
89+
--output-path, -o OUTPUT_PATH
90+
Specify the output path for the generated
91+
graph image.
9092
--open-image Open the generated image after visualization.
9193
```
9294

pyproject.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,13 @@ dependencies = [
1919
]
2020

2121
[project.optional-dependencies]
22-
test = ["black==21.9b0", "pytest==8.3"]
23-
22+
test = [
23+
"black==21.9b0",
24+
"pytest==8.3",
25+
"pytest-cov>=3.0.0", # Added for coverage reporting
26+
"flake8>=6.0.0", # Ensure flake8 is included here for consistency
27+
"codecov>=2.1.11", # (Optional) If you intend to use Codecov's Python package]
28+
]
2429
[project.urls]
2530
Homepage = "https://github.com/dalager/graphedexcel"
2631
Issues = "https://github.com/dalager/graphedexcel/issues"
@@ -33,5 +38,5 @@ build-backend = "setuptools.build_meta"
3338

3439
[tool.pytest.ini_options]
3540
minversion = "8.0"
36-
addopts = "-ra"
41+
addopts = "-ra --cov=graphedexcel --cov-report=xml --cov-report=term"
3742
testpaths = ["tests"]

src/graphedexcel/__main__.py

Lines changed: 2 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,5 @@
1-
import os
2-
import sys
3-
import argparse
4-
import logging
5-
from .graphbuilder import build_graph_and_stats
6-
from .graph_summarizer import print_summary
7-
from .graph_visualizer import visualize_dependency_graph
1+
from graphedexcel.cli import main
82
from graphedexcel import logger_config # noqa: F401
93

10-
logger = logging.getLogger("graphedexcel.main")
11-
12-
13-
def parse_arguments():
14-
parser = argparse.ArgumentParser(
15-
prog="graphedexcel",
16-
description="Process an Excel file to build and visualize dependency graphs.",
17-
)
18-
19-
# Positional argument for the path to the Excel file
20-
parser.add_argument(
21-
"path_to_excel", type=str, help="Path to the Excel file to process."
22-
)
23-
24-
# Optional flags with shorthand aliases
25-
parser.add_argument(
26-
"--remove-unconnected",
27-
"-r",
28-
action="store_true",
29-
help="Remove unconnected nodes from the dependency graph.",
30-
)
31-
32-
parser.add_argument(
33-
"--as-directed-graph",
34-
"-d",
35-
action="store_true",
36-
help="Treat the dependency graph as directed.",
37-
)
38-
39-
parser.add_argument(
40-
"--no-visualize",
41-
"-n",
42-
action="store_true",
43-
help="Skip the visualization of the dependency graph.",
44-
)
45-
46-
parser.add_argument(
47-
"--layout",
48-
"-l",
49-
type=str,
50-
default="spring",
51-
choices=["spring", "circular", "kamada_kawai", "shell", "spectral"],
52-
help="Layout algorithm for graph visualization (default: spring).",
53-
)
54-
55-
parser.add_argument(
56-
"--config",
57-
"-c",
58-
type=str,
59-
help="Path to the configuration file for visualization. See README for details.",
60-
)
61-
62-
parser.add_argument(
63-
"--output-path",
64-
"-o",
65-
type=str,
66-
default=None,
67-
help="Specify the output path for the generated graph image.",
68-
)
69-
70-
parser.add_argument(
71-
"--open-image",
72-
action="store_true",
73-
help="Open the generated image after visualization.",
74-
)
75-
76-
return parser.parse_args()
77-
78-
79-
def main():
80-
args = parse_arguments()
81-
82-
path_to_excel = args.path_to_excel
83-
84-
# Check if the file exists
85-
if not os.path.exists(path_to_excel):
86-
logger.error(f"File not found: {path_to_excel}")
87-
sys.exit(1)
88-
89-
# Build the dependency graph and gather statistics
90-
dependency_graph, function_stats = build_graph_and_stats(
91-
path_to_excel,
92-
remove_unconnected=args.remove_unconnected,
93-
as_directed=args.as_directed_graph,
94-
)
95-
96-
# Print summary of the dependency graph
97-
print_summary(dependency_graph, function_stats)
98-
99-
if args.no_visualize:
100-
logger.info("Skipping visualization as per the '--no-visualize' flag.")
101-
sys.exit(0)
102-
103-
logger.info("Visualizing the graph of dependencies. (This might take a while...)")
104-
105-
# Determine layout
106-
layout = args.layout
107-
108-
# Configuration path
109-
config_path = args.config
110-
111-
# Determine output filename
112-
if args.output_path:
113-
filename = args.output_path
114-
else:
115-
# Create a default filename based on the Excel file name
116-
base_name = os.path.splitext(os.path.basename(path_to_excel))[0]
117-
filename = f"{base_name}_dependency_graph.png"
118-
119-
# Visualize the dependency graph
120-
visualize_dependency_graph(dependency_graph, filename, config_path, layout)
121-
122-
logger.info(f"Dependency graph image saved to {filename}.")
123-
124-
# Open the image file if requested
125-
if args.open_image:
126-
try:
127-
os.startfile(filename) # Note: os.startfile is Windows-specific
128-
except AttributeError:
129-
# For macOS and Linux, use 'open' and 'xdg-open' respectively
130-
import subprocess
131-
import platform
132-
133-
if platform.system() == "Darwin": # macOS
134-
subprocess.call(["open", filename])
135-
elif platform.system() == "Linux":
136-
subprocess.call(["xdg-open", filename])
137-
else:
138-
logger.warning("Unable to open the image automatically on this OS.")
139-
140-
1414
if __name__ == "__main__":
142-
try:
143-
main()
144-
except Exception as e:
145-
logger.exception("An unexpected error occurred:", e)
146-
sys.exit(1)
5+
main()

0 commit comments

Comments
 (0)