Преглед изворни кода

add code to replace the import commands to fix execution errors

Sven Czarnian пре 3 година
родитељ
комит
1d50f0e9af
1 измењених фајлова са 14 додато и 0 уклоњено
  1. 14 0
      setup.py

+ 14 - 0
setup.py

@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 
 import os
+import re
 import shutil
 import subprocess
 import sys
@@ -28,6 +29,18 @@ def generateProtobuf(source):
         if 0 != subprocess.call(command):
             sys.exit(-1)
 
+        # check if we need to replace some import commands
+        replaced = False
+        content = open(output, 'r').read()
+        for entry in re.findall('import.[A-Z].*.as.*', content):
+            content = content.replace(entry, 'from . ' + entry)
+            replaced = True
+
+        # update the content
+        if replaced:
+            with open(output, 'w') as file:
+                file.write(content)
+
 # @brief Cleans up all auto-generated files and folders
 # @param[in] _clean Instance of setuptools to clean up the system
 class clean(_clean):
@@ -76,6 +89,7 @@ setup(
         'configparser',
         'protobuf',
         'pyzmq',
+        're',
         'setuptools'
     ]
 )