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 pyproject.toml to maintain version from Kebechet's version manager #1163

Merged
merged 2 commits into from
Nov 16, 2022

Conversation

shreekarSS
Copy link
Member

Signed-off-by: Shreekara sshreeka@redhat.com

Related Issues and Dependencies

Fixes: #1158

@sesheta sesheta added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 26, 2022
@sesheta sesheta added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 26, 2022
@sesheta sesheta added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 28, 2022
@shreekarSS shreekarSS changed the title [WIP] Add pyproject.toml to maintain version from Kebechet's version manager Add pyproject.toml to maintain version from Kebechet's version manager Oct 28, 2022
@sesheta sesheta removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 28, 2022
Copy link
Member

@KPostOffice KPostOffice left a comment

Choose a reason for hiding this comment

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

Looks good! I'm worried about the length of adjust...

@@ -108,6 +126,7 @@ def adjust_version_in_sources(
"version.py",
"app.py",
"wsgi.py",
Copy link
Member

Choose a reason for hiding this comment

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

WDYT about turning this into a list of tuples Tuple[str, function] where the function is based on how to process the file type. So, for all existing entries, the function would be self.adjust_version_file, but for the new entry it would self.adjust_version_toml_file or something like this? adjust_version_file is getting a bit long, so I think it should be either refactored into smaller functions, or the new functionality should go in its own function. Let me know what you think.

Copy link
Member Author

Choose a reason for hiding this comment

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

@KPostOffice I'm thinking about using dict of {file_name : function} , fetch the function based on file_name and call

@sesheta sesheta added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 1, 2022
Copy link
Member

@harshad16 harshad16 left a comment

Choose a reason for hiding this comment

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

Good approach.

kebechet/managers/version/release_triggers.py Outdated Show resolved Hide resolved
Copy link
Member

@harshad16 harshad16 left a comment

Choose a reason for hiding this comment

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

some more suggestions

kebechet/managers/version/messages.py Outdated Show resolved Hide resolved
kebechet/managers/version/release_triggers.py Outdated Show resolved Hide resolved
@shreekarSS shreekarSS force-pushed the add_pyproject.toml branch 2 times, most recently from ae216ee to cd1b7c1 Compare November 1, 2022 20:48
Copy link
Member

@harshad16 harshad16 left a comment

Choose a reason for hiding this comment

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

/lgtm
PTAL @KPostOffice

@sesheta sesheta added the lgtm Indicates that a PR is ready to be merged. label Nov 1, 2022
Copy link
Member

@harshad16 harshad16 left a comment

Choose a reason for hiding this comment

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

@VannTen
Copy link
Member

VannTen commented Nov 2, 2022

I have a question:
How do we handle version specified not in by the [project] section, but provided by the build backend ?
I'm thinking specifically of setup like:

[project]
dynamic = ["version"]

[tool.setuptools-scm]
enabled = true

or

[project]
dynamic = ["version"]

[tool.setuptools.dynamic]
version = {attr = "thoth.document_sync.__version__"}

(I'm not sure it's possible in a general way, but in that case we might want to state that in the docs)

@harshad16
Copy link
Member

/hold

@sesheta sesheta added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 2, 2022
@harshad16
Copy link
Member

That is a valid point, we should check/address if the version is not in the project section.

@shreekarSS shreekarSS force-pushed the add_pyproject.toml branch 2 times, most recently from 96e77a1 to bc30c61 Compare November 3, 2022 14:44
Copy link
Member

@harshad16 harshad16 left a comment

Choose a reason for hiding this comment

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

/lgtm

PTAL @KPostOffice

@sesheta sesheta added the lgtm Indicates that a PR is ready to be merged. label Nov 3, 2022
@KPostOffice
Copy link
Member

python-poetry/poetry#144

An interesting thread about why "version" should never be put in source code and should instead be derived from package metadata when needed.

The basic argument here is that version should be set from package metadata, not the other way around.

@KPostOffice
Copy link
Member

I'm not sure what this should mean for this PR, just a rabbit hole that I fell down when looking into Max's concern.

One way to just fix the issue raised is to recognize that json if version is a dictionary then it won't hold a proper string and to return early. If it is specified in a different file then the version manager should update it automatically already so throwing an exception would be wrong in this case.

@harshad16
Copy link
Member

I believe we are addressing the required pattern with PR.
we are only updating the pyproject.toml version if it is the project section, or else it wouldn't be picked for updated.
and we are describing this in our docs as well.

@KPostOffice
Copy link
Member

I believe we are addressing the required pattern with PR. we are only updating the pyproject.toml version if it is the project section, or else it wouldn't be picked for updated. and we are describing this in our docs as well.

Oh yeah, I see what you mean

Copy link
Member

@KPostOffice KPostOffice left a comment

Choose a reason for hiding this comment

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

Looks good. Just a few small changes to the new function

project = toml_content.get("project", None)
old_version = project.get("version", None)
try:
new_version = self.get_new_version(old_version)
Copy link
Member

Choose a reason for hiding this comment

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

Old version must be a string. Passing None here will throw an error.

kebechet/managers/version/release_triggers.py Show resolved Hide resolved
if old_version:
toml_content["project"]["version"] = new_version
changed = True
if not changed:
Copy link
Member

Choose a reason for hiding this comment

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

Having changed and this conditional will be unnecessary if old_version is checked to not be None above

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack

@sesheta sesheta removed the lgtm Indicates that a PR is ready to be merged. label Nov 14, 2022
Copy link
Member

@KPostOffice KPostOffice left a comment

Choose a reason for hiding this comment

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

Just a couple of small comments and then it should be good I think

toml_content["project"]["version"] = new_version
new_content = toml.dumps(toml_content)
with open(file_path, "w") as output_file:
output_file.write(new_content)
Copy link
Member

Choose a reason for hiding this comment

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

Here you can directly do toml.dump(toml_content, output_file), no need for an intermediate string representation.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

file_path = os.path.join(root, file_name)
adjusted_version = self.adjust_version_file(file_path)
if file_name in files_dict:
func_to_call: Any = files_dict[file_name]
Copy link
Member

Choose a reason for hiding this comment

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

could use Callable[[str], Optional[Tuple[str, str]]] as a type hint here. If it gives any errors, we can just leave it as callable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Pre commit failed with : error: Incompatible types in assignment (expression has type "Callable[[str], Optional[Tuple[Any, ...]]]", variable has type "Callable[[str], Optional[Tuple[str, str]]]")

Copy link
Member

Choose a reason for hiding this comment

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

That's because of the function signatures of the called functions could be more descriptive too, so you would need to change this line as well as the the function signatures.

@shreekarSS
Copy link
Member Author

/test pre-commit

@KPostOffice
Copy link
Member

/retest

environment_details=ManagerBase.get_environment_details(),
)
) from e
_LOGGER.info("Computed new version: %s", new_version)
Copy link
Member

Choose a reason for hiding this comment

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

These need to be shifted over so that they are inside the conditional I'm pretty sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

ack, done

toml_content["project"]["version"] = new_version
with open(file_path, "w") as output_file:
output_file.write(toml.dumps(toml_content))
return new_version, old_version
Copy link
Member

Choose a reason for hiding this comment

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

This also needs to be tabbed over. If there is no version, it should just return None

Copy link
Member Author

Choose a reason for hiding this comment

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

ack

…ager

 - Update Messages ISSUE_BODY_NO_VERSION_IDENTIFIER_FOUND variable with
   pyproject.toml related

Signed-off-by: Shreekara <sshreeka@redhat.com>
Signed-off-by: Shreekara <sshreeka@redhat.com>
@KPostOffice
Copy link
Member

/approve

@sesheta
Copy link
Member

sesheta commented Nov 16, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: KPostOffice

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sesheta sesheta added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 16, 2022
Copy link
Member

@harshad16 harshad16 left a comment

Choose a reason for hiding this comment

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

/unhold
/lgtm

thanks 👍

@sesheta sesheta added lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Nov 16, 2022
@sesheta sesheta merged commit f9f7f6d into thoth-station:master Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[3pt] Support pyproject.toml and PEP 566 standards in Kebechet version manager
5 participants