-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add version info to each generated file #144
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import datetime | ||
from importlib.metadata import PackageNotFoundError | ||
from importlib.metadata import version | ||
|
||
from jinja2_simple_tags import StandaloneTag | ||
|
||
|
||
class VersionTag(StandaloneTag): | ||
tags = {"version_info"} | ||
|
||
def _get_version(self): | ||
try: | ||
return version("dbt-copilot-tools") | ||
except PackageNotFoundError: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to test this? Looks like we are testing the happy path via fixtures already, but we also handle this exception and return "UNKNOWN". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be an edge case - it only happens if the code is run directly, instead of after installing the package. I did consider manually parsing pyproject.toml to grab the version, but I don't see much value in it. Your There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason why I mention it is because we have a similar method here that does parse There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh cool, I'll raise another PR and fix it in both places. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I went down a rabbit hole here. I wasn't liking the way Poetry installs the package as a dependency so at one point I manually removed it, which then caused the I did some digging yesterday and found this: python-poetry/poetry#800, which explains why poetry works this way. But the upshot of it is, there's no scenario that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeahhh, I was thinking we would ideally never run into that exception anyway. It might be worth bumping up the version as well, so this change gets published on to PyPI as well. |
||
return "UNKNOWN" | ||
|
||
def render(self): | ||
format = "%Y-%m-%d %H:%M:%S" | ||
time = datetime.datetime.now().strftime(format) | ||
return f"Generated by copilot-helper {self._get_version()} / {time}" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# {% version_info %} | ||
Parameters: | ||
# Copilot required Parameters... | ||
App: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# {% version_info %} | ||
Parameters: | ||
# Copilot required Parameters... | ||
App: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# {% version_info %} | ||
Parameters: | ||
# Copilot required Parameters... | ||
App: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# {% version_info %} | ||
Parameters: | ||
# Copilot required Parameters... | ||
App: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# {% version_info %} | ||
Parameters: | ||
# Copilot required Parameters... | ||
App: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# {% version_info %} | ||
Parameters: | ||
App: | ||
Type: String | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# {% version_info %} | ||
Metadata: | ||
cfn-lint: | ||
config: | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Generated by copilot-helper v0.1-TEST / 2023-08-22 16:00:00 | ||
Parameters: | ||
# Copilot required Parameters... | ||
App: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Generated by copilot-helper v0.1-TEST / 2023-08-22 16:00:00 | ||
Parameters: | ||
# Copilot required Parameters... | ||
App: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Generated by copilot-helper v0.1-TEST / 2023-08-22 16:00:00 | ||
Parameters: | ||
# Copilot required Parameters... | ||
App: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Generated by copilot-helper v0.1-TEST / 2023-08-22 16:00:00 | ||
Parameters: | ||
# Copilot required Parameters... | ||
App: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Generated by copilot-helper v0.1-TEST / 2023-08-22 16:00:00 | ||
Parameters: | ||
# Copilot required Parameters... | ||
App: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Generated by copilot-helper v0.1-TEST / 2023-08-22 16:00:00 | ||
Parameters: | ||
App: | ||
Type: String | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Generated by copilot-helper v0.1-TEST / 2023-08-22 16:00:00 | ||
Metadata: | ||
cfn-lint: | ||
config: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Generated by copilot-helper v0.1-TEST / 2023-08-22 16:00:00 | ||
Metadata: | ||
cfn-lint: | ||
config: | ||
|
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.
Could we call this file something which better describes it's reason for being?
Maybe
generated_by_tags.py
?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.
It's fine as it is. If it grows and requires refactoring, then so be it. It's similar to the Django convention of putting views in a views.py file, models in a models.py file etc.
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.
Actually,
version_tag.py
, to match the class name, would be best.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.
jinja2 tags are a standard. It's self explanatory and follows conventions.
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.
Everywhere I have worked for over a decade it has been the convention to name a file containing a class to match the class name.
Are you able to link to the standard you mention?
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.
It sounds like you've spent too much time working with Java; my experience has been the opposite for the past 10+ years working mainly in python land.
It's worth reading the modules section of this python structure guide: https://docs.python-guide.org/writing/structure/#modules
Maybe we should start a team style guide and come to a consensus on these smaller issues, so that we can increase the objectivity of code reviews?
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.
Ignoring the side languages, the last ten years went PHP > TypeScript > Java & Ruby.
Now Python.
I am 100% up for a team style guide. I'll start a thread in Slack to get the ball rolling.