-
Notifications
You must be signed in to change notification settings - Fork 7
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
Improved templating audits #238
base: main
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
combine-durations/action.py
Outdated
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.
pre-commit/ruff changes
template-files/action.py
Outdated
@cache | ||
def _get_emoji_style(self) -> tuple[str, str]: | ||
match self: | ||
case self.UNUSED: | ||
return ":warning-emoji:", "yellow" | ||
case self.MISSING: | ||
return ":cross_mark:", "red" | ||
case self.USED: | ||
return ":white_check_mark:", "green" | ||
case self.CONTEXT: | ||
return ":books:", "blue" | ||
case self.OPTIONAL: | ||
return ":heavy_plus_sign:", "yellow" | ||
case _: | ||
raise ValueError("Invalid TemplateState") |
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.
or is the old-school way more clear? it's more concise 🤷🏼♂️
@cache | |
def _get_emoji_style(self) -> tuple[str, str]: | |
match self: | |
case self.UNUSED: | |
return ":warning-emoji:", "yellow" | |
case self.MISSING: | |
return ":cross_mark:", "red" | |
case self.USED: | |
return ":white_check_mark:", "green" | |
case self.CONTEXT: | |
return ":books:", "blue" | |
case self.OPTIONAL: | |
return ":heavy_plus_sign:", "yellow" | |
case _: | |
raise ValueError("Invalid TemplateState") | |
@cache | |
def _get_emoji_style(self) -> tuple[str, str]: | |
try: | |
return { | |
self.UNUSED: (":warning-emoji:", "yellow"), | |
self.MISSING: (":cross_mark:", "red"), | |
self.USED: (":white_check_mark:", "green"), | |
self.CONTEXT: (":books:", "blue"), | |
self.OPTIONAL: (":heavy_plus_sign:", "yellow"), | |
}[self] | |
except KeyError: | |
raise ValueError("Invalid TemplateState") |
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.
No, I like the match ... case ... statements.
template-files/action.py
Outdated
# GitHub repository name or local directory | ||
r"\w+/\w+|\..+": { |
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.
this allows us to fetch templates from the local file system, not just those checked into GitHub repos
template-files/action.py
Outdated
class LocalContents: | ||
# mirror GitHub contents object | ||
def __init__(self, path: Path): | ||
self.decoded_content = path.read_text().encode() | ||
|
||
|
||
class LocalRepository: | ||
# mirror GitHub repository object | ||
def __init__(self, *paths: str | os.PathLike[str] | Path) -> None: | ||
self.path = Path(*paths).resolve() | ||
if not paths or not self.path.is_dir(): | ||
raise FileNotFoundError(f"{self.path} is not a directory") | ||
|
||
# constants | ||
self.html_url = f"file://{self.path}" | ||
self.user = "<local>" | ||
self.name = "<local>" | ||
|
||
def get_contents(self, path: str) -> LocalContents: | ||
return LocalContents(self.path / path) |
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.
these mirror the GitHub Repository and Contents objects allowing us to use templates from the local file system (this is useful for testing purposes)
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.
while useful for testing idk if we should keep it, feels like a hack that will only hurt in the future
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.
Well, it doesn't look like this is being tested anyways (at least in CI), so if it helps with testing it locally I don't see a reason for removing it.
Maybe a little outside the scope of this pull request, but why isn't the code in this repository being tested? 😅 If you could, maybe now would be a good time to introduce it if only for this code that is changing in this pull request. |
I created a separate issue for adding a testing actions: |
GitHub Actions/Workflows are not exactly easy to test in many cases since they're always running in "production", this GHA is probably an easier one to test since the action defers to a standalone script, but yes it would be good to figure something out testing wise |
caf37f1
to
eb76256
Compare
eb76256
to
8eaa05a
Compare
bc0e4a9
to
55f3449
Compare
55f3449
to
c595976
Compare
This comment was marked as outdated.
This comment was marked as outdated.
Template SuccessTemplating Audit
Template ErrorTemplating Audit
Got 1 error(s) |
a72247b
to
73ae56d
Compare
Description
Depends on #243
Whoa this became kinda complicated...no wonder I originally skipped this stuff.
I was reminded (in conda/conda-libmamba-solver#588 (comment)) that I had chosen not to over engineered the templating engine but with the templates becoming more complex (and others besides myself monitoring the templating jobs) we might as well include all the bells and whistles to help ourselves when debugging.
Old Audit
New Audit
This change introduces a few key improvements:
we now watch for context usage so we can warn the user about missing variables, the context has 4 possible states:
if the templating produces errors we will leave the audit open by default, this will make the errors more noticeable
the template stubs table also includes counts of how many times the stubs are referenced