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

feat: refactor Version.bump() to accept bumping major/minor/patch/last #452

Merged
merged 19 commits into from
Jan 2, 2024

Conversation

hadim
Copy link
Contributor

@hadim hadim commented Dec 19, 2023

See #449 for context.

  • add new enum VersionBumpType
  • refactor Version.bump() to Version.bump(bump_type: VersionBumpType)
  • add unit tests
  • adapt the python binding

This PR is breaking backward compat but since rust does not support overloading or default args, I could not find a more creative way to keep backward compat. That being said, it might not be that much of a problem. If it is, please let me know, and I can always keep bump() as it is and create a new function.

@hadim
Copy link
Contributor Author

hadim commented Dec 19, 2023

I would also need some help/guidance for the python binding.

@baszalmstra
Copy link
Collaborator

I would also need some help/guidance for the python binding.

@Wackyator ?

@Wackyator
Copy link
Contributor

Hey @hadim, this looks great, appreciate the PR! I can help you with the Python bindings if you have any kind of issues.

@hadim
Copy link
Contributor Author

hadim commented Dec 20, 2023

Hey @hadim, this looks great, appreciate the PR! I can help you with the Python bindings if you have any kind of issues.

I am not sure how to 1) propagate the Result and the Error 2) integrate the new enum VersionBumpType

@Wackyator
Copy link
Contributor

Wackyator commented Dec 20, 2023

Hey @hadim, this looks great, appreciate the PR! I can help you with the Python bindings if you have any kind of issues.

I am not sure how to 1) propagate the Result and the Error 2) integrate the new enum VersionBumpType

For propagating the Result and Error, you can return the PyResult type from functions & extend the PyRattlerError and create the exception for it.
After that you can simply do a PyRattlerError::from the errors.
You can see an example of it here

For the VersionBumpType I'd say introduce seperate functions for them instead of making an enum on the python side, that seems more pythonic.

@hadim
Copy link
Contributor Author

hadim commented Dec 20, 2023

For the VersionBumpType I'd say introduce seperate functions for them instead of making an enum on the python side, that seems more pythonic.

Make sense! Should I keep bump() and forward it to bump_last()? or should I just get rid of it?

@hadim
Copy link
Contributor Author

hadim commented Dec 20, 2023

@Wackyator @baszalmstra: LGTM - ready for another round of review. Thanks!

/// Bump the patch version number.
Patch,
/// Bump the last version number.
Last,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a Segment(uint) type? So that we can explicitly select the segment to bump?

We might also consider that bumping non-existent segments should be possible. Usually, all non-existent segments are implicit .0, so bumping the patch of a 1.0 could also result in 1.0.1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you add a Segment(uint) type? So that we can explicitly select the segment to bump?

Good idea. Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We might also consider that bumping non-existent segments should be possible. Usually, all non-existent segments are implicit .0, so bumping the patch of a 1.0 could also result in 1.0.1.

Don't you prefer to instead fail, so it also builds incentive for the user to explicitly use x.x.x instead of x or x.x?

Unless you feel strongly here, I would prefer to let it for another PR (I can open a ticket if you want).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added support for VersionBumpType::Segment(i32) in 9283770 (rust side only).

Self {
inner: self.inner.bump(),
/// Returns a new version where the major segment of this version has been bumped.
pub fn bump_major(&self) -> PyResult<Self> {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we had that integer option we could pass an int from Python (with -1 being the last element, for example), and bump like that.
Then in Python we could also define an enum for the different named segments and allow both, passing an enum or an int.

Copy link
Contributor Author

@hadim hadim Dec 20, 2023

Choose a reason for hiding this comment

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

I am fine with this Python API.

What we have so far is:

  • bump_major()
  • bump_minor()
  • bump_patch()
  • bump_last()

I can add the below as well:

  • bump_segment(int)
  • bump(enum)

Does that sound good to you?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Python side done at 4ac1858

I didn't implement bump(enum) since it seems a bit overkill at this point, but let me know if you still want it.

@wolfv
Copy link
Contributor

wolfv commented Dec 20, 2023

Really nice work. I had some simple remarks. Let me know what you think!

Copy link
Contributor

@Wackyator Wackyator left a comment

Choose a reason for hiding this comment

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

Good work, just a couple of nits. :)

py-rattler/src/version/mod.rs Outdated Show resolved Hide resolved
py-rattler/src/version/mod.rs Show resolved Hide resolved
py-rattler/src/version/mod.rs Show resolved Hide resolved
py-rattler/src/version/mod.rs Show resolved Hide resolved
py-rattler/src/version/mod.rs Outdated Show resolved Hide resolved
py-rattler/tests/unit/test_version.py Outdated Show resolved Hide resolved
hadim and others added 3 commits December 21, 2023 06:45
@hadim hadim requested a review from Wackyator December 21, 2023 13:12
@hadim
Copy link
Contributor Author

hadim commented Dec 21, 2023

All good @Wackyator on my side.


Out of curiosity: are you using VSCode and rust-analyzer by any chance? I'm asking because I do and noticed that any .rs files located within py-rattler/ are failing to do any kind of linting/problem-detection within the VSCode editor, while all the .rs files located into crates/ works just fine. I tried playing with members = ["crates/*", "py-rattler/*"] in Cargo.toml but no success.

Sorry, I know it's not really related to that PR, but didnt want to open a new issue for this.

@Wackyator
Copy link
Contributor

Out of curiosity: are you using VSCode and rust-analyzer by any chance? I'm asking because I do and noticed that any .rs files located within py-rattler/ are failing to do any kind of linting/problem-detection within the VSCode editor, while all the .rs files located into crates/ works just fine. I tried playing with members = ["crates/*", "py-rattler/*"] in Cargo.toml but no success.

Sorry, I know it's not really related to that PR, but didnt want to open a new issue for this.

I'm indeed using vscode and rust-analyzer for py-rattler, I usually open rattler/py-rattler/ in a separate vscode instance & it works fine.

@Wackyator
Copy link
Contributor

This looks good to me, others can point out anything I may have missed.

@hadim
Copy link
Contributor Author

hadim commented Dec 21, 2023

I'm indeed using vscode and rust-analyzer for py-rattler, I usually open rattler/py-rattler/ in a separate vscode instance & it works fine.

Ok, thanks. I was trying to avoid that and after going into the rabbit hole I found that:

{
    "rust-analyzer.linkedProjects": [
        "./py-rattler/Cargo.toml"
    ]
}

into .vscode/settings.json solve the issue.

@baszalmstra baszalmstra requested a review from wolfv January 2, 2024 08:40
Copy link
Collaborator

@baszalmstra baszalmstra left a comment

Choose a reason for hiding this comment

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

I left one final comment with regards to the unit test but other than that this looks good to me!

py-rattler/tests/unit/test_version.py Outdated Show resolved Hide resolved
@baszalmstra baszalmstra merged commit 02e68c9 into conda:main Jan 2, 2024
13 checks passed
@hadim hadim deleted the bump branch January 2, 2024 15:18
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.

4 participants