-
-
Notifications
You must be signed in to change notification settings - Fork 35k
bpo-35348: Make parsing the output of the file command in platform.architecture() more reliable. #11160
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
bpo-35348: Make parsing the output of the file command in platform.architecture() more reliable. #11160
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -611,10 +611,13 @@ def _syscmd_file(target, default=''): | |
| try: | ||
| output = subprocess.check_output(['file', target], | ||
| stderr=subprocess.DEVNULL, | ||
| encoding='latin-1') | ||
| env={'LC_ALL': 'C'}) | ||
| except (OSError, subprocess.CalledProcessError): | ||
| return default | ||
| return (output or default) | ||
| prefix = os.fsencode(target) + b': ' | ||
| if output.startswith(prefix): | ||
| output = output[len(prefix):] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use -b option, my PR #11159? It would prefer simpler to not display the filename than try to remove it, no?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only reason is that this option is non-standard. It may introduce a regression on some exotic platform if add the -b option. |
||
| return (os.fsdecode(output) or default) | ||
|
|
||
| ### Information about the used architecture | ||
|
|
||
|
|
@@ -676,7 +679,7 @@ def architecture(executable=sys.executable, bits='', linkage=''): | |
| linkage = l | ||
| return bits, linkage | ||
|
|
||
| if 'executable' not in fileout: | ||
| if 'executable' not in fileout and 'shared object' not in fileout: | ||
| # Format not supported | ||
| return bits, linkage | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Make parsing the output of the ``file`` command in | ||
| :func:`platform.architecture`: more reliable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you use LC_ALL=C to change the encoding? If yes, I'm not sure that it's a good idea.
If it's to get the output in english: I would be surprised since I'm not aware of a translated output of file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LC_ALL=C is used because the output can be locale depending (as it is documented).