Skip to content

Conversation

groodt
Copy link
Collaborator

@groodt groodt commented May 17, 2022

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature (please, look at the "Scope of the project" section in the README.md file)
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

There are some entry_points in the wild that end with a .py suffix. This is an extreme edge-case, but this clashes with the native Python rules in Bazel that forbids py_binary to end with .py.

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

An example entry_point in the wild that ends with .py https://github.com/jupyterhub/jupyterhub-idle-culler/blob/9dba16033485f3c70352edd3255bb0c5905f16ce/setup.py#L15

@groodt groodt requested review from brandjon and lberki as code owners May 17, 2022 12:37
(directory_path / entry_point_script).write_text(
# There is an extreme edge-case with entry_points that end with `.py`
# See: https://github.com/bazelbuild/bazel/blob/09c621e4cf5b968f4c6cdf905ab142d5961f9ddc/src/test/java/com/google/devtools/build/lib/rules/python/PyBinaryConfiguredTargetTest.java#L174
entry_point_without_py = name[:-3] if name.endswith(".py") else name

Choose a reason for hiding this comment

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

Suggested change
entry_point_without_py = name[:-3] if name.endswith(".py") else name
entry_point_without_py = name.removesuffix(".py")

https://docs.python.org/3/library/stdtypes.html#str.removesuffix

Copy link
Collaborator Author

@groodt groodt May 18, 2022

Choose a reason for hiding this comment

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

Incredible as it may seem , that is New in version 3.9. and I would prefer this to be compatible with older versions of PY3.

Choose a reason for hiding this comment

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

Bah, so it is.

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.

2 participants