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

refactor: have a single function for normalized PyPI package names #1329

Merged
merged 4 commits into from
Jul 21, 2023

Conversation

aignas
Copy link
Collaborator

@aignas aignas commented Jul 19, 2023

Before this PR there were at least 2 places where such a helper function
existed and it made it very easy to make another copy. This PR introduces a
hardened version, that follows conventions from upstream PyPI and tests have
been added.

Split from #1294, work towards #1262.

Copy link
Collaborator

@chrislovecnm chrislovecnm left a comment

Choose a reason for hiding this comment

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

Looks great! Just a nit pick with the testing.

"friendly.bard",
"friendly_bard",
"friendly--bard",
"FrIeNdLy-._.-bArD",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add an empty string here please? And maybe something that is not a string?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure I can do that easily because I am not sure rules_testing supports failure testing yet and I am not sure if passing a failure function to the normalize_name would be a good idea. Because this is a private function I am not sure how much benefit there is in doing such testing.

Copy link
Contributor

Choose a reason for hiding this comment

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

Failure testing a unit test is possible, but annoying to do. You basically have to switch over to treating it like an analysis test (the same as skylib's unittest): implement a rule to call your code that fails, instantiate the target as the target under test, then check for that failure in the target under test.

(Fabian and I tried kicking around ideas for how we could somehow make use whats available today to make it easier, but couldn't come up with anything).

I'm fine with the tests as-is, fwiw.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Arg. That is all.

Normalize a PyPI package name to allow consistent label names
"""

# Keep in sync with python/pip_install/tools/bazel.py
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we rewrite bazel.py, so that we only have this code here? I do not want that rewrite in this PR, but if we can I would love an issue opened.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is possible but not entirely easy, so created #1330. Let's discuss the technical details there.

python/private/normalize_name.bzl Outdated Show resolved Hide resolved
"friendly.bard",
"friendly_bard",
"friendly--bard",
"FrIeNdLy-._.-bArD",
Copy link
Contributor

Choose a reason for hiding this comment

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

Failure testing a unit test is possible, but annoying to do. You basically have to switch over to treating it like an analysis test (the same as skylib's unittest): implement a rule to call your code that fails, instantiate the target as the target under test, then check for that failure in the target under test.

(Fabian and I tried kicking around ideas for how we could somehow make use whats available today to make it easier, but couldn't come up with anything).

I'm fine with the tests as-is, fwiw.

@chrislovecnm
Copy link
Collaborator

@aignas I approved the PR but CI is failing

@chrislovecnm
Copy link
Collaborator

@aignas, I also included a doc change that Richard recommended, but that is not why CI is failing.

@aignas
Copy link
Collaborator Author

aignas commented Jul 20, 2023

Thanks guys for the review. The bazel.py had a regression (missed prefix +) during the update and I have just pushed a fix with the docstring suggestion. Should be good now.

Copy link
Collaborator

@chrislovecnm chrislovecnm left a comment

Choose a reason for hiding this comment

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

LGTM

@chrislovecnm chrislovecnm added this pull request to the merge queue Jul 21, 2023
Merged via the queue into bazelbuild:main with commit 93f5ea2 Jul 21, 2023
@aignas aignas deleted the refactor/normalize-name branch May 13, 2024 06:48
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.

3 participants