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

Support envfile task level and global option #29

Merged
merged 1 commit into from
Jun 13, 2021
Merged

Conversation

nat-n
Copy link
Owner

@nat-n nat-n commented May 25, 2021

Adds support for a new envfile option at global or task level. #22

Includes an original lightweight parser for envfiles closely following bash syntax.


else:
# We found one or more backslashes
num_backslashes = len(match_terminator)
Copy link
Contributor

Choose a reason for hiding this comment

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

I see what you're doing. But won't the regex

((?:".*?(?<!\\)(\\\\)*?")|(?:'.*?(?<!\\)(\\\\)*?'))

Be sufficient?

Explanation

  • 2 groups: one for handling " and one for handling '.
  • The middle part (.*?) should be self-explanatory
  • The last part ((?<!\\)(\\\\)*?) will match an even number of \ that are not escaped.

Copy link
Owner Author

@nat-n nat-n May 26, 2021

Choose a reason for hiding this comment

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

Hmm, it seemed simpler this way, but that's worth exploring. Note that backslashes don't work as escapes within single quotes, and we need remove active quotes from the result but preserve escaped backslashes as in lines 84 & 120.

""",
{"FOO": "BAR", "BAR": "FOO"},
),
]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a test for space before the FOO, too? And, instead of strictly complying, why not allow spaces between the =?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Look again, preceding space is present in all the tests 💯 Maybe there should be a test without preceding space...

I considered allowing spaces around the = though felt that sticking to how bash does it was a safer bet design wise. I figured it would be least surprising if the file is loaded exactly the same way as it would be via the source command. Maybe this is worth revisiting, though I would need evidence to motivate a change.

Copy link
Contributor

@ThatXliner ThatXliner left a comment

Choose a reason for hiding this comment

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

Nice. This is tested to work, right?

EDIT: Also, why did you "UI" so much?

@nat-n
Copy link
Owner Author

nat-n commented May 26, 2021

@ThatXliner Thanks for taking a look.

Nice. This is tested to work, right?

EDIT: Also, why did you "UI" so much?

I tried it with a few simple scenarios, I intend it test it more and also add a few scenarios to the feature test suite before merging and making a pre-release, when I get another block of time to work on it.

The "UI" line changes are all about being able to print a warning at context.py:90 when the UI is in verbose mode.

@nat-n nat-n force-pushed the feature/envfile branch 2 times, most recently from 1671091 to 101eb9f Compare May 28, 2021 22:35
@ThatXliner
Copy link
Contributor

The current envfile parsing is very fault tolerant, which is good, but doesn't emit warnings for syntax errors.

With this envfile:

TEST=yeetus  # Epic


 e = A
 A = b
a = b
a = c

Only TEST is set. It doesn't send an error! (Removing spaces around the = will make it set all of these). Poe doesn't warn on duplicate keys either.

@nat-n
Copy link
Owner Author

nat-n commented May 29, 2021

The current envfile parsing is very fault tolerant, which is good, but doesn't emit warnings for syntax errors.

Good catch, regexes are tricky beasts. I added some tests with bad input to give more confidence.

@nat-n nat-n force-pushed the feature/envfile branch 3 times, most recently from a170ce7 to 7b0f6f7 Compare May 29, 2021 14:06
@nat-n nat-n marked this pull request as ready for review June 5, 2021 19:34
@ThatXliner
Copy link
Contributor

ThatXliner commented Jun 5, 2021

Good, it's erroring now. Except the error message is very cryptic... You might wanna use something like Lark which has very epic error message support. (Lark can generate a standalone so you don't need to worry about an extra dependency)

@nat-n nat-n force-pushed the feature/envfile branch 3 times, most recently from cd0d9fe to 26b34e0 Compare June 12, 2021 21:58
- Includes original envfile parser that closely follows bash syntax
@nat-n
Copy link
Owner Author

nat-n commented Jun 12, 2021

@ThatXliner

Good, it's erroring now. Except the error message is very cryptic... You might wanna use something like Lark which has very epic error message support. (Lark can generate a standalone so you don't need to worry about an extra dependency)

Good point. I tweaked the error handling so it's a bit more specific and helpful I think.

I think it's good to go now, but I'll leave this open a short while longer in case you'd like to give more feedback before I merge and create another pre-release.

@ThatXliner
Copy link
Contributor

Looks good. It would be nice to have suggestions but at least the errors are correct.

@nat-n nat-n merged commit e5cd24c into development Jun 13, 2021
@nat-n nat-n deleted the feature/envfile branch June 13, 2021 21:29
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.

2 participants