def run(mmain): import runpy # search sys.path for module and run corresponding .py file as script # NOTE runpy._run_module_as_main works on sys.modules['__main__'] sysmain = sys.modules['__main__'] assert sysmain is mmain, (sysmain, mmain) runpy._run_module_as_main(mod)
def main(): command = sys.argv[1:] if len(command) == 0: command = [] for arg in list(pyto.EditorViewController.parseArguments(input("python -m "))): command.append(str(arg)) if len(command) == 0: print(usage) return module_name = command[0] try: del sys.modules[module_name] except KeyError: pass bin = os.path.expanduser("~/Documents/stash_extensions/bin") sys.path.insert(-1, bin) sys.argv = command __clear_mods__() try: runpy._run_module_as_main(module_name) except KeyboardInterrupt: pass except SystemExit: pass except: print(traceback.format_exc()) sys.argv = [sys.argv[0]]
def run_file(file, globals=None, locals=None, is_module=False): module_name = None entry_point_fn = None if is_module: file, _, entry_point_fn = file.partition(':') module_name = file filename = get_fullname(file) if filename is None: sys.stderr.write("No module named %s\n" % file) return else: file = filename if os.path.isdir(file): new_target = os.path.join(file, '__main__.py') if os.path.isfile(new_target): file = new_target if globals is None: m = save_main_module(file, 'pydev_run_in_console') globals = m.__dict__ try: globals['__builtins__'] = __builtins__ except NameError: pass # Not there on Jython... if locals is None: locals = globals if not is_module: sys.path.insert(0, os.path.split(file)[0]) print('Running %s' % file) try: if not is_module: pydev_imports.execfile(file, globals, locals) # execute the script else: # treat ':' as a seperator between module and entry point function # if there is no entry point we run we same as with -m switch. Otherwise we perform # an import and execute the entry point if entry_point_fn: mod = __import__(module_name, level=0, fromlist=[entry_point_fn], globals=globals, locals=locals) func = getattr(mod, entry_point_fn) func() else: # Run with the -m switch import runpy if hasattr(runpy, '_run_module_as_main'): runpy._run_module_as_main(module_name) else: runpy.run_module(module_name) except: traceback.print_exc() return globals
def run_file(file, globals=None, locals=None, is_module=False): module_name = None entry_point_fn = None if is_module: file, _, entry_point_fn = file.partition(':') module_name = file filename = get_fullname(file) if filename is None: sys.stderr.write("No module named %s\n" % file) return else: file = filename if os.path.isdir(file): new_target = os.path.join(file, '__main__.py') if os.path.isfile(new_target): file = new_target if globals is None: m = save_main_module(file, 'pydev_run_in_console') globals = m.__dict__ try: globals['__builtins__'] = __builtins__ except NameError: pass # Not there on Jython... if locals is None: locals = globals if not is_module: sys.path.insert(0, os.path.split(file)[0]) print('Running %s' % file) try: if not is_module: pydev_imports.execfile(file, globals, locals) # execute the script else: # treat ':' as a seperator between module and entry point function # if there is no entry point we run we same as with -m switch. Otherwise we perform # an import and execute the entry point if entry_point_fn: mod = __import__(module_name, level=0, fromlist=[entry_point_fn], globals=globals, locals=locals) func = getattr(mod, entry_point_fn) func() else: # Run with the -m switch import runpy if hasattr(runpy, '_run_module_as_main'): runpy._run_module_as_main(module_name) else: runpy.run_module(module_name) except: traceback.print_exc() return globals
def submit(): usr = getpass.getuser() expected_users =["RAM_maint","RAM_clinical:"] if usr not in expected_users: print("This script is meant to be run from RAM_maint not", usr) confirm("Are you sure you want to continue? ") host = socket.gethostname() if "node" not in host: print("This script is best run from a node not the headnode (use qlogin)") confirm("Are you sure you want to continue? ") runpy._run_module_as_main("event_creation.submission.convenience")
def run(folder): folder = os.path.abspath(folder) module = os.path.basename(folder).replace(".sikuli", "") #print("Running %s from %s" % (module, folder)) sys.path.append(folder) sys.path.append(os.path.dirname(folder)) # FIXME: adding parent is unofficial Settings.ImagePaths.append(folder) try: runpy._run_module_as_main(module) # mod = __import__(module) except KeyboardInterrupt: pass
def run(folder: str) -> None: folder = os.path.abspath(folder) module = os.path.basename(folder).replace(".sikuli", "") # print("Running %s from %s" % (module, folder)) sys.path.append(folder) sys.path.append(os.path.dirname(folder)) # FIXME: adding parent is unofficial Settings.ImagePaths.append(folder) try: runpy._run_module_as_main(module) # mod = __import__(module) except KeyboardInterrupt: pass
def submit(): usr = getpass.getuser() expected_users = ["RAM_maint", "RAM_clinical:"] if usr not in expected_users: print("This script is meant to be run from RAM_maint not", usr) confirm("Are you sure you want to continue? ") host = socket.gethostname() if "node" not in host: print( "This script is best run from a node not the headnode (use qlogin)" ) confirm("Are you sure you want to continue? ") runpy._run_module_as_main("event_creation.submission.convenience")
def _main_function_no_one_calls_a_function_like_that(): command = sys.argv[1:] if len(command) == 0: command = [] args = shlex.split(input("python -m ")) for arg in args: command.append(str(arg)) if len(command) == 0: print(usage) return module_name = command[0] try: del sys.modules[module_name] except KeyError: pass bin = os.path.expanduser("~/Documents/stash_extensions/bin") if not bin in sys.path: sys.path.insert(-1, bin) sys.argv = command __clear_mods__() try: try: sys.modules["__main__"] except KeyError: sys.modules["__main__"] = pyto runpy._run_module_as_main(module_name) except KeyboardInterrupt: pass except SystemExit: pass except: print(traceback.format_exc()) sys.argv = [sys.argv[0]] if bin in sys.path: sys.path.remove(bin)
def main(): del sys.argv[0] parser = argparse.ArgumentParser() parser.add_argument('-m', help='module to run') parser.add_argument('target', help='module to run') parser.add_argument('args', nargs=argparse.REMAINDER) print(sys.argv) args = parser.parse_args() sys.argv = [args.target] + args.args from . import importer importer.install_hook() if args.m: runpy._run_module_as_main(args.target) else: runpy.run_path(args.target, run_name='__main__')
def _run(path): from runpy import _run_module_as_main program_name = os.path.basename(sys.argv[0]) init_name = path.init_mod_name try: init = __import__(init_name) except: init = None if init is None: mod_name = path.main_mod_name else: mod_name = init.get_main_module(path) return _run_module_as_main(mod_name, alter_argv=False)
if sys.argv[0].endswith(".py"): app_dir = sys.argv[0].rpartition("/")[0] if app_dir == '': app_dir = os.getcwd() sys.path.insert(0, app_dir) app_globals = globals() app_globals["__file__"] = sys.argv[0] app_locals = locals() app_locals["__file__"] = sys.argv[0] _execfile(sys.argv[0], app_globals, app_locals) elif sys.argv[0] == "-m": # Run with the -m switch import runpy mod_name = sys.argv[1] sys.argv = sys.argv[1:] if hasattr(runpy, '_run_module_as_main'): # Newer versions of Python actually use this when the -m switch is used. if sys.version_info[:2] <= (2, 6): runpy._run_module_as_main(mod_name, set_argv0=False) else: runpy._run_module_as_main(mod_name, alter_argv=False) else: runpy.run_module(sys.argv[1]) else: print("Unsupported file to execute.", file=sys.stderr) print("Sys args are : {}".format(sys.argv), file=sys.stderr) print("Python Instrumentor exiting.")
package depth of 0 indicates that this would be a top level import. If no relative module name is given, it is derived from the final component in the supplied path with the extension stripped. """ fspath = os.path.abspath(fspath) if modname is None: fspath, modname = _splitmodname(fspath) package_depth = 0 while _is_package_dir(fspath): fspath, pkg = _splitmodname(fspath) modname = pkg + '.' + modname package_depth += 1 return package_depth, fspath, modname if __name__ == '__main__': # Direct script execution if len(sys.argv) < 2: print >> sys.stderr, "%s: No script specified" % sys.argv[0] sys.exit(1) del sys.argv[0] # Make the requested module sys.argv[0] in_package, path_entry, modname = split_path_module(sys.argv[0]) sys.path.insert(0, path_entry) if in_package: runpy._run_module_as_main(modname) else: runpy.run_path(sys.argv[0], run_name='__main__')
import runpy import sys sys.argv[0] = __loader__.archive # Set sys.executable to None. The real executable is available as # sys.argv[0], and too many things assume sys.executable is a regular Python # binary, which isn't available. By setting it to None we get clear errors # when people try to use it. sys.executable = None runpy._run_module_as_main("ENTRY_POINT", alter_argv=False)
def main(): sys.meta_path.insert(0, Finder) PnPReader.read_pnp_config() sys.modules = SysModules() module_name = sys.argv[1] runpy._run_module_as_main(module_name)
def split(): runpy._run_module_as_main("event_creation.submission.readers.eeg_splitter")
Does not support any other ``python.exe`` options or flags, e.g., ``-b``, ``-Q`` (see ``python.exe -h`` for all flags supported by actual CPython). ''' import sys import path_helpers as ph import runpy if __name__ == "__main__": import multiprocessing multiprocessing.freeze_support() if '-h' in sys.argv: print >> sys.stderr, "Usage: python {-m <module> | <script filepath>} [arg [arg ...]]" sys.exit(-1) elif len(sys.argv) < 2: # No script or module was specified. Emulate console using IPython. import IPython IPython.embed() sys.exit() elif sys.argv[1] == '-m': # Emulate `python -m <module>`. del sys.argv[:2] # Make the requested module sys.argv[0] runpy._run_module_as_main(sys.argv[0]) else: __filepath__ = ph.path(sys.argv[1]).realpath() __file__ = str(__filepath__) sys.path.insert(0, __filepath__.parent) exec(__filepath__.text())
def split(): runpy._run_module_as_main("event_creation.submission.readers.eeg_splitter")
def runfile(filename, args=None, wdir=None, is_module=False, global_vars=None): """ Run filename args: command line arguments (string) wdir: working directory """ try: if hasattr(filename, 'decode'): filename = filename.decode('utf-8') except (UnicodeError, TypeError): pass global __umd__ if os.environ.get("PYDEV_UMD_ENABLED", "").lower() == "true": if __umd__ is None: namelist = os.environ.get("PYDEV_UMD_NAMELIST", None) if namelist is not None: namelist = namelist.split(',') __umd__ = UserModuleDeleter(namelist=namelist) else: verbose = os.environ.get("PYDEV_UMD_VERBOSE", "").lower() == "true" __umd__.run(verbose=verbose) if global_vars is None: m = save_main_module(filename, 'pydev_umd') global_vars = m.__dict__ try: global_vars['__builtins__'] = __builtins__ except NameError: pass # Not there on Jython... local_vars = global_vars module_name = None entry_point_fn = None if is_module: file, _, entry_point_fn = filename.partition(':') module_name = file filename = get_fullname(file) if filename is None: sys.stderr.write("No module named %s\n" % file) return else: # The file being run must be in the pythonpath (even if it was not before) sys.path.insert(0, os.path.split(rPath(filename))[0]) global_vars['__file__'] = filename sys.argv = [filename] if args is not None: for arg in args: sys.argv.append(arg) if wdir is not None: try: if hasattr(wdir, 'decode'): wdir = wdir.decode('utf-8') except (UnicodeError, TypeError): pass os.chdir(wdir) try: if not is_module: pydev_imports.execfile(filename, global_vars, local_vars) # execute the script else: # treat ':' as a seperator between module and entry point function # if there is no entry point we run we same as with -m switch. Otherwise we perform # an import and execute the entry point if entry_point_fn: mod = __import__(module_name, level=0, fromlist=[entry_point_fn], globals=global_vars, locals=local_vars) func = getattr(mod, entry_point_fn) func() else: # Run with the -m switch import runpy if hasattr(runpy, '_run_module_as_main'): runpy._run_module_as_main(module_name) else: runpy.run_module(module_name) finally: sys.argv = [''] interpreter_globals = _get_interpreter_globals() interpreter_globals.update(global_vars)
def runfile(filename, args=None, wdir=None, is_module=False, global_vars=None): """ Run filename args: command line arguments (string) wdir: working directory """ try: if hasattr(filename, 'decode'): filename = filename.decode('utf-8') except (UnicodeError, TypeError): pass global __umd__ if os.environ.get("PYDEV_UMD_ENABLED", "").lower() == "true": if __umd__ is None: namelist = os.environ.get("PYDEV_UMD_NAMELIST", None) if namelist is not None: namelist = namelist.split(',') __umd__ = UserModuleDeleter(namelist=namelist) else: verbose = os.environ.get("PYDEV_UMD_VERBOSE", "").lower() == "true" __umd__.run(verbose=verbose) if global_vars is None: m = save_main_module(filename, 'pydev_umd') global_vars = _get_interpreter_globals() global_vars.update(m.__dict__) try: global_vars['__builtins__'] = __builtins__ except NameError: pass # Not there on Jython... local_vars = global_vars module_name = None entry_point_fn = None if is_module: file, _, entry_point_fn = filename.partition(':') module_name = file filename = get_fullname(file) if filename is None: sys.stderr.write("No module named %s\n" % file) return else: # The file being run must be in the pythonpath (even if it was not before) sys.path.insert(0, os.path.split(rPath(filename))[0]) global_vars['__file__'] = filename sys.argv = [filename] if args is not None: for arg in args: sys.argv.append(arg) if wdir is not None: try: if hasattr(wdir, 'decode'): wdir = wdir.decode('utf-8') except (UnicodeError, TypeError): pass os.chdir(wdir) try: if not is_module: pydev_imports.execfile(filename, global_vars, local_vars) # execute the script else: # treat ':' as a seperator between module and entry point function # if there is no entry point we run we same as with -m switch. Otherwise we perform # an import and execute the entry point if entry_point_fn: mod = __import__(module_name, level=0, fromlist=[entry_point_fn], globals=global_vars, locals=local_vars) func = getattr(mod, entry_point_fn) func() else: # Run with the -m switch import runpy if hasattr(runpy, '_run_module_as_main'): runpy._run_module_as_main(module_name) else: runpy.run_module(module_name) finally: sys.argv = [''] interpreter_globals = _get_interpreter_globals() interpreter_globals.update(global_vars)
# mindl - A plugin-based downloading tool. # Copyright (C) 2016 Mino <*****@*****.**> # This file is part of mindl. # mindl is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # mindl 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 mindl. If not, see <http://www.gnu.org/licenses/>. import runpy import sys if __name__ == "__main__": sys.argv[0] = "mindl" runpy._run_module_as_main("mindl")
If no relative module name is given, it is derived from the final component in the supplied path with the extension stripped. """ fspath = os.path.abspath(fspath) if modname is None: fspath, modname = _splitmodname(fspath) package_depth = 0 while _is_package_dir(fspath): fspath, pkg = _splitmodname(fspath) modname = pkg + '.' + modname package_depth += 1 return package_depth, fspath, modname if __name__ == '__main__': # Direct script execution if len(sys.argv) < 2: print >> sys.stderr, "%s: No script specified" % sys.argv[0] sys.exit(1) del sys.argv[0] # Make the requested module sys.argv[0] in_package, path_entry, modname = split_path_module(sys.argv[0]) sys.path.insert(0, path_entry) if in_package: runpy._run_module_as_main(modname) else: runpy.run_path(sys.argv[0], run_name='__main__')
def update_event(self, inp=-1): self.set_output_val(0, runpy._run_module_as_main(self.input(0), self.input(1)))