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

Add version info to each generated file #144

Merged
merged 2 commits into from
Aug 23, 2023

Conversation

lgarvey
Copy link
Member

@lgarvey lgarvey commented Aug 22, 2023

This PR adds logic that drops a comment at the top of every generated file including the copilot-helper version and the date/time that the file was created.

The copilot/.workspace file has been omitted because its contents does not vary.

Example comment:

# Created by copilot-helper 0.1.26 / 16:21:43 2023-21-22

@lgarvey lgarvey requested a review from a team August 22, 2023 16:34
Copy link
Contributor

@ejayesh ejayesh left a comment

Choose a reason for hiding this comment

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

This is epic, exactly what we need

Copy link
Member

@yusufsheiqh yusufsheiqh left a comment

Choose a reason for hiding this comment

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

Looks like the CodeBuild build project is failing ATM - will review once this is passing.

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

@WillGibson WillGibson Aug 23, 2023

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Contributor

@shehzadashiq shehzadashiq left a comment

Choose a reason for hiding this comment

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

Really great change. Looks good to me.

@shehzadashiq shehzadashiq merged commit 281ce59 into main Aug 23, 2023
1 check passed
def _get_version(self):
try:
return version("dbt-copilot-tools")
except PackageNotFoundError:
Copy link
Member

Choose a reason for hiding this comment

The 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".

Copy link
Member Author

Choose a reason for hiding this comment

The 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 --version command also has the same issue.

Copy link
Member

Choose a reason for hiding this comment

The 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 pyproject.toml: https://github.com/uktrade/copilot-tools/blob/main/utils/check_pypi.py#L43

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

The 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 PackageNotFound exception.

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 version() should fail and require a fall back to parsing the toml file. So I'm just going to remove the try/except block.

Copy link
Member

Choose a reason for hiding this comment

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

ejayesh pushed a commit that referenced this pull request Aug 24, 2023
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.

5 participants