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

Replace Config class with ConfigReader class #259

Merged
merged 2 commits into from
Nov 27, 2017

Conversation

theseanything
Copy link
Contributor

@theseanything theseanything commented Nov 14, 2017

This PR aims are replacing the Config class with a ConfigReader class. This is apart of an effort to simplify constructing Stack and Environment objects, addressing issue #5.

Currently Sceptre's main entry point when using it as Python module is to create an environment object using the Environment(sceptre_dir, environment_path, options=None) constructor. The Environment class is responsible for reading the relevant config from a Sceptre project folder and creating Stack objects. Additionally Config class is a subclass of the built-in dict with custom class attributes - which make testing incredible difficult and confusing on how to access relevant properties (i.e. is it a key or a attribute - config["region"] vs config.sceptre_dir).

The new ConfigReader class aims to fix these issues - by encapsulating functions related to gathering/parsing Sceptre project folders and reading in config (instead of the Environment class). -

  • Config read in from a file is now represented by a "vanilla" python dict - simplifying where properties are located.
  • The construct_stack and construct_environment methods now provide the ability to generate Stack or Environment object respectively using config files.
  • This cleans up the constructor of the Environment class and adds the ability of generating Stack objects without having to make a Environment object first.

This API change include referencing stacks and environment by full relative paths - laying the foundation to solve issue #62.


  • Wrote good commit messages.
  • Squashed related commits together after the changes have been approved.
  • Commit message starts with [Resolve #issue-number] (if a related issue exists).
  • Added unit tests.
  • Added integration tests (if applicable).
  • All unit tests (make test) are passing.
  • Used the same coding conventions as the rest of the project.
  • The new code doesn't generate flake8 (make lint) offenses.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences. - Sort of, difficult to do in stages.

@theseanything theseanything added this to the v2.0 milestone Nov 14, 2017
@theseanything theseanything self-assigned this Nov 15, 2017
@theseanything theseanything mentioned this pull request Nov 15, 2017
9 tasks

def __init__(self, sceptre_dir, variables=None):
self.logger = logging.getLogger(__name__)
self._deferred_constructors = []
Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove

del self.templating_vars["environment_config"]
return stack

def construct_stack(self, rel_path):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rel_path not clear

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clarified


self._is_leaf = None
self.stacks = []
self.environments = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Potentially rename to sub_environments

Copy link
Contributor

@ngfgrant ngfgrant left a comment

Choose a reason for hiding this comment

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

A really nice PR. Cleans up many methods and makes tests more readable too. I have a couple of small suggestions that you might want to apply. Nothing drastic.

env = Environment(context.sceptre_dir, environment_name)
stack = env.stacks[basename]
config_reader = ConfigReader(context.sceptre_dir)
stack = config_reader.construct_stack(stack_name + ".yaml")
Copy link
Contributor

Choose a reason for hiding this comment

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

If we address #221 hard coding this .ymal extension may cause issues. Consider a different approach that does not use a hardcoded value for the extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just for the stack config which can only be .yaml at the moment - but yeah possible improvement at a later date.

:type environment_path: str
:param options: A dict of key-value pairs to update self.config with.
:type debug: dict
:param environment: The name of the environment.
Copy link
Contributor

Choose a reason for hiding this comment

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

A very pedantic point but parameters docstrings in reST format typically don't end with a full stop. If this is part of project's conventions then just ingnore this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We've used full stops everywhere else, so will just stick with it for now to be consistent.

sceptre/cli.py Outdated
:type environment: str
:param stack: The name of the stack.
:type stack: str
:returns: An Stack.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo. Change An Stack. to A Stack.

hooks used in hooks. Environment and stack config and the connection
manager are supplied to the class, as they may be of use to inheriting
classes.
hooks used in hooks.
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider changing hooks used in hooks. to hooks..

So that the sentence reads:
Hook is an abstract base class that should be inherited by all hooks.

@b-t-g b-t-g merged commit 0d456f4 into v2.0 Nov 27, 2017
@theseanything theseanything deleted the refactor-config-to-config-reader branch November 29, 2017 20:52
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.

None yet

3 participants