-
Notifications
You must be signed in to change notification settings - Fork 313
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
[Resolves #1268] Modify ConfigFileNotFound Error to Conditionally Include Valid Stack Paths #1270
[Resolves #1268] Modify ConfigFileNotFound Error to Conditionally Include Valid Stack Paths #1270
Conversation
sceptre/plan/plan.py
Outdated
command_path = pathlib.PurePath(self.context.command_path) | ||
filtered_valid_stack_paths = [] | ||
for stack_path in self._valid_stack_paths(): | ||
for parent in pathlib.PurePath(stack_path).parents: | ||
if command_path.parent == parent: | ||
filtered_valid_stack_paths.append(stack_path) | ||
break | ||
if filtered_valid_stack_paths and len(filtered_valid_stack_paths) > MAX_VALID_STACK_PATH_COUNT: | ||
filtered_valid_stack_paths = None | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few thoughts on this:
- This seems rather deeply nested. I'd like to avoid getting so nested, especially in this function. It hurts readability. I also don't think we need to do it this way.
- Rather than crawling every combination of segments and comparing parents, I don't think we need to get that intense about it. Rather, I think a simpler and more straight-forward logic here would be to do this:
- Check if there's a "/" in the command path. If not, then the prefix to use is
''
(all strings technically start with''
). If there IS, doprefix, _ = command_path.rsplit('/' 1)
to get the prefix. - Filter the valid paths for those that start with the prefix. You can either use
filter()
or a list comprehension.
- Check if there's a "/" in the command path. If not, then the prefix to use is
Done this way, it would look more like:
command_path = pathlib.PurePath(self.context.command_path) | |
filtered_valid_stack_paths = [] | |
for stack_path in self._valid_stack_paths(): | |
for parent in pathlib.PurePath(stack_path).parents: | |
if command_path.parent == parent: | |
filtered_valid_stack_paths.append(stack_path) | |
break | |
if filtered_valid_stack_paths and len(filtered_valid_stack_paths) > MAX_VALID_STACK_PATH_COUNT: | |
filtered_valid_stack_paths = None | |
break | |
if '/' in self.context.command_path: | |
prefix, _ = self.context.command_path.rsplit('/', 1) | |
else: | |
prefix = '' | |
all_paths = self._valid_stack_paths() | |
# We'll fall back to all_paths if no valid path starts with the prefix | |
filtered_valid_stack_paths = [p for p in all_paths if p.startswith(prefix + '/')] or all_paths | |
if len(filtered_valid_stack_paths) > MAX_VALID_STACK_PATH_COUNT: | |
filtered_valid_stack_paths = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored function to use this suggestion with pathlib
rather than /
processing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also like to see a test around this functionality.
fe7bc0b
to
de92670
Compare
@X-Guardian, what are the status on the tests for this PR? |
@X-Guardian Do you have any plans to finish this PR? |
From what I remember it works, but I don't use Sceptre any more, so won't be writing any tests, which is what I think was blocking this getting merged. |
@zaro0508 I have had a look at this stale PR and I agree with @X-Guardian and I think the PR should be merged as-is. The new private method is simply tweaking the error message seen and I do not think that such a trivial change justifies us adding more unit test code. Nor is it obvious to me how you would test this anyway. Could we merge? I've added it into my integration branch and I'm certainly happy with it. |
Modifies the Sceptre Plan
ConfigFileNotFound
error to only include the list of valid stack paths from the command path specified and only there are less than 10 stacks.Example
New Error Message (when there are less than 10 stacks under the specified parent path)
New Error Message (when there are 10 stacks or more under the specified parent path)
PR Checklist
[Resolve #issue-number]
.make test
) are passing.pre-commit run --all-files
).and description in grammatically correct, complete sentences.
Approver/Reviewer Checklist
Other Information
Guide to writing a good commit