Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds option to specify config location using env variable #110

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cats/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import logging
import sys
import os
from collections.abc import Mapping
from typing import Any, Optional

Expand Down Expand Up @@ -76,7 +77,16 @@
return yaml.safe_load(f)
logging.info(f"Using provided config file: {configpath}\n")
else:
# if no path provided, look for `config.yml` in current directory
# if no path provided, try to use config environment variable
cfile = os.getenv("CATS_CONFIG_FILE")
if cfile is not None:
try:
with open(cfile, "r") as f:
return yaml.safe_load(f)
logging.info("Using config.yml found in CATS_CONFIG_FILE\n")
except FileNotFoundError:
logging.warning("CATS_CONFIG_FILE config file not found")

Check warning on line 88 in cats/configure.py

View check run for this annotation

Codecov / codecov/patch

cats/configure.py#L83-L88

Added lines #L83 - L88 were not covered by tests
Comment on lines +80 to +88
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would benefit from a test being added to test_configure.py (which will stop codecov throwing a fit). I'll see if I can add something to this PR for that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created a PR against your main branch - I think that will add a test to this PR if you merge it.

# if no path provided and no env variable, look for `config.yml` in current directory
try:
with open("config.yml", "r") as f:
return yaml.safe_load(f)
Expand Down
11 changes: 10 additions & 1 deletion docs/source/quickstart.rst
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect there will be a merge conflict for this file if #111 gets merged first. Should be easy to resolve.

Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,22 @@ Use the ``--config`` option to specify a path to the configuration
file, relative to the current directory.

In case of a missing location command line argument, ``cats`` looks
for a file named ``config.yaml`` in the current directory.
first in the ``CATS_CONFIG_FILE`` environment variable and if that
is not set it looks for a file named ``config.yaml`` in the current directory.

.. code-block:: shell

# Override duration value at the command line
cats --config /path/to/config.yaml --location "OX1"

.. code-block:: shell

# location information is provided by the file
# specified in $CATS_CONFIG_FILE
# If not, it looks for ./config.yaml
export CATS_CONFIG_FILE=/path/to/config.yaml
cats --duration 480

.. code-block:: shell

# location information is assumed to be provided in
Expand Down