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

Improve update-versions.py #47

Merged
merged 2 commits into from
Mar 4, 2024

Conversation

pedorich-n
Copy link
Contributor

Comment on lines +173 to +175
versions_jsonified = OrderedDict(
(str(version), hashes.__dict__) for version, hashes in versions.items()
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This hack is required because json.dump allows only str as keys. So we have to create another OrderedDict (it preserves insert order) with string keys.

Copy link
Member

Choose a reason for hiding this comment

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

@pedorich-n I think that is fine for the time being.

}
return versions
result: List[semver.Version] = []
for release in releases:
Copy link
Member

Choose a reason for hiding this comment

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

@pedorich-n I would argue that using high-order functions makes it a little bit easier to reason what this specific section of the code does as it hides some of the implementation details of looping over the elements of the list, filtering, and generating a new list out of the subset of stable releases:

return map(to_version, filter(is_stable, releases))

While I understand the proposed approach involves looping through the list of releases only once, I don't think we have a lot of entries right now to worry about performance, so I'm more inclined to favor readability. What are your thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I primarily use FP languages, I agree, but I think in Python FP is not the preferred way of doing things. I've even heard the map, filter, reduce, and other functions were supposed to be removed from Python 3.
But if you don't mind that, I sure can change to map and filter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

import subprocess
from dataclasses import dataclass
from pathlib import Path
from typing import (
Copy link
Member

Choose a reason for hiding this comment

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

@pedorich-n this is a great improvement! Thank you for adding type-hints throughout the script.

Copy link
Member

@sestrella sestrella left a comment

Choose a reason for hiding this comment

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

@pedorich-n I appreciate you taking the effort to work on this issue; the type-hints were an amazing touch! I left one comment, please let me know your thoughts.

@oscar-izval
Copy link
Contributor

Hey @pedorich-n! You may want to rebase/merge the main branch to get the build going. We just fixed it for PRs coming from forks :)

@pedorich-n pedorich-n force-pushed the improve-update-versions branch from 3b10c18 to 1218dac Compare March 1, 2024 00:55
Copy link
Member

@sestrella sestrella left a comment

Choose a reason for hiding this comment

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

@pedorich-n this is a fantastic contribution; apologies for taking so long to merge this one.

@sestrella sestrella merged commit 9049e26 into stackbuilders:main Mar 4, 2024
3 checks passed
@pedorich-n pedorich-n deleted the improve-update-versions branch March 5, 2024 00:26
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.

Inconsistent ordering of versions
3 participants