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

fix: add version to samconfig.toml file #1581

Merged
merged 2 commits into from
Nov 23, 2019

Conversation

sriram-mv
Copy link
Contributor

  • support version key, any float is okay.
  • if a config file is present and the version key is missing, we do not
    process it.
  • if a config file is missing, thats fine. this check does not get in
    the way.
  • validation logic to determine if a SAM CLI version is compatible can
    be written later.

Issue #, if available:

Description of changes:

Checklist:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Member

@awood45 awood45 left a comment

Choose a reason for hiding this comment

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

The PR is fine in form, but I want to understand more about what the purpose of a version number is.


def _version_sanity_check(self, version):
if not isinstance(version, float):
raise SamConfigVersionException(f"'{VERSION_KEY}' key is not present " f"or is in unrecognized format. ")
Copy link
Member

Choose a reason for hiding this comment

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

This is well and good, but what is the purpose of a version number? The AWS CLI config has never needed this, what does it mean when we increment it?

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 was discussed as part of design, but at the very least, it provides us a mechanism depending on the growth of scope of the configuration file in the future.


except SamConfigVersionException as ex:
LOG.debug("%s %s", samconfig.path(), str(ex))
raise ConfigException(f"Syntax invalid in samconfig.toml: {str(ex)}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why change Exception type? What is difference between SamConfigVersionException and ConfigException?

Also probably include in exception message that this is due to Invalid Version instead of Invalid Syntax.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One is a click exception, and the other isnt. str(ex) gives us version based information.

self.document = tomlkit.loads(txt)
self._version_sanity_check(self._version())
except OSError:
self.document = tomlkit.document()
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: Probably add a debug log before default to tomlkit.document().

Copy link
Contributor Author

@sriram-mv sriram-mv Nov 22, 2019

Choose a reason for hiding this comment

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

Sure. Edit: actually lets think about that a bit more, if there is no config file we say we couldn't find it every-time under debug, I'm not sure if thats the behavior we want.

return self.document

def _write(self):
if not self.document:
return
if not self.exists():
open(self.filepath, "a+").close()
current_version = self._version() if self._version() else SAM_CONFIG_VERSION
try:
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: any reason why we are not checking for key to be present and add only if it isn't?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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 do.

current_version = self._version() if self._version() else SAM_CONFIG_VERSION
try:
self.document.add(VERSION_KEY, current_version)
except tomlkit.exceptions.KeyAlreadyPresent:
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 check it here.

- support version key, any float is okay.
- if a config file is present and the version key is missing, we do not
  process it.
- if a config file is missing, thats fine. this check does not get in
  the way.
- validation logic to determine if a SAM CLI version is compatible can
  be written later.
if not self.document:
self._read()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

bugfix: do not attempt to read everytime a put is made, read once and load.

@c2tarun c2tarun requested review from c2tarun and awood45 November 23, 2019 00:09
@sriram-mv sriram-mv merged commit 961af97 into aws:release-v0.32.0 Nov 23, 2019
sriram-mv added a commit that referenced this pull request Nov 23, 2019
* fix: add version to `samconfig.toml` file

- support version key, any float is okay.
- if a config file is present and the version key is missing, we do not
  process it.
- if a config file is missing, thats fine. this check does not get in
  the way.
- validation logic to determine if a SAM CLI version is compatible can
  be written later.

* bugfix: do not continously read everytime a samconfig.put is called
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.

3 participants