Skip to content

Commit

Permalink
Support .env files for CRASHSTATS_API_TOKEN. (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
willkg committed Oct 15, 2024
1 parent 2e8cc7d commit 15efdf2
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ __pycache__
dist
build
.cache
.env
.pytest_cache
.tox
.python-version
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]
Expand Down Expand Up @@ -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]]]
Expand Down Expand Up @@ -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]]]
Expand Down Expand Up @@ -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]]]
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ requires-python = ">=3.8"
dependencies = [
"click",
"more_itertools",
"python-dotenv",
"requests",
"rich",
"tomli>=1.1.0; python_version < '3.11'",
Expand Down
10 changes: 10 additions & 0 deletions src/crashstats_tools/cmd_fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import time

import click
from dotenv import load_dotenv
from rich.console import Console

from crashstats_tools.libcrashstats import (
Expand Down Expand Up @@ -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
Expand All @@ -191,6 +197,7 @@ def fetch_data(
workers,
stats,
color,
dotenv,
outputdir,
crash_ids,
):
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion src/crashstats_tools/cmd_reprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time

import click
from dotenv import load_dotenv
from rich.console import Console
from more_itertools import chunked

Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
19 changes: 18 additions & 1 deletion src/crashstats_tools/cmd_supersearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions src/crashstats_tools/cmd_supersearchfacet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -294,6 +300,7 @@ def supersearchfacet(
color,
denote_weekends,
leftover_count,
dotenv,
):
"""Fetches facet data from Crash Stats using Super Search
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 15efdf2

Please sign in to comment.