mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-07-07 15:07:33 -06:00
klippy: Add Python2 module wrappers and use Python3 module naming
Add wrappers for some common Python modules so that the code can run on both Python2 and Python3. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
b8c91914b7
commit
f1747b5118
6 changed files with 29 additions and 8 deletions
|
@ -90,6 +90,27 @@ def dump_mcu_build():
|
|||
dump_file_stats(build_dir, 'out/klipper.elf')
|
||||
|
||||
|
||||
######################################################################
|
||||
# Python2 wrapper hacks
|
||||
######################################################################
|
||||
|
||||
def setup_python2_wrappers():
|
||||
if sys.version_info.major >= 3:
|
||||
return
|
||||
# Add module hacks so that common Python3 module imports work in Python2
|
||||
import Queue, io, StringIO, ConfigParser, time
|
||||
sys.modules["queue"] = Queue
|
||||
io.StringIO = StringIO.StringIO
|
||||
time.process_time = time.clock
|
||||
sys.modules["configparser"] = ConfigParser
|
||||
OrigRawConfigParser = ConfigParser.RawConfigParser
|
||||
def RCP(strict=False, *args, **kwargs):
|
||||
return OrigRawConfigParser(*args, **kwargs)
|
||||
RCP.SECTCRE = OrigRawConfigParser.SECTCRE
|
||||
ConfigParser.RawConfigParser = RCP
|
||||
setup_python2_wrappers()
|
||||
|
||||
|
||||
######################################################################
|
||||
# General system and software information
|
||||
######################################################################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue