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

git_helpers: add fallback for inconsistent describe #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

proppy
Copy link
Contributor

@proppy proppy commented Dec 22, 2022

Fixes #1

Before:

>>> import conda_build_prepare.git_helpers
>>> conda_build_prepare.git_helpers.get_latest_describe_tag('.')
'Public_Release-7.6.0-77-g50daf8e8e069363aea2fe91cc8012a8d3038bd87'

After:

>>> import conda_build_prepare.git_helpers
>>> conda_build_prepare.git_helpers.get_latest_describe_tag('.')
'Release-7.6.0'

@proppy
Copy link
Contributor Author

proppy commented Dec 22, 2022

@mithru @ajelinski can you take a look?

Copy link
Member

@mithro mithro left a comment

Choose a reason for hiding this comment

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

I'm not sure this is right but I'm not sure if it is wrong either :-P

Copy link
Member

@mithro mithro left a comment

Choose a reason for hiding this comment

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

I'm going to assume this works?

Would be nice to have tests but I don't think we want to block things to add tests.

conda_build_prepare/git_helpers.py Outdated Show resolved Hide resolved
conda_build_prepare/git_helpers.py Show resolved Hide resolved
@proppy
Copy link
Contributor Author

proppy commented Dec 23, 2022

Would be nice to have tests but I don't think we want to block things to add tests.

Added tests and simplified implementation.

@proppy
Copy link
Contributor Author

proppy commented Dec 23, 2022

@ajelinski @mithro PTAL, added some tests

Copy link
Member

@mithro mithro left a comment

Choose a reason for hiding this comment

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

Some minor comments on the testing.

gh._call_custom_git_cmd(filepath.parent, f'commit -m {msg}')
if tag:
gh._call_custom_git_cmd(filepath.parent, f'tag {tag}')
time.sleep(COMMIT_DELAY)
Copy link
Member

Choose a reason for hiding this comment

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

You might need to explain why you need time.sleep and COMMIT_DELAY?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

otherwise git get confused about the sorting with all the commit dates being the same (it doesn't got below second resolution).

I'll add a comment.



def git_commit_and_tag(filepath, msg, tag=None):
now = time.time()
Copy link
Member

Choose a reason for hiding this comment

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

Why not use tempfile?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do use tmp_path fixture from pytest in the test function, see https://docs.pytest.org/en/7.1.x/how-to/tmp_path.html for more details.

The date here is used for the file content (not the name).

time.sleep(COMMIT_DELAY)


def test_get_first_reachable_tag(tmp_path):
Copy link
Member

Choose a reason for hiding this comment

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

I think you probably want to put the setup into a def setup_test_repo type function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean the git init + git config? Maybe we can do this when there is actually more than one test that share the same setup.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, mostly because it wasn't clear to see what was the actual test verse what was just needed to get things set up for the test.

@mithro
Copy link
Member

mithro commented Dec 29, 2022

@proppy - What do we need to do to get this merged?

@proppy
Copy link
Contributor Author

proppy commented Dec 29, 2022

@proppy - What do we need to do to get this merged?

We need to address the remaining comments :)

try:
return _call_custom_git_cmd(git_repo, 'describe --tags --abbrev=0', quiet=True)
# list reachable tag sorted by commit date
tags = _call_custom_git_cmd(git_repo, 'tag --merged').splitlines()
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps it depends on the git configuration but for me this is sorted lexicographically.
For example for hidapi (https://github.com/libusb/hidapi) this is definitely not a valid replacement:

$ git describe --tags --abbrev=0
hidapi-0.13.1
$ git tag --merged
hidapi-0.1.0
hidapi-0.10.0
hidapi-0.10.1
hidapi-0.11.0
hidapi-0.11.1
hidapi-0.11.2
hidapi-0.12.0
hidapi-0.12.0-rc1
hidapi-0.12.0-rc2
hidapi-0.13.0
hidapi-0.13.1
hidapi-0.2.2
hidapi-0.2.3
hidapi-0.2.4
hidapi-0.3.0
hidapi-0.5.0
hidapi-0.5.1
hidapi-0.5.2
hidapi-0.6.0
hidapi-0.7.0
hidapi-0.8.0-rc1
hidapi-0.9.0
hidapi-0.9.0-rc1

I tried using different --sort options but they don't seem very stable to me (shouldn't creatordate be the same as taggerdate or committerdate?):

$ git tag --sort=taggerdate --merged
hidapi-0.1.0
hidapi-0.10.0
hidapi-0.10.1
hidapi-0.11.0
hidapi-0.11.1
hidapi-0.11.2
hidapi-0.12.0
hidapi-0.12.0-rc1
hidapi-0.12.0-rc2
hidapi-0.2.2
hidapi-0.2.3
hidapi-0.2.4
hidapi-0.3.0
hidapi-0.5.0
hidapi-0.8.0-rc1
hidapi-0.9.0
hidapi-0.9.0-rc1
hidapi-0.5.1
hidapi-0.5.2
hidapi-0.6.0
hidapi-0.7.0
hidapi-0.13.0
hidapi-0.13.1

$ git tag --sort=committerdate --merged
hidapi-0.13.0
hidapi-0.13.1
hidapi-0.5.1
hidapi-0.5.2
hidapi-0.6.0
hidapi-0.7.0
hidapi-0.1.0
hidapi-0.2.2
hidapi-0.2.3
hidapi-0.2.4
hidapi-0.3.0
hidapi-0.5.0
hidapi-0.8.0-rc1
hidapi-0.9.0-rc1
hidapi-0.9.0
hidapi-0.10.0
hidapi-0.10.1
hidapi-0.11.0
hidapi-0.11.1
hidapi-0.11.2
hidapi-0.12.0-rc1
hidapi-0.12.0-rc2
hidapi-0.12.0

$ git tag --sort=creatordate --merged
hidapi-0.1.0
hidapi-0.2.2
hidapi-0.2.3
hidapi-0.2.4
hidapi-0.3.0
hidapi-0.5.0
hidapi-0.5.1
hidapi-0.5.2
hidapi-0.6.0
hidapi-0.7.0
hidapi-0.8.0-rc1
hidapi-0.9.0-rc1
hidapi-0.9.0
hidapi-0.10.0
hidapi-0.10.1
hidapi-0.11.0
hidapi-0.11.1
hidapi-0.11.2
hidapi-0.12.0-rc1
hidapi-0.12.0-rc2
hidapi-0.12.0
hidapi-0.13.0
hidapi-0.13.1

The --sort=creatordate option seems to be what we look for but I'd need to test this on all our packages if it's really correct. I have a feeling the date of creation of either tag or commit won't necessarily point to the tag "closest" to the current HEAD.

Therefore I started thinking about other options.
Since for Xyce the Public_Release-7.6.0 name returned by git describe --tags is invalid I didn't find any way to get to the actual tag name from it.

Maybe we should simply call git describe --tags and grep the warning message to return the "is really '(.*)' here" name:

warning: tag 'Public_Release-7.6.0' is really 'Release-7.6.0' here

I don't like this option very much but at least we don't need to worry about tag sorting which might be tricky.
WDYT?

@ajelinski
Copy link
Contributor

FYI: I've just pushed a fix for the issue causing the CI to fail.

This is my proposal how to fix the #1 issue as I'd really prefer to still use git describe: b7ef41f
Unfortunately I'll be OOO for a week so feel free to include this commit to your PR and merge if you agree on the solution.


gh._call_custom_git_cmd(repo, 'checkout main')
git_commit_and_tag(repo / 'foo', 'third', tag='v0.2')

Copy link
Contributor

Choose a reason for hiding this comment

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

To make sure this isn't just sorted lexicographically perhaps let's also add a v0.10 tag?

Copy link
Contributor

Choose a reason for hiding this comment

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

Otherwise the test file LGTM.

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.

error when deleting inconsistent tag
3 participants