Skip to content

Commit 4195ac8

Browse files
committed
Improve documentation from CLI
1 parent 23b5d3b commit 4195ac8

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

pipelines/notebooks/test_plusierus_annees.ipynb

Whitespace-only changes.

pipelines/run.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,22 @@ def cli():
2121
def list():
2222
"""List all available tasks."""
2323
tasks_dir = os.path.join(os.path.dirname(__file__), "tasks")
24-
click.echo("Available tasks:")
25-
for filename in os.listdir(tasks_dir):
24+
25+
for filename in sorted(os.listdir(tasks_dir)):
2626
if filename.endswith(".py") and not filename.startswith("_"):
2727
module_name = filename[:-3]
2828
module = importlib.import_module(f"tasks.{module_name}")
29-
description = module.__doc__ or "No description"
30-
description = description.strip().split("\n")[0]
31-
click.echo(f"- {module_name}: {description}")
29+
30+
doc = module.__doc__ or "No description"
31+
doc_lines = doc.strip().split("\n")
32+
while doc_lines and not doc_lines[0].strip():
33+
doc_lines.pop(0)
34+
while doc_lines and not doc_lines[-1].strip():
35+
doc_lines.pop()
36+
37+
click.echo(f"\n{module_name}:")
38+
for line in doc_lines:
39+
click.echo(f" {line}")
3240

3341

3442
@cli.command()
@@ -38,27 +46,29 @@ def list():
3846
type=click.Choice(["all", "last", "custom"]),
3947
default="all",
4048
help="Type of refresh to perform",
49+
hidden=True,
4150
)
4251
@click.option(
4352
"--custom-years",
4453
type=str,
4554
help="Comma-separated list of years to process (for custom refresh type)",
55+
hidden=True,
4656
)
47-
def run(task_name, refresh_type, custom_years):
57+
def run(task_name, refresh_type, custom_years, drop_tables):
4858
"""Run a specified task."""
4959
try:
5060
module = importlib.import_module(f"tasks.{task_name}")
5161
task_func = getattr(module, "execute")
5262
logging.info(f"Starting task {task_name}...")
53-
63+
5464
# Parse custom years if provided
5565
custom_years_list = None
5666
if custom_years:
5767
custom_years_list = [year.strip() for year in custom_years.split(",")]
58-
68+
5969
# Call the task function with parameters
6070
task_func(refresh_type=refresh_type, custom_years=custom_years_list)
61-
71+
6272
logging.info(f"Task {task_name} completed.")
6373
except (ModuleNotFoundError, AttributeError):
6474
logging.error(f"Task {task_name} not found.")

pipelines/tasks/build_database.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
"""
2-
Consolidate data into the database.
2+
Consolidate data into the database.\n
3+
Args:
4+
- refresh-type (str): Type of refresh to perform ("all", "last", or "custom")
5+
- custom-years (list[str]): List of years to process when refresh_type is "custom"
36
"""
47

58
import logging
69
import os
7-
from typing import Dict, List, Literal
10+
from typing import List, Literal
811
from zipfile import ZipFile
912

1013
import duckdb
1114
import requests
1215

1316
from ._common import CACHE_FOLDER, DUCKDB_FILE, clear_cache
14-
from ._config_edc import get_edc_config, create_edc_yearly_filename
17+
from ._config_edc import create_edc_yearly_filename, get_edc_config
1518

1619
logger = logging.getLogger(__name__)
1720
edc_config = get_edc_config()
@@ -33,7 +36,6 @@ def check_table_existence(conn: duckdb.DuckDBPyConnection, table_name: str) -> b
3336
return list(conn.fetchone())[0] == 1
3437

3538

36-
3739
def download_extract_insert_yearly_edc_data(year: str):
3840
"""
3941
Downloads from www.data.gouv.fr the EDC (Eau distribuée par commune) dataset for one year,
@@ -134,7 +136,9 @@ def process_edc_datasets(
134136
f"Invalid years provided: {sorted(invalid_years)}. Years must be among: {available_years}"
135137
)
136138
# Filtering and sorting of valid years
137-
years_to_update = sorted(list(set(custom_years).intersection(available_years)))
139+
years_to_update = sorted(
140+
list(set(custom_years).intersection(available_years))
141+
)
138142
else:
139143
raise ValueError(
140144
""" custom_years parameter needs to be specified if refresh_type="custom" """
@@ -153,10 +157,11 @@ def process_edc_datasets(
153157
clear_cache(recreate_folder=False)
154158
return True
155159

160+
156161
def execute(refresh_type: str = "all", custom_years: List[str] = None):
157162
"""
158163
Execute the EDC dataset processing with specified parameters.
159-
164+
160165
:param refresh_type: Type of refresh to perform ("all", "last", or "custom")
161166
:param custom_years: List of years to process when refresh_type is "custom"
162167
"""

0 commit comments

Comments
 (0)