Python imp.reload() Examples
The following are 30
code examples of imp.reload().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
imp
, or try the search function
.
Example #1
Source File: ModelingCloth.py From Modeling-Cloth with MIT License | 6 votes |
def collision_series(paperback=True, kindle=True): import webbrowser import imp if paperback: webbrowser.open("https://www.createspace.com/6043857") imp.reload(webbrowser) webbrowser.open("https://www.createspace.com/7164863") return if kindle: webbrowser.open("https://www.amazon.com/Resolve-Immortal-Flesh-Collision-Book-ebook/dp/B01CO3MBVQ") imp.reload(webbrowser) webbrowser.open("https://www.amazon.com/Formulacrum-Collision-Book-Rich-Colburn-ebook/dp/B0711P744G") return webbrowser.open("https://www.paypal.com/donate/?token=G1UymFn4CP8lSFn1r63jf_XOHAuSBfQJWFj9xjW9kWCScqkfYUCdTzP-ywiHIxHxYe7uJW&country.x=US&locale.x=US") # ============================================================================================
Example #2
Source File: test_reloading.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_numpy_reloading(): # gh-7844. Also check that relevant globals retain their identity. import numpy as np import numpy._globals _NoValue = np._NoValue VisibleDeprecationWarning = np.VisibleDeprecationWarning ModuleDeprecationWarning = np.ModuleDeprecationWarning reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning) assert_raises(RuntimeError, reload, numpy._globals) reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)
Example #3
Source File: test_reloading.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_numpy_reloading(): # gh-7844. Also check that relevant globals retain their identity. import numpy as np import numpy._globals _NoValue = np._NoValue VisibleDeprecationWarning = np.VisibleDeprecationWarning ModuleDeprecationWarning = np.ModuleDeprecationWarning reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning) assert_raises(RuntimeError, reload, numpy._globals) reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)
Example #4
Source File: test_pixel.py From yatsm with MIT License | 6 votes |
def test_cli_pixel_pass_3(example_timeseries, monkeypatch): """ Correctly run for one pixel when default colormap isn't available """ # Pop out default colormap cmap_d = mpl.cm.cmap_d.copy() cmap_d.pop(yatsm.cli.pixel._DEFAULT_PLOT_CMAP, None) monkeypatch.setattr('matplotlib.cm.cmap_d', cmap_d) # Reload CLI imp.reload(yatsm.cli.pixel) imp.reload(yatsm.cli.main) from yatsm.cli.main import cli runner = CliRunner() result = runner.invoke( cli, ['-v', 'pixel', '--band', '5', '--ylim', '0', '10000', '--plot', 'TS', '--plot', 'DOY', '--plot', 'VAL', '--style', 'ggplot', example_timeseries['config'], '1', '1' ]) assert result.exit_code == 0
Example #5
Source File: include.py From locasploit with GNU General Public License v2.0 | 6 votes |
def load_modules(): """ Import modules from source/modules/ folder """ lib.module_objects = [] lib.modules = {} module_names = [x[:-3] for x in os.listdir('source/modules') if x[0]!='_' and x[-3:] == '.py'] # import/reimport modules for m in module_names: if 'source.modules.' + m in sys.modules: imp.reload(sys.modules['source.modules.' + m]) # TODO deprecated? else: importlib.import_module('source.modules.' + m) # initialize modules dictionary for v in lib.module_objects: if v.name in lib.modules: log.warn('Duplicit module %s.' % (v.name)) lib.modules[v.name] = v log.info('%d modules loaded.' % (len(lib.modules)))
Example #6
Source File: test_reloading.py From recruit with Apache License 2.0 | 6 votes |
def test_numpy_reloading(): # gh-7844. Also check that relevant globals retain their identity. import numpy as np import numpy._globals _NoValue = np._NoValue VisibleDeprecationWarning = np.VisibleDeprecationWarning ModuleDeprecationWarning = np.ModuleDeprecationWarning reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning) assert_raises(RuntimeError, reload, numpy._globals) reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)
Example #7
Source File: test_reloading.py From lambda-packs with MIT License | 6 votes |
def test_numpy_reloading(): # gh-7844. Also check that relevant globals retain their identity. import numpy as np import numpy._globals _NoValue = np._NoValue VisibleDeprecationWarning = np.VisibleDeprecationWarning ModuleDeprecationWarning = np.ModuleDeprecationWarning reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning) assert_raises(RuntimeError, reload, numpy._globals) reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)
Example #8
Source File: test_core.py From deepWordBug with Apache License 2.0 | 6 votes |
def test_missing_ordereddict_uses_module(monkeypatch): "ordereddict module is imported when without collections.OrderedDict." import blessed.keyboard if hasattr(collections, 'OrderedDict'): monkeypatch.delattr('collections.OrderedDict') try: imp.reload(blessed.keyboard) except ImportError as err: assert err.args[0] in ("No module named ordereddict", # py2 "No module named 'ordereddict'") # py3 sys.modules['ordereddict'] = mock.Mock() sys.modules['ordereddict'].OrderedDict = -1 imp.reload(blessed.keyboard) assert blessed.keyboard.OrderedDict == -1 del sys.modules['ordereddict'] monkeypatch.undo() imp.reload(blessed.keyboard) else: assert platform.python_version_tuple() < ('2', '7') # reached by py2.6
Example #9
Source File: test_reloading.py From vnpy_crypto with MIT License | 6 votes |
def test_numpy_reloading(): # gh-7844. Also check that relevant globals retain their identity. import numpy as np import numpy._globals _NoValue = np._NoValue VisibleDeprecationWarning = np.VisibleDeprecationWarning ModuleDeprecationWarning = np.ModuleDeprecationWarning reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning) assert_raises(RuntimeError, reload, numpy._globals) reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)
Example #10
Source File: importer.py From AutomaticPackageReloader with MIT License | 6 votes |
def __import__(self, name, globals=None, locals=None, fromlist=(), level=0): module = self._orig___import__(name, globals, locals, fromlist, level) self.reload(module) if fromlist: from_names = [ name for item in fromlist for name in ( getattr(module, '__all__', []) if item == '*' else (item,) ) ] for name in from_names: value = getattr(module, name, None) if ismodule(value): self.reload(value) return module
Example #11
Source File: test_reloading.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_numpy_reloading(): # gh-7844. Also check that relevant globals retain their identity. import numpy as np import numpy._globals _NoValue = np._NoValue VisibleDeprecationWarning = np.VisibleDeprecationWarning ModuleDeprecationWarning = np.ModuleDeprecationWarning reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning) assert_raises(RuntimeError, reload, numpy._globals) reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)
Example #12
Source File: _pydev_sys_patch.py From PyDev.Debugger with Eclipse Public License 1.0 | 6 votes |
def cancel_patches_in_sys_module(): sys.exc_info = sys.system_exc_info # @UndefinedVariable if sys.version_info[0] >= 3: import builtins # Py3 else: import __builtin__ as builtins if hasattr(sys, "builtin_orig_reload"): builtins.reload = sys.builtin_orig_reload if hasattr(sys, "imp_orig_reload"): import imp imp.reload = sys.imp_orig_reload if hasattr(sys, "importlib_orig_reload"): import importlib importlib.reload = sys.importlib_orig_reload del builtins
Example #13
Source File: ModelingCloth28.py From Modeling-Cloth-2_8 with MIT License | 6 votes |
def collision_series(paperback=True, kindle=True): import webbrowser import imp if paperback: webbrowser.open("https://www.amazon.com/s?i=digital-text&rh=p_27%3ARich+Colburn&s=relevancerank&text=Rich+Colburn&ref=dp_byline_sr_ebooks_1") #imp.reload(webbrowser) #webbrowser.open("https://www.createspace.com/7164863") return if kindle: webbrowser.open("https://www.amazon.com/s?i=digital-text&rh=p_27%3ARich+Colburn&s=relevancerank&text=Rich+Colburn&ref=dp_byline_sr_ebooks_1") #imp.reload(webbrowser) #webbrowser.open("https://www.amazon.com/Formulacrum-Collision-Book-Rich-Colburn-ebook/dp/B0711P744G") return webbrowser.open("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4T4WNFQXGS99A") # ============================================================================================
Example #14
Source File: extensions.py From Computable with MIT License | 6 votes |
def reload_extension(self, module_str): """Reload an IPython extension by calling reload. If the module has not been loaded before, :meth:`InteractiveShell.load_extension` is called. Otherwise :func:`reload` is called and then the :func:`load_ipython_extension` function of the module, if it exists is called. """ from IPython.utils.syspathcontext import prepended_to_syspath if (module_str in self.loaded) and (module_str in sys.modules): self.unload_extension(module_str) mod = sys.modules[module_str] with prepended_to_syspath(self.ipython_extension_dir): reload(mod) if self._call_load_ipython_extension(mod): self.loaded.add(module_str) else: self.load_extension(module_str)
Example #15
Source File: test_core.py From deepWordBug with Apache License 2.0 | 6 votes |
def test_python3_2_raises_exception(monkeypatch): "Test python version 3.0 through 3.2 raises an exception." import blessed monkeypatch.setattr('platform.python_version_tuple', lambda: ('3', '2', '2')) try: imp.reload(blessed) except ImportError as err: assert err.args[0] == ( 'Blessed needs Python 3.2.3 or greater for Python 3 ' 'support due to http://bugs.python.org/issue10570.') monkeypatch.undo() imp.reload(blessed) else: assert False, 'Exception should have been raised'
Example #16
Source File: test_reloading.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def test_numpy_reloading(): # gh-7844. Also check that relevant globals retain their identity. import numpy as np import numpy._globals _NoValue = np._NoValue VisibleDeprecationWarning = np.VisibleDeprecationWarning ModuleDeprecationWarning = np.ModuleDeprecationWarning reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning) assert_raises(RuntimeError, reload, numpy._globals) reload(np) assert_(_NoValue is np._NoValue) assert_(ModuleDeprecationWarning is np.ModuleDeprecationWarning) assert_(VisibleDeprecationWarning is np.VisibleDeprecationWarning)
Example #17
Source File: __init__.py From ibeis with Apache License 2.0 | 5 votes |
def reload_subs(verbose=True): """ Reloads ibeis.algo and submodules """ if verbose: print('Reloading submodules') rrr(verbose=verbose) def wrap_fbrrr(mod): def fbrrr(*args, **kwargs): """ fallback reload """ if verbose: print('Trying fallback relaod for mod=%r' % (mod,)) import imp imp.reload(mod) return fbrrr def get_rrr(mod): if hasattr(mod, 'rrr'): return mod.rrr else: return wrap_fbrrr(mod) def get_reload_subs(mod): return getattr(mod, 'reload_subs', wrap_fbrrr(mod)) get_rrr(Config)(verbose=verbose) get_reload_subs(detect)(verbose=verbose) get_reload_subs(hots)(verbose=verbose) get_reload_subs(preproc)(verbose=verbose) rrr(verbose=verbose) try: # hackish way of propogating up the new reloaded submodule attributes reassign_submodule_attributes(verbose=verbose) except Exception as ex: print(ex)
Example #18
Source File: autoreload.py From Computable with MIT License | 5 votes |
def aimport(self, parameter_s='', stream=None): """%aimport => Import modules for automatic reloading. %aimport List modules to automatically import and not to import. %aimport foo Import module 'foo' and mark it to be autoreloaded for %autoreload 1 %aimport -foo Mark module 'foo' to not be autoreloaded for %autoreload 1 """ modname = parameter_s if not modname: to_reload = self._reloader.modules.keys() to_reload.sort() to_skip = self._reloader.skip_modules.keys() to_skip.sort() if stream is None: stream = sys.stdout if self._reloader.check_all: stream.write("Modules to reload:\nall-except-skipped\n") else: stream.write("Modules to reload:\n%s\n" % ' '.join(to_reload)) stream.write("\nModules to skip:\n%s\n" % ' '.join(to_skip)) elif modname.startswith('-'): modname = modname[1:] self._reloader.mark_module_skipped(modname) else: top_module, top_name = self._reloader.aimport_module(modname) # Inject module to user namespace self.shell.push({top_name: top_module})
Example #19
Source File: test_simplepush_plugin.py From apprise with MIT License | 5 votes |
def test_simplepush_plugin(tmpdir): """ API: NotifySimplePush Plugin() """ suite = tmpdir.mkdir("simplepush") suite.join("__init__.py").write('') module_name = 'cryptography' suite.join("{}.py".format(module_name)).write('raise ImportError()') # Update our path to point to our new test suite sys.path.insert(0, str(suite)) for name in list(sys.modules.keys()): if name.startswith('{}.'.format(module_name)): del sys.modules[name] del sys.modules[module_name] # The following libraries need to be reloaded to prevent # TypeError: super(type, obj): obj must be an instance or subtype of type # This is better explained in this StackOverflow post: # https://stackoverflow.com/questions/31363311/\ # any-way-to-manually-fix-operation-of-\ # super-after-ipython-reload-avoiding-ty # reload(sys.modules['apprise.plugins.NotifySimplePush']) reload(sys.modules['apprise.plugins']) reload(sys.modules['apprise.Apprise']) reload(sys.modules['apprise']) # imported and therefore the extra encryption offered by SimplePush is # not available... obj = apprise.Apprise.instantiate('spush://salt:pass@valid_api_key') assert obj is not None # Tidy-up / restore things to how they were os.unlink(str(suite.join("{}.py".format(module_name)))) reload(sys.modules['apprise.plugins.NotifySimplePush']) reload(sys.modules['apprise.plugins']) reload(sys.modules['apprise.Apprise']) reload(sys.modules['apprise'])
Example #20
Source File: test_imp.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_extension(self): with support.CleanImport('time'): import time imp.reload(time)
Example #21
Source File: test_imp.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_builtin(self): with support.CleanImport('marshal'): import marshal imp.reload(marshal)
Example #22
Source File: _pydev_sys_patch.py From PyDev.Debugger with Eclipse Public License 1.0 | 5 votes |
def patch_reload(): if sys.version_info[0] >= 3: import builtins # Py3 else: import __builtin__ as builtins if hasattr(builtins, "reload"): sys.builtin_orig_reload = builtins.reload builtins.reload = patched_reload(sys.builtin_orig_reload) # @UndefinedVariable try: import imp sys.imp_orig_reload = imp.reload imp.reload = patched_reload(sys.imp_orig_reload) # @UndefinedVariable except: pass else: try: import importlib sys.importlib_orig_reload = importlib.reload # @UndefinedVariable importlib.reload = patched_reload(sys.importlib_orig_reload) # @UndefinedVariable except: pass del builtins
Example #23
Source File: test_imp.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_with_deleted_parent(self): # see #18681 from html import parser html = sys.modules.pop('html') def cleanup(): sys.modules['html'] = html self.addCleanup(cleanup) with self.assertRaisesRegex(ImportError, 'html'): imp.reload(parser)
Example #24
Source File: test_imp.py From oss-ftp with MIT License | 5 votes |
def test_extension(self): with test_support.CleanImport('time'): import time imp.reload(time)
Example #25
Source File: test_imp.py From oss-ftp with MIT License | 5 votes |
def test_source(self): # XXX (ncoghlan): It would be nice to use test_support.CleanImport # here, but that breaks because the os module registers some # handlers in copy_reg on import. Since CleanImport doesn't # revert that registration, the module is left in a broken # state after reversion. Reinitialising the module contents # and just reverting os.environ to its previous state is an OK # workaround with test_support.EnvironmentVarGuard(): import os imp.reload(os)
Example #26
Source File: test_import.py From oss-ftp with MIT License | 5 votes |
def test_infinite_reload(self): # http://bugs.python.org/issue742342 reports that Python segfaults # (infinite recursion in C) when faced with self-recursive reload()ing. sys.path.insert(0, os.path.dirname(__file__)) try: import infinite_reload finally: del sys.path[0]
Example #27
Source File: test_import.py From oss-ftp with MIT License | 5 votes |
def test_failing_reload(self): # A failing reload should leave the module object in sys.modules. source = TESTFN + os.extsep + "py" with open(source, "w") as f: print >> f, "a = 1" print >> f, "b = 2" sys.path.insert(0, os.curdir) try: mod = __import__(TESTFN) self.assertIn(TESTFN, sys.modules) self.assertEqual(mod.a, 1, "module has wrong attribute values") self.assertEqual(mod.b, 2, "module has wrong attribute values") # On WinXP, just replacing the .py file wasn't enough to # convince reload() to reparse it. Maybe the timestamp didn't # move enough. We force it to get reparsed by removing the # compiled file too. remove_files(TESTFN) # Now damage the module. with open(source, "w") as f: print >> f, "a = 10" print >> f, "b = 20//0" self.assertRaises(ZeroDivisionError, imp.reload, mod) # But we still expect the module to be in sys.modules. mod = sys.modules.get(TESTFN) self.assertIsNot(mod, None, "expected module to be in sys.modules") # We should have replaced a w/ 10, but the old b value should # stick. self.assertEqual(mod.a, 10, "module has wrong attribute values") self.assertEqual(mod.b, 2, "module has wrong attribute values") finally: del sys.path[0] remove_files(TESTFN) unload(TESTFN)
Example #28
Source File: __init__.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def register(): #################### # F8 - key import imp imp.reload(fpx_ui) # F8 - key #################### fpx_ui.register() register_module(__name__) INFO_MT_file_import.append(FpmImportOperator.menu_func) INFO_MT_file_import.append(FplImportOperator.menu_func) INFO_MT_file_import.append(FptImportOperator.menu_func)
Example #29
Source File: test_standard_library.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 5 votes |
def test_reload(self): """ reload has been moved to the imp module """ import imp imp.reload(imp) self.assertTrue(True)
Example #30
Source File: data_curation_functions.py From AMPL with MIT License | 5 votes |
def atom_curation(targ_lst, smiles_lst, shared_inchi_keys): imp.reload(curate_data) tolerance=10 column='PIC50'; #'standard_value' list_bad_duplicates='No' max_std=1 curated_lst=[] num_dropped_lst=[] #print(targ_lst) #print(smiles_lst) for it in range(len(targ_lst)) : data=smiles_lst[it] data = data[data.standard_relation.str.strip() == '='] print("gene_names",data.gene_names.unique()) print("standard_type",data.standard_type.unique()) print("standard_relation",data.standard_relation.unique()) print("before",data.shape) curated_df=curate_data.average_and_remove_duplicates (column, tolerance, list_bad_duplicates, data, max_std, compound_id='standard_inchi_key',smiles_col='rdkit_smiles') # (Yaru) Remove inf in curated_df curated_df = curated_df[~curated_df.isin([np.inf]).any(1)] # (Yaru) Remove nan on rdkit_smiles curated_df = curated_df.dropna(subset=['rdkit_smiles']) curated_lst.append(curated_df) prev_cmpd_cnt=shared_inchi_keys.nunique() num_dropped=prev_cmpd_cnt-curated_df.shape[0] num_dropped_lst.append(num_dropped) print("After",curated_df.shape, "# of dropped compounds",num_dropped) return curated_lst,num_dropped_lst # Use Kevin's "aggregate_assay_data()" to remove duplicates and generate base rdkit smiles