diff --git a/.gitignore b/.gitignore index cec393b..4081fd0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ __pycache__ dist build .cache +.env .pytest_cache .tox .python-version diff --git a/README.rst b/README.rst index 026ede4..0c7cde9 100644 --- a/README.rst +++ b/README.rst @@ -155,6 +155,8 @@ supersearch color is shut off when stdout is not an interactive terminal automatically [default: color] + --dotenv / --no-dotenv whether or not to load a .env file for + environment variables [default: no-dotenv] --help Show this message and exit. .. [[[end]]] @@ -319,6 +321,8 @@ supersearchfacet Calculates the leftover that is the difference between the total minus the sum of all term counts [default: no-leftover-count] + --dotenv / --no-dotenv whether or not to load a .env file for + environment variables [default: no-dotenv] --help Show this message and exit. .. [[[end]]] @@ -414,6 +418,8 @@ fetch-data color is shut off when stdout is not an interactive terminal automatically [default: color] + --dotenv / --no-dotenv whether or not to load a .env file for + environment variables [default: no-dotenv] --help Show this message and exit. .. [[[end]]] @@ -473,6 +479,8 @@ reprocess color is shut off when stdout is not an interactive terminal automatically [default: color] + --dotenv / --no-dotenv whether or not to load a .env file for + environment variables [default: no-dotenv] --help Show this message and exit. .. [[[end]]] diff --git a/pyproject.toml b/pyproject.toml index cae36b7..e1b70b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,6 +10,7 @@ requires-python = ">=3.8" dependencies = [ "click", "more_itertools", + "python-dotenv", "requests", "rich", "tomli>=1.1.0; python_version < '3.11'", diff --git a/src/crashstats_tools/cmd_fetch_data.py b/src/crashstats_tools/cmd_fetch_data.py index 4d612be..6bca933 100644 --- a/src/crashstats_tools/cmd_fetch_data.py +++ b/src/crashstats_tools/cmd_fetch_data.py @@ -11,6 +11,7 @@ import time import click +from dotenv import load_dotenv from rich.console import Console from crashstats_tools.libcrashstats import ( @@ -178,6 +179,11 @@ def fetch_crash( "when stdout is not an interactive terminal automatically" ), ) +@click.option( + "--dotenv/--no-dotenv", + default=False, + help="whether or not to load a .env file for environment variables", +) @click.argument("outputdir") @click.argument("crash_ids", nargs=-1) @click.pass_context @@ -191,6 +197,7 @@ def fetch_data( workers, stats, color, + dotenv, outputdir, crash_ids, ): @@ -220,6 +227,9 @@ def fetch_data( https://crash-stats.mozilla.org/documentation/protected_data_access/ """ + if dotenv: + load_dotenv() + if not color: console = Console(color_system=None) else: diff --git a/src/crashstats_tools/cmd_reprocess.py b/src/crashstats_tools/cmd_reprocess.py index 23bddaf..3ca929d 100644 --- a/src/crashstats_tools/cmd_reprocess.py +++ b/src/crashstats_tools/cmd_reprocess.py @@ -8,6 +8,7 @@ import time import click +from dotenv import load_dotenv from rich.console import Console from more_itertools import chunked @@ -58,9 +59,14 @@ "when stdout is not an interactive terminal automatically" ), ) +@click.option( + "--dotenv/--no-dotenv", + default=False, + help="whether or not to load a .env file for environment variables", +) @click.argument("crashids", nargs=-1) @click.pass_context -def reprocess(ctx, host, sleep, ruleset, allow_many, color, crashids): +def reprocess(ctx, host, sleep, ruleset, allow_many, color, dotenv, crashids): """ Sends specified crashes for reprocessing @@ -79,6 +85,9 @@ def reprocess(ctx, host, sleep, ruleset, allow_many, color, crashids): Also, if you're processing a lot of crashes, you should let us know before you do it. """ + if dotenv: + load_dotenv() + host = host.rstrip("/") if not color: diff --git a/src/crashstats_tools/cmd_supersearch.py b/src/crashstats_tools/cmd_supersearch.py index 29217fe..cf0480f 100644 --- a/src/crashstats_tools/cmd_supersearch.py +++ b/src/crashstats_tools/cmd_supersearch.py @@ -8,6 +8,7 @@ from urllib.parse import urlparse, parse_qs import click +from dotenv import load_dotenv from rich.console import Console from rich.table import Table @@ -88,9 +89,22 @@ def extract_supersearch_params(url): "when stdout is not an interactive terminal automatically" ), ) +@click.option( + "--dotenv/--no-dotenv", + default=False, + help="whether or not to load a .env file for environment variables", +) @click.pass_context def supersearch_cli( - ctx, host, supersearch_url, num, headers, format_type, verbose, color + ctx, + host, + supersearch_url, + num, + headers, + format_type, + verbose, + color, + dotenv, ): """ Performs a basic search on Crash Stats using the Super Search API and @@ -159,6 +173,9 @@ def supersearch_cli( https://crash-stats.mozilla.org/documentation/protected_data_access/ """ + if dotenv: + load_dotenv() + host = host.rstrip("/") if not color: diff --git a/src/crashstats_tools/cmd_supersearchfacet.py b/src/crashstats_tools/cmd_supersearchfacet.py index 3c81653..9e92366 100644 --- a/src/crashstats_tools/cmd_supersearchfacet.py +++ b/src/crashstats_tools/cmd_supersearchfacet.py @@ -9,6 +9,7 @@ from urllib.parse import urlparse, parse_qs import click +from dotenv import load_dotenv from rich.console import Console from rich.table import Table from rich import box @@ -281,6 +282,11 @@ def fix_value(value, denote_weekends=False): + "minus the sum of all term counts" ), ) +@click.option( + "--dotenv/--no-dotenv", + default=False, + help="whether or not to load a .env file for environment variables", +) @click.pass_context def supersearchfacet( ctx, @@ -294,6 +300,7 @@ def supersearchfacet( color, denote_weekends, leftover_count, + dotenv, ): """Fetches facet data from Crash Stats using Super Search @@ -378,6 +385,9 @@ def supersearchfacet( https://crash-stats.mozilla.org/documentation/protected_data_access/ """ + if dotenv: + load_dotenv() + host = host.rstrip("/") today = datetime.datetime.now()