def _setPaths(): path = os.pathsep.join(PyInstaller.__pathex__) old = compat.getenv(envvar) if old is not None: path = os.pathsep.join((path, old)) compat.setenv(envvar, path) return old
def _run_created_exe(self, test, testdir=None): """ Run executable created by PyInstaller. """ self._msg('EXECUTING TEST ' + self.test_name) # Run the test in a clean environment to make sure they're # really self-contained path = compat.getenv('PATH') compat.unsetenv('PATH') prog = self._find_exepath(test, 'dist') if prog is None: self._plain_msg('ERROR: no file generated by PyInstaller found!') compat.setenv("PATH", path) return 1 else: self._plain_msg("RUNNING: " + prog) old_wd = os.getcwd() os.chdir(os.path.dirname(prog)) prog = os.path.join(os.curdir, os.path.basename(prog)) retcode, out, err = compat.exec_command_all(prog) os.chdir(old_wd) self._msg('STDOUT %s' % self.test_name) self._plain_msg(out) self._msg('STDERR %s' % self.test_name) self._plain_msg(err) compat.setenv("PATH", path) return retcode
def _setPaths(): path = os.pathsep.join(CONF['pathex']) old = compat.getenv(envvar) if old is not None: path = os.pathsep.join((path, old)) compat.setenv(envvar, path) return old
def extend_system_path(paths): """ Add new paths at the beginning of environment variable PATH. Some hooks might extend PATH where PyInstaller should look for dlls. """ old_PATH = compat.getenv('PATH', '') paths.append(old_PATH) new_PATH = os.pathsep.join(paths) compat.setenv('PATH', new_PATH)
def setupUPXFlags(): f = compat.getenv("UPX", "") if is_win: # Binaries built with Visual Studio 7.1 require --strip-loadconf or they will not compress. Configure.py makes # sure that UPX is new enough to support --strip-loadconf. f = "--strip-loadconf " + f # Do not compress any icon, so that additional icons in the executable can still be externally bound. f = "--compress-icons=0 " + f f = "--best " + f compat.setenv("UPX", f)
def extend_system_path(paths): """ Add new paths at the beginning of environment variable PATH. Some hooks might extend PATH where PyInstaller should look for dlls. """ # imported here to avoid circular import from PyInstaller import compat old_path = compat.getenv('PATH', '') paths.append(old_path) new_path = os.pathsep.join(paths) compat.setenv('PATH', new_path)
def wrapper(*args, **kwargs): if is_win: old_path = getenv('PATH', '') new_path = os.pathsep.join([ x for x in os.environ['PATH'].split(os.pathsep) if path_to_clean not in x ]) setenv('PATH', new_path) try: return f(*args, **kwargs) finally: if is_win: setenv('PATH', old_path)
def test_exe(test, testdir=None): _msg("EXECUTING TEST", testdir + '/' + test) # Run the test in a clean environment to make sure they're # really self-contained path = compat.getenv("PATH") compat.unsetenv("PATH") prog = find_exepath(test, 'dist') if prog is None: print "ERROR: no file generated by PyInstaller found!" compat.setenv("PATH", path) return 1 else: print "RUNNING:", prog tmp = compat.exec_command_rc(prog) compat.setenv("PATH", path) return tmp
def _run_created_exe(self, prog): """ Run executable created by PyInstaller. """ # Run the test in a clean environment to make sure they're # really self-contained path = compat.getenv('PATH') compat.unsetenv('PATH') # For Windows we need to keep minimal PATH for sucessful running of some tests. if is_win: # Minimum Windows PATH is in most cases: C:\Windows\system32;C:\Windows compat.setenv('PATH', os.pathsep.join(winutils.get_system_path())) self._plain_msg("RUNNING: " + prog) old_wd = os.getcwd() os.chdir(os.path.dirname(prog)) # Run executable. prog = os.path.join(os.curdir, os.path.basename(prog)) proc = subprocess.Popen([prog], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Prints stdout of subprocess continuously. self._msg('STDOUT %s' % self.test_name) while proc.poll() is None: # We need to read a line, not single bytes. Otherwise decoding # would ail. line = proc.stdout.readline() self._plain_msg(line.decode('utf-8'), newline=False) # Print any stdout that wasn't read before the process terminated. # See the conversation in https://github.com/pyinstaller/pyinstaller/pull/1092 # for examples of why this is necessary. self._plain_msg(proc.stdout.read().decode('utf-8'), newline=False) # Print possible stderr at the end. stderr = proc.stderr.read().decode('utf-8') self._msg('STDERR %s' % self.test_name) self._plain_msg(stderr) compat.setenv("PATH", path) # Restore current working directory os.chdir(old_wd) return proc.returncode, stderr
def django_dottedstring_imports(django_root_dir): """ Get all the necessary Django modules specified in settings.py. In the settings.py the modules are specified in several variables as strings. """ package_name = os.path.basename(django_root_dir) compat.setenv('DJANGO_SETTINGS_MODULE', '%s.settings' % package_name) # Extend PYTHONPATH with parent dir of django_root_dir. PyInstaller.__pathex__.append(misc.get_path_to_toplevel_modules(django_root_dir)) # Extend PYTHONPATH with django_root_dir. # Many times Django users do not specify absolute imports in the settings module. PyInstaller.__pathex__.append(django_root_dir) ret = eval_script('django-import-finder.py') # Unset environment variables again. compat.unsetenv('DJANGO_SETTINGS_MODULE') return ret
def _run_created_exe(self, prog): """ Run executable created by PyInstaller. """ # Run the test in a clean environment to make sure they're # really self-contained path = compat.getenv('PATH') compat.unsetenv('PATH') # For Windows we need to keep minimal PATH for sucessful running of some tests. if is_win: # Minimum Windows PATH is in most cases: C:\Windows\system32;C:\Windows compat.setenv('PATH', os.pathsep.join(winutils.get_system_path())) self._plain_msg("RUNNING: " + prog) old_wd = compat.getcwd() os.chdir(os.path.dirname(prog)) # Run executable. prog = os.path.join(os.curdir, os.path.basename(prog)) proc = subprocess.Popen([prog], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Prints stdout of subprocess continuously. self._msg('STDOUT %s' % self.test_name) while proc.poll() is None: # We need to read a line, not single bytes. Otherwise decoding # would ail. line = proc.stdout.readline() self._plain_msg(line.decode('utf-8'), newline=False) # Print any stdout that wasn't read before the process terminated. # See the conversation in https://github.com/pyinstaller/pyinstaller/pull/1092 # for examples of why this is necessary. self._plain_msg(proc.stdout.read().decode('utf-8'), newline=False) # Print possible stderr at the end. stderr = proc.stderr.read().decode('utf-8') self._msg('STDERR %s' % self.test_name) self._plain_msg(stderr) compat.setenv("PATH", path) # Restore current working directory os.chdir(old_wd) return proc.returncode, stderr
def __exec_python_cmd(cmd): """ Executes an externally spawned Python interpreter and returns anything that was emitted in the standard output as a single string. """ # Prepend PYTHONPATH with pathex pp = os.pathsep.join(PyInstaller.__pathex__) old_pp = compat.getenv('PYTHONPATH') if old_pp: pp = os.pathsep.join([old_pp, pp]) compat.setenv("PYTHONPATH", pp) try: try: txt = compat.exec_python(*cmd) except OSError, e: raise SystemExit("Execution failed: %s" % e) finally: if old_pp is not None: compat.setenv("PYTHONPATH", old_pp) else: compat.unsetenv("PYTHONPATH") return txt.strip()
def __exec_python_cmd(cmd): """ Executes an externally spawned Python interpreter and returns anything that was emitted in the standard output as a single string. """ # Prepend PYTHONPATH with pathex pp = os.pathsep.join(PyInstaller.__pathex__) old_pp = compat.getenv('PYTHONPATH') if old_pp: pp = os.pathsep.join([pp, old_pp]) compat.setenv("PYTHONPATH", pp) try: try: txt = compat.exec_python(*cmd) except OSError, e: raise SystemExit("Execution failed: %s" % e) finally: if old_pp is not None: compat.setenv("PYTHONPATH", old_pp) else: compat.unsetenv("PYTHONPATH") return txt.strip()
def _run_created_exe(self, test, testdir=None): """ Run executable created by PyInstaller. """ self._msg('EXECUTING TEST ' + self.test_name) # Run the test in a clean environment to make sure they're # really self-contained path = compat.getenv('PATH') compat.unsetenv('PATH') # For Windows we need to keep minimal PATH for sucessful running of some tests. if is_win: # Minimum Windows PATH is in most cases: C:\Windows\system32;C:\Windows compat.setenv('PATH', os.pathsep.join(winutils.get_system_path())) prog = self._find_exepath(test, 'dist') if prog is None: self._plain_msg('ERROR: no file generated by PyInstaller found!') compat.setenv("PATH", path) return 1 else: self._plain_msg("RUNNING: " + prog) old_wd = os.getcwd() os.chdir(os.path.dirname(prog)) # Run executable. prog = os.path.join(os.curdir, os.path.basename(prog)) proc = subprocess.Popen([prog], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Prints stdout of subprocess continuously. self._msg('STDOUT %s' % self.test_name) while proc.poll() is None: #line = proc.stdout.readline().strip() line = proc.stdout.read(1) self._plain_msg(line, newline=False) # Print possible stderr at the end. self._msg('STDERR %s' % self.test_name) self._plain_msg(proc.stderr.read()) compat.setenv("PATH", path) # Restore current working directory os.chdir(old_wd) return proc.returncode
import PyInstaller import PyInstaller.compat as compat from hookutils import django_dottedstring_imports, find_django_root python_path = compat.getenv("PYTHONPATH") if python_path: python_path = os.pathsep.join([python_path] + PyInstaller.__pathex__) else: python_path = os.pathsep.join(PyInstaller.__pathex__) django_root_dirs = [find_django_root(path) for path in python_path.split(os.pathsep)] if not django_root_dirs: raise RuntimeError("No django root directory found. Please check your " "pathex definition in the project spec file.") if django_root_dirs[0] in PyInstaller.__pathex__: raise RuntimeError("The django root directory is defined in the pathex. " "You have to define the parent directory instead of " "the django root directory.") compat.setenv("PYTHONPATH", python_path) hiddenimports = [django_dottedstring_imports(root_dir) for root_dir in django_root_dirs]
def django_dottedstring_imports(django_root_dir): package_name = os.path.basename(django_root_dir) compat.setenv("DJANGO_SETTINGS_MODULE", "%s.settings" % package_name) return eval_script("django-import-finder.py")
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA import os import PyInstaller.compat as compat from hookutils import logger if not compat.getenv("DJANGO_SETTINGS_MODULE"): compat.setenv("DJANGO_SETTINGS_MODULE", "settings") from django.conf import settings hiddenimports = (list(settings.AUTHENTICATION_BACKENDS) + [settings.DEFAULT_FILE_STORAGE] + list(settings.FILE_UPLOAD_HANDLERS) + list(settings.INSTALLED_APPS) + list(settings.MIDDLEWARE_CLASSES) + list(settings.TEMPLATE_CONTEXT_PROCESSORS) + list(settings.TEMPLATE_LOADERS) + [settings.ROOT_URLCONF]) def find_url_callbacks(urls_module): urlpatterns = urls_module.urlpatterns hid_list = [urls_module.__name__]
def _restorePaths(old): if old is None: compat.unsetenv(envvar) else: compat.setenv(envvar, old)
import PyInstaller import PyInstaller.compat as compat from hookutils import django_dottedstring_imports, find_django_root python_path = compat.getenv("PYTHONPATH") if python_path: python_path = os.pathsep.join([python_path] + PyInstaller.__pathex__) else: python_path = os.pathsep.join(PyInstaller.__pathex__) django_root_dirs = [ find_django_root(path) for path in python_path.split(os.pathsep) ] if not django_root_dirs: raise RuntimeError("No django root directory found. Please check your " "pathex definition in the project spec file.") if django_root_dirs[0] in PyInstaller.__pathex__: raise RuntimeError("The django root directory is defined in the pathex. " "You have to define the parent directory instead of " "the django root directory.") compat.setenv("PYTHONPATH", python_path) hiddenimports = [ django_dottedstring_imports(root_dir) for root_dir in django_root_dirs ]
# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA import PyInstaller.compat as compat from hookutils import logger if not compat.getenv("DJANGO_SETTINGS_MODULE"): compat.setenv("DJANGO_SETTINGS_MODULE", "settings") from django.conf import settings hiddenimports = (list(settings.AUTHENTICATION_BACKENDS) + [settings.DEFAULT_FILE_STORAGE] + list(settings.FILE_UPLOAD_HANDLERS) + list(settings.INSTALLED_APPS) + list(settings.MIDDLEWARE_CLASSES) + list(settings.TEMPLATE_CONTEXT_PROCESSORS) + list(settings.TEMPLATE_LOADERS) + [settings.ROOT_URLCONF]) def find_url_callbacks(urls_module): urlpatterns = urls_module.urlpatterns