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

fix: use custom strtobool if distutils not available #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Vallishp
Copy link

  1. distutils not available from python 3.12 so clang-format-lint-action will fail.
  2. strtobool is relatively simple function, we can use this function if the import fails.

inspiration:

  1. https://stackoverflow.com/questions/42248342/yes-no-prompt-in-python3-using-strtobool

@DoozyX
Copy link
Owner

DoozyX commented Sep 10, 2024

Thanks, but this issue has already been resolved by pinning the Python version, can you reproduce the issue versions > v0.16 ?

@Vallishp
Copy link
Author

Thanks, but this issue has already been resolved by pinning the Python version, can you reproduce the issue versions > v0.16 ?
tried with latest version. its working . thank you

@echoix
Copy link

echoix commented Sep 10, 2024

At some point we will need to change from the old python version, as it is a temporary solution. It is fine to think about how to migrate out.

Comment on lines +29 to +43
def strtobool(val):
"""
Convert a string representation of truth to true (1) or false (0).

True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
'val' is anything else.
"""
val = val.lower()
if val in ('y', 'yes', 't', 'true', 'on', '1'):
return 1
elif val in ('n', 'no', 'f', 'false', 'off', '0'):
return 0
else:
raise ValueError("Invalid truth value '{}'".format(val))

Choose a reason for hiding this comment

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

(Disclaimer: I'm not a maintainer, just a drive-by reviewer.)

The substance of the solution is good, but the current implementation hurts maintainability: defining a function inline, in a try-catch block, in an import statement, leaves a bit of a mess.

Ideally, we'd define this function in one of the other library files, and add unit tests. But, this project appears to be a single-python-file setup which doesn't have unit tests. So, I think the cleanest thing to do would be to stop trying to import distutils, and just define strtobool as a function in this file.

In fact, since we have total control of this file, and there is only a single usage, we can dispense with the awkward bool(strtobool(...)) at the callsite (line 314 in the "before" version), and simply return bool directly from this function.

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