Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Lib/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'})

Copy link
Copy Markdown
Member

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?

Copy link
Copy Markdown
Member Author

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).

except (OSError, subprocess.CalledProcessError):
return default
return (output or default)
prefix = os.fsencode(target) + b': '
if output.startswith(prefix):
output = output[len(prefix):]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.
"--" is non-standard too. Since the target should be an absolute name, I think it is not needed.

return (os.fsdecode(output) or default)

### Information about the used architecture

Expand Down Expand Up @@ -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

Expand Down
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.