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

Allow setting user conf path through environment variables #496

Open
wants to merge 3 commits into
base: master
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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ ones in. -->

<!-- [Updated cylc-ui to x.y.z](https://github.com/cylc/cylc-ui/blob/master/CHANGES.md) -->

### Enhancements
[#496](https://github.com/cylc/cylc-uiserver/pull/496) - Allow configuring the
user config path and log path with environment variables

### Fixes

[#379](https://github.com/cylc/cylc-uiserver/pull/379) - Fixed lack of info
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ below.
- David Matthews
- Mel Hall
- Christopher Bennett
- Scott Wales
<!-- end-shortlog -->

(All contributors are identifiable with email addresses in the git version
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ The Cylc Hub will load the following files in order:

3) User Config

This file
This file configures the Hub/UIS for the current user. The default path can
be changed by the ``CYLC_CONF_PATH`` environment variable.

(`~/.cylc/uiserver/jupyter_config.py`)

Expand Down Expand Up @@ -174,7 +175,8 @@ are run use the `ServerApp.jpserver_extensions` configuration, see the
[Jupyter Server configuration documentation](https://jupyter-server.readthedocs.io/en/latest/other/full-config.html#other-full-config).

By default the Cylc part of the UI Server log is written to
`~/.cylc/uiserver/uiserver.log`.
`~/.cylc/uiserver/log/log`. This can be changed with the environment
variable ``CYLC_UISERVER_LOG_PATH``.

<!--
TODO: Link to Jupyter Server logging_config docs when published
Expand Down
2 changes: 1 addition & 1 deletion cylc/uiserver/config_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
or GlobalConfig.DEFAULT_SITE_CONF_PATH,
UISERVER_DIR
)
USER_CONF_ROOT = Path.home() / '.cylc' / UISERVER_DIR
USER_CONF_ROOT = Path(os.getenv('CYLC_CONF_PATH') or Path.home() / '.cylc', UISERVER_DIR)


def get_conf_dir_hierarchy(
Expand Down
2 changes: 1 addition & 1 deletion cylc/uiserver/logging_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RotatingUISFileHandler(logging.handlers.RotatingFileHandler):
LOG_NAME_EXTENSION = "-uiserver.log"

def __init__(self):
self.file_path = Path(USER_CONF_ROOT / "log").expanduser()
self.file_path = Path(os.getenv('CYLC_UISERVER_LOG_PATH') or USER_CONF_ROOT, "log").expanduser()

def on_start(self):
"""Set up logging"""
Expand Down
29 changes: 29 additions & 0 deletions cylc/uiserver/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from cylc.uiserver import config_util

import pytest
import importlib

from cylc.flow.cfgspec.globalcfg import GlobalConfig
from cylc.uiserver import __file__ as UIS_PKG
Expand Down Expand Up @@ -84,6 +85,34 @@ def test_cylc_site_conf_path(clear_env, capload, monkeypatch):
]


def test_cylc_user_conf_path(clear_env, monkeypatch):
"""The user config should change to $CYLC_CONF_PATH if set."""
monkeypatch.setenv('CYLC_CONF_PATH', 'elephant')

# Reload modules with updated environment
import cylc.uiserver
importlib.reload(cylc.uiserver.config_util)
importlib.reload(cylc.uiserver.jupyterhub_config)
from cylc.uiserver.config_util import USER_CONF_ROOT

monkeypatch.setattr(config_util, '__version__', '0')

# Can't use the fixture due to the reload
capload = []
monkeypatch.setattr('cylc.uiserver.jupyterhub_config._load', capload.append)

assert USER_CONF_ROOT == Path('elephant/uiserver')

load()
assert capload == [
SYS_CONF,
(SITE_CONF / 'jupyter_config.py'),
(SITE_CONF / '0/jupyter_config.py'),
Path('elephant/uiserver/jupyter_config.py'),
Path('elephant/uiserver/0/jupyter_config.py'),
]


def test_get_conf_dir_hierarchy(monkeypatch: pytest.MonkeyPatch):
"""Tests hierarchy of versioning for config"""
config_paths = ['config_path/one', 'config_path/two']
Expand Down
7 changes: 7 additions & 0 deletions cylc/uiserver/tests/test_logging_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def test_first_init_log(tmp_path):
LOG.file_path / '01-uiserver.log')


def test_log_conf_path(tmp_path, monkeypatch):
"""Check initial setup, no previous logs present"""
monkeypatch.setenv('CYLC_UISERVER_LOG_PATH', 'elephant')
LOG = RotatingUISFileHandler()
assert str(LOG.file_path) == 'elephant/log'


def test_init_log_with_established_setup(tmp_path):
"""Tests the entire logging init with a typically full logging dir"""
LOG = RotatingUISFileHandler()
Expand Down