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

Global config hierarchy #3802

Merged
merged 8 commits into from
Sep 17, 2020
Merged

Global config hierarchy #3802

merged 8 commits into from
Sep 17, 2020

Conversation

MetRonnie
Copy link
Member

@MetRonnie MetRonnie commented Sep 2, 2020

These changes close #3689

Cylc will attempt to load the global configuration (global.cylc) from a hierarchy of locations, including the site directory (defaults to /etc/cylc/flow/) and the user directory at ~/.cylc/flow/. E.g. for Cylc version 8.0.1, the hierarchy would be, in order of ascending priority:

  • ${CYLC_SITE_CONF_PATH}/global.cylc
  • ${CYLC_SITE_CONF_PATH}/8/global.cylc
  • ${CYLC_SITE_CONF_PATH}/8.0/global.cylc
  • ${CYLC_SITE_CONF_PATH}/8.0.1/global.cylc
  • ~/.cylc/flow/global.cylc
  • ~/.cylc/flow/8/global.cylc
  • ~/.cylc/flow/8.0/global.cylc
  • ~/.cylc/flow/8.0.1/global.cylc

A setting in a file lower down in the list will override the same setting from those higher up (but if a setting is present in a file higher up and not in any files lower down, it will not be overridden).

To override the default configuration path, set the CYLC_CONF_PATH environment variable to the directory containing your global.cylc file. If this is set, the hierarchy above is ignored.

Setting the CYLC_SITE_CONF_PATH environment variable overrides the default value of /etc/cylc/flow/, without ignoring the hierarchy.

Requirements check-list

  • I have read CONTRIBUTING.md and added my name as a Code Contributor.
  • Contains logically grouped changes (else tidy your branch by rebase).
  • Does not contain off-topic changes (use other PRs for other changes).
  • Appropriate tests are included (unit and/or functional) - kind of 😛
  • Appropriate change log entry included.
  • No dependency changes.

@MetRonnie MetRonnie added this to the cylc-8.0a3 milestone Sep 2, 2020
@MetRonnie MetRonnie self-assigned this Sep 2, 2020
@MetRonnie
Copy link
Member Author

I'm not sure how best to test the global config hierarchy

@oliver-sanders
Copy link
Member

I'm not sure how best to test the global config hierarchy

  • Can test the value of SITE_CONF_DIR_HIERARCHY.
  • If really going for it could move the logic which loads files into it's own function load_config(files: list).

Comment on lines 776 to 780
if os.access(fname, os.F_OK | os.R_OK):
self.loadcfg(fname, upgrader.USER_CONFIG)
else:
LOG.warning(
f'No global.cylc file at CYLC_CONF_PATH: {conf_path_str}')
Copy link
Member Author

Choose a reason for hiding this comment

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

Is this useful? I noticed there was a previous commit to raise an error if the path doesn't exist, but that commit was reverted

Copy link
Member

Choose a reason for hiding this comment

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

Because this environment variable can get copied to remote platforms (which aren't on the same filesystem) this warning is useful some of the time, and misleading some of the time.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, removing it on the basis that being misleading some of the time is worse than not being helpful some of the time

@MetRonnie
Copy link
Member Author

I've found it messy trying to unit test the exact config dir hierarchy, but at least there is a doctest for the version number hierarchy:

def get_version_hierarchy(version):
"""Return list of versions whose global configs are compatible, in
ascending priority.
Args:
version (str): A PEP 440 compliant version number.
Example:
>>> get_version_hierarchy('8.0.1a2.dev')
['', '8', '8.0', '8.0.1', '8.0.1a2', '8.0.1a2.dev']

and a unit test for the override behaviour of ParsecConfig.loadcfg

def test_loadcfg_override(sample_spec):
"""Test that loading a second config file overrides common settings but
leaves in settings only present in the first"""

@oliver-sanders
Copy link
Member

@MetRonnie a rebase should fix test failure

@MetRonnie
Copy link
Member Author

Just undoing & redoing the last commit and force pushing seems to have done the trick, as the tests run on a merge commit (PR branch merged into master). Ideally the tests should re-run when master changes, then. But I don't think that's possible currently

@oliver-sanders
Copy link
Member

That's interesting, didn't know it worked like that, Travis CI just checked out your branch locally so you had to rebase to pick up changes which resulted in a couple of false negatives over the years.

@MetRonnie
Copy link
Member Author

Travis also creates a merge commit to run the tests, e.g. for https://travis-ci.org/github/metomi/isodatetime/builds/725975670 it says " Commit ba1e4c1 " and if you click on the link it shows
image

Copy link
Member

@oliver-sanders oliver-sanders left a comment

Choose a reason for hiding this comment

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

Looks good, one style comment.

Comment on lines +733 to +742
self.SITE_CONF_PATH = (os.getenv('CYLC_SITE_CONF_PATH') or
os.path.join(os.sep, 'etc', 'cylc', 'flow'))
self.USER_CONF_PATH = os.path.join(self._HOME, '.cylc', 'flow')
version_hierarchy = get_version_hierarchy(CYLC_VERSION)
self.CONF_DIR_HIERARCHY = [
*[(upgrader.SITE_CONFIG, os.path.join(self.SITE_CONF_PATH, ver))
for ver in version_hierarchy],
*[(upgrader.USER_CONFIG, os.path.join(self.USER_CONF_PATH, ver))
for ver in version_hierarchy]
]
Copy link
Member

Choose a reason for hiding this comment

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

If converting these class attributes to instance attributes make them lower case.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was only CONF_DIR_HIERARCHY that needed to be moved inside __init__ because it's not possible to use another class attribute inside the list comprehension (https://stackoverflow.com/a/13913933/3217306). Seeing as this is the only reason for making it a instance attribute, would it make sense to leave it uppercase if the other two are changed to class attributes?

Copy link
Member

@hjoliver hjoliver left a comment

Choose a reason for hiding this comment

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

LGTM 👍 thanks @MetRonnie

@hjoliver hjoliver merged commit 8406f4e into cylc:master Sep 17, 2020
@MetRonnie MetRonnie deleted the config-changes2 branch September 17, 2020 09:01
@hjoliver hjoliver modified the milestones: cylc-8.0a3, cylc-8.0b0 Feb 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

conf: configuration file changes
3 participants