# -*- encoding: utf-8 -*- import distutils.util import os import shutil import tempfile __author__ = 'Suzumizaki-Kimitaka(鈴見咲 君高)' """Test byte compiling of distutils under the non-ASCII path `distutils.util.byte_compile` fails _indirect_ byte compiling when the full-path of the .py file contains non-ASCII characters. Because there is the project (cx_Freeze) which directly uses `distutils.util.byte_compile`, the problem would happen while installing it under the non-ASCII path. Fortunately, it is easy to fix. Ofcourse, the files included in external libraries should be named ASCII only, but `distutils.util.byte_compile` makes and uses full path of them. I learned many of libraries uses setuptools instead of distutils, but please consider the following situations: 1) The case that venv creates the virtual environment under or with non-ASCII named folder. 2) And special cases of 1), on Windows, the name of end-users OFTEN be composed with non-ASCII characters, this means including theirs Documents, Desktop, or Downloads etc. The more they are not professional,they make easily the situation above. """ temp_folder = tempfile.mkdtemp() print('Byte compiling test will be done under "{}"'.format(temp_folder)) path_of_temp_py = os.path.join(temp_folder, '日本語.py') print('The byte compile target is "{}"'.format(path_of_temp_py)) with open(path_of_temp_py, 'wt', encoding='utf-8') as fo: fo.write("""# -*- encoding: utf-8 -*- print('distutilsが間接的にbyte compileするときの挙動を調べています。') print('checking the behavior of indirect byte compiling, distutils does.') """) try: distutils.util.byte_compile( [path_of_temp_py, ], optimize=2, # should be either 1 or 2 to our test. force=True, # make sure our test would be done. direct=False, # Yes, we want to test indirect mode! ) print('Done. The byte compiling test seems succeeded.') finally: shutil.rmtree(temp_folder) # EOF