Skip to content

Commit

Permalink
Autodetect encoding of setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
regebro committed Mar 6, 2021
1 parent 7c43d47 commit 936720b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Changelog
3.0.2 (unreleased)
------------------

- Nothing changed yet.
- Added correct detection of setup.py encoding

- Code cleanup [CAM Gerlach]


3.0.1 (2021-03-02)
Expand Down
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,4 @@ Contributors:
* Max Tyulin
* Michael Howitz
* Florian Bruhin
* Christopher A.M. Gerlach
8 changes: 7 additions & 1 deletion pyroma/projectdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import sys
import logging
import tokenize

from copy import copy
from distutils import core
Expand Down Expand Up @@ -119,7 +120,12 @@ def run_setup(script_name, script_args=None, stop_after="run"):
sys.argv[0] = script_name
if script_args is not None:
sys.argv[1:] = script_args
with open(script_name, encoding="UTF-8") as f:

# Find the encoding
with open(script_name, "rb") as f:
encoding = tokenize.detect_encoding(f.readline)[0]

with open(script_name, "rt", encoding=encoding) as f:
exec(f.read(), glocals, glocals)
finally:
sys.argv = save_argv
Expand Down

0 comments on commit 936720b

Please sign in to comment.