Skip to content

Commit 3d029fc

Browse files
enryHenryhsayalaruano
authored
Entrypoint (#38)
* 🐛 update how to run example, set default either have a default for report type, or not. But None is not a valid default. * 🎨 also print instructions to stdout * ✨ add entrypoint to package * 🔧 extend integration testing to quarto * 🔧 add all report types (based on quatro) * 🎨 prepare entrypoint (needs a fct) * 🎨 add entry point to script * 🎨 display help message if no config or dir is given. Could be improved * 🐛 Fix(quarto_reportview): Fix jupyter report errro by using the quarto convert command * 🎨 Style(cdci.yml, pyproject.toml): Fix typos, unnecesary spaces and update gitignore and class diagram --------- Co-authored-by: enryh <[email protected]> Co-authored-by: sayalaruano <[email protected]>
1 parent 2be1994 commit 3d029fc

File tree

11 files changed

+138
-50
lines changed

11 files changed

+138
-50
lines changed

.github/workflows/cdci.yml

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

1111
jobs:
1212
test:
13-
name: Test
13+
name: Unittests+streamlit
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
@@ -30,4 +30,59 @@ jobs:
3030
pip install -e .
3131
- name: Run tests
3232
run: python -m pytest tests
33+
- name: Execute streamlit report
34+
run: |
35+
cd docs
36+
vuegen --config example_data/MicW2Graph/report_config_micw2graph.yaml
3337
38+
other-reports:
39+
name: Integration tests
40+
runs-on: ubuntu-latest
41+
strategy:
42+
matrix:
43+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
44+
steps:
45+
- uses: actions/checkout@v4
46+
- name: Set up Python ${{ matrix.python-version }}
47+
uses: actions/setup-python@v5
48+
with:
49+
python-version: ${{ matrix.python-version }}
50+
cache: 'pip' # caching pip dependencies
51+
cache-dependency-path: '**/pyproject.toml'
52+
- name: Install dependencies
53+
run: |
54+
pip install --upgrade pip
55+
pip install -e ".[quarto]"
56+
- name: Execute streamlit report (to check)
57+
run: |
58+
cd docs
59+
vuegen -c example_data/MicW2Graph/report_config_micw2graph.yaml
60+
# repeat for easier inspection on GitHub:
61+
- name: quarto html report
62+
run: |
63+
cd docs
64+
vuegen -c example_data/MicW2Graph/report_config_micw2graph.yaml -rt html
65+
- name: quarto pdf report
66+
run: |
67+
cd docs
68+
vuegen -c example_data/MicW2Graph/report_config_micw2graph.yaml -rt pdf
69+
- name: quarto docx report
70+
run: |
71+
cd docs
72+
vuegen -c example_data/MicW2Graph/report_config_micw2graph.yaml -rt docx
73+
- name: quarto odt report
74+
run: |
75+
cd docs
76+
vuegen -c example_data/MicW2Graph/report_config_micw2graph.yaml -rt odt
77+
- name: quarto revealjs report
78+
run: |
79+
cd docs
80+
vuegen -c example_data/MicW2Graph/report_config_micw2graph.yaml -rt revealjs
81+
- name: quarto pptx report
82+
run: |
83+
cd docs
84+
vuegen -c example_data/MicW2Graph/report_config_micw2graph.yaml -rt pptx
85+
- name: quarto jupyter report
86+
run: |
87+
cd docs
88+
vuegen -c example_data/MicW2Graph/report_config_micw2graph.yaml -rt jupyter

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ quarto_report/
123123
.DS_Store
124124

125125
# Extra info
126-
UML_diagrams/
127-
Graphical_abstract/
126+
docs/images/UML_diagrams/
127+
docs/images/Graphical_abstract/
128+
docs/images/Nfcore_module_figure
128129
docs/presentations/
129130
test.py

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,18 @@ quarto check
7070
Run VueGen using a configuration file with the following command:
7171

7272
```bash
73-
python vuegen/main.py --config docs/example_data/MicW2Graph/report_config_micw2graph.yaml --report_type streamlit
73+
cd docs
74+
vuegen --config example_data/MicW2Graph/report_config_micw2graph.yaml --report_type streamlit
7475
```
7576

77+
> 💡 If `vuegen` does not work, try `python -m vuegen` instead.
78+
7679
By default, the `streamlit_autorun` argument is set to False, but you can use it in case you want to automatically run the streamlit app.
7780

7881
It's also possible to provide a directory instead of a configuration file:
7982

8083
```bash
81-
python vuegen/main.py --directory docs/example_data/MicW2Graph/ --report_type streamlit
84+
vuegen --directory docs/example_data/MicW2Graph/ --report_type streamlit
8285
```
8386

8487
The current report types are streamlit, html, pdf, docx, odt, revealjs, pptx, and jupyter.
-30.5 KB
Loading

pyproject.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ kaleido = "0.2.0"
2727
vl-convert-python = "^1.7.0"
2828
dataframe-image = "^0.2.6"
2929
strenum = { version = "^0.4.15", python = "<3.11" }
30+
3031
# optional doc depencencies, follow approach as described here:
3132
# https://github.com/python-poetry/poetry/issues/2567#issuecomment-646766059
3233
sphinx = {version="*", optional=true}
@@ -35,13 +36,12 @@ myst-nb = {version="*", optional=true}
3536
ipywidgets = {version="*", optional=true}
3637
sphinx-new-tab-link = {version = "!=0.2.2", optional=true}
3738
jupytext = {version="*", optional=true}
38-
# quartro
39+
# quarto
3940
quarto-cli = {version="*", optional=true}
4041

4142
[tool.poetry.group.dev.dependencies]
4243
ipykernel = {version="^6.29.5", optional=true}
4344

44-
4545
[build-system]
4646
requires = ["poetry-core"]
4747
build-backend = "poetry.core.masonry.api"
@@ -52,5 +52,6 @@ streamlit = ["streamlit"]
5252
quarto = ["quarto-cli", "ipykernel"]
5353
docs = ["sphinx", "sphinx-book-theme", "myst-nb", "ipywidgets", "sphinx-new-tab-link", "jupytext"]
5454

55-
# [project.scripts]
56-
# my-script = "vuegen.main:main"
55+
[tool.poetry.scripts]
56+
# https://python-poetry.org/docs/pyproject/#scripts
57+
vuegen = "vuegen.__main__:main"

tests/test_module_imports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
def test_imports():
33
import vuegen
4-
import vuegen.main
4+
import vuegen.__main__
55
import vuegen.quarto_reportview
66
import vuegen.report
77
import vuegen.report_generator

vuegen/__main__.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import sys
2+
from pathlib import Path
3+
4+
from vuegen import report_generator
5+
from vuegen.utils import get_logger, get_parser
6+
7+
8+
def main():
9+
# Parse command-line arguments
10+
parser = get_parser(prog_name="VueGen")
11+
args = parser.parse_args()
12+
13+
# Determine the vuegen arguments
14+
config_path = args.config
15+
dir_path = args.directory
16+
report_type = args.report_type
17+
streamlit_autorun = args.streamlit_autorun
18+
19+
# Determine the report name for logger suffix
20+
if config_path:
21+
report_name = Path(config_path).stem
22+
elif dir_path:
23+
report_name = Path(dir_path).name
24+
else:
25+
print("Please provide a configuration file or directory path:\n")
26+
# https://docs.python.org/3/library/argparse.html#printing-help
27+
parser.print_help()
28+
sys.exit(1)
29+
30+
if config_path and dir_path:
31+
print("Please provide only one of configuration file or directory path:\n")
32+
parser.print_help()
33+
sys.exit(1) # otherwise could resort to either or ?
34+
35+
# Define logger suffix based on report type and name
36+
logger_suffix = f"{report_type}_report_{str(report_name)}"
37+
38+
# Initialize logger
39+
logger = get_logger(f"{logger_suffix}")
40+
41+
# Generate the report
42+
report_generator.get_report(report_type=report_type,
43+
logger=logger,
44+
config_path=config_path,
45+
dir_path=dir_path,
46+
streamlit_autorun=streamlit_autorun)
47+
48+
if __name__ == '__main__':
49+
main()

vuegen/main.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

vuegen/quarto_reportview.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ def run_report(self, output_dir: str = BASE_DIR) -> None:
117117
"""
118118
try:
119119
subprocess.run(["quarto", "render", os.path.join(output_dir, f"{self.BASE_DIR}.qmd")], check=True)
120+
if self.report_type == r.ReportType.JUPYTER:
121+
subprocess.run(["quarto", "convert", os.path.join(output_dir, f"{self.BASE_DIR}.qmd")], check=True)
120122
self.report.logger.info(f"'{self.report.title}' '{self.report_type}' report rendered")
121123
except subprocess.CalledProcessError as e:
122124
self.report.logger.error(f"Error running '{self.report.title}' {self.report_type} report: {str(e)}")
@@ -174,8 +176,12 @@ def _create_yaml_header(self) -> str:
174176
toc: false
175177
output: true""",
176178
r.ReportType.JUPYTER: """
177-
jupyter:
178-
kernel: python3"""
179+
html:
180+
toc: true
181+
toc-location: left
182+
toc-depth: 3
183+
page-layout: full
184+
self-contained: true"""
179185
}
180186

181187
# Create a key based on the report type and format

vuegen/streamlit_reportview.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,13 @@ def run_report(self, output_dir: str = SECTIONS_DIR) -> None:
127127
# If autorun is False, print instructions for manual execution
128128
self.report.logger.info(f"All the scripts to build the Streamlit app are available at {output_dir}")
129129
self.report.logger.info(f"To run the Streamlit app, use the following command:")
130-
self.report.logger.info(f"streamlit run {os.path.join(output_dir, self.REPORT_MANAG_SCRIPT)}")
130+
self.report.logger.info(f"streamlit run {os.path.join(output_dir, self.REPORT_MANAG_SCRIPT)}")
131+
msg = (
132+
f"\nAll the scripts to build the Streamlit app are available at: {output_dir}\n\n"
133+
f"To run the Streamlit app, use the following command:\n\n"
134+
f"\tstreamlit run {os.path.join(output_dir, self.REPORT_MANAG_SCRIPT)}"
135+
)
136+
print(msg)
131137

132138
def _format_text(self, text: str, type: str, level: int = 1, color: str = '#000000', text_align: str = 'center') -> str:
133139
"""

0 commit comments

Comments
 (0)