bpo-35348: Make parsing the output of the file command in platform.architecture() more reliable. by serhiy-storchaka · Pull Request #11160 · python/cpython
| output = subprocess.check_output(['file', target], | ||
| stderr=subprocess.DEVNULL, | ||
| encoding='latin-1') | ||
| env={'LC_ALL': 'C'}) |
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?
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).
| return (output or default) | ||
| prefix = os.fsencode(target) + b': ' | ||
| if output.startswith(prefix): | ||
| output = output[len(prefix):] |
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?
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.