sys.path.remove

Here are the examples of the python api sys.path.remove taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

57 Examples 7

Example 1

Project: theyworkforyou
Source File: _library.py
View license
def RemoveLibrary(name):
  """Remove a library that has been installed."""
  installed_version, _ = installed[name]
  path = CreatePath(name, installed_version)
  try:
    sys.path.remove(path)
  except ValueError:
    pass
  del installed[name]

Example 2

Project: filesync-server
Source File: test_patch.py
View license
    def tearDown(self):
        super(PatchTest, self).tearDown()
        transaction.abort()
        self.zstorm._reset()
        sys.path.remove(self.patchdir)
        for name in list(sys.modules):
            if name == "mypackage" or name.startswith("mypackage."):
                del sys.modules[name]

Example 3

Project: art_pipeline
Source File: py_env.py
View license
def remove_paths( paths ):
   removed_paths = []
   
   for path in paths:
      sys.path.remove( path )
      removed_paths.append( path )

   return removed_paths

Example 4

Project: python-haystack
Source File: test_listmodel.py
View license
    def tearDown(self):
        self.memory_handler.reset_mappings()
        self.memory_handler = None
        self.m = None
        self.usual = None
        self.ctypes6_gen32 = None
        sys.path.remove('test/src/')

Example 5

Project: habitat
Source File: test_dynamicloader.py
View license
    def teardown(self):
        """clean up the temp folder and path entries"""
        sys.path.remove(self.tempdir)
        if 'unimp' in sys.modules:
            del sys.modules['unimp']
        shutil.rmtree(self.tempdir)

Example 6

Project: abjad
Source File: base.py
View license
    def tearDown(self):
        super(ScorePackageScriptTestCase, self).tearDown()
        for path in sorted(self.test_path.iterdir()):
            if path in self.directory_items:
                continue
            if path.is_file():
                path.unlink()
            else:
                shutil.rmtree(str(path))
        sys.path.remove(str(self.score_path))
        for path, module in tuple(sys.modules.items()):
            if not path or not module:
                continue
            if path.startswith('test_score'):
                del(sys.modules[path])

Example 7

Project: python-haystack
Source File: test_reversers.py
View license
    def tearDown(self):
        self.memory_handler.reset_mappings()
        self.memory_handler = None
        self.m = None
        self.usual = None
        sys.path.remove('test/src/')

Example 8

View license
def _cleanup():
    global _module_dir
    if _module_dir is not None:
        try:
            sys.path.remove(_module_dir)
        except ValueError:
            pass
        try:
            shutil.rmtree(_module_dir)
        except (IOError, OSError):
            pass
        _module_dir = None

Example 9

Project: art_pipeline
Source File: py_env.py
View license
def remove_paths( paths ):
   removed_paths = []
   
   for path in paths:
      sys.path.remove( path )
      removed_paths.append( path )

   return removed_paths

Example 10

Project: SASM
Source File: __init__.py
View license
def GdbSetPythonDirectory(dir):
    """Update sys.path, reload gdb and auto-load packages."""
    global PYTHONDIR

    try:
        sys.path.remove(PYTHONDIR)
    except ValueError:
        pass
    sys.path.insert(0, dir)

    PYTHONDIR = dir

    # note that reload overwrites the gdb module without deleting existing
    # attributes
    reload(__import__(__name__))
    auto_load_packages()

Example 11

View license
def _cleanup():
    global _module_dir
    if _module_dir is not None:
        try:
            sys.path.remove(_module_dir)
        except ValueError:
            pass
        try:
            shutil.rmtree(_module_dir)
        except (IOError, OSError):
            pass
        _module_dir = None

Example 12

Project: simian
Source File: _library.py
View license
def RemoveLibrary(name):
  """Remove a library that has been installed."""
  installed_version, _ = installed[name]
  path = CreatePath(name, installed_version)
  try:
    sys.path.remove(path)
  except ValueError:
    pass
  del installed[name]

Example 13

Project: theyworkforyou
Source File: _library.py
View license
def RemoveLibrary(name):
  """Remove a library that has been installed."""
  installed_version, _ = installed[name]
  path = CreatePath(name, installed_version)
  try:
    sys.path.remove(path)
  except ValueError:
    pass
  del installed[name]

Example 14

Project: filesync-server
Source File: __init__.py
View license
    def tearDown(self):
        for package_dir in self._package_dirs:
            sys.path.remove(package_dir)

        for name in list(sys.modules):
            if name in self._package_names:
                del sys.modules[name]
            elif filter(None, [name.startswith("%s." % x)
                               for x in self._package_names]):
                del sys.modules[name]

        super(MakePackage, self).tearDown()

Example 15

View license
    def tearDown(self):
        super(MultiAppTestCase, self).tearDown()
        sys.path.remove(self.app_directory)
        for app in self.apps:
            del sys.modules[app]
        shutil.rmtree(self.app_directory)

Example 16

Project: python-future
Source File: test_requests.py
View license
    def __exit__(self, exc_type, exc_val, exc_tb):
        """
        If an exception occurred, we leave the file for inspection.
        """
        sys.path.remove(self.tempdir)
        if exc_type is None:
            # No exception occurred
            os.remove(self.tempdir + 'test_imports_future_stdlib.py')
            try:
                os.remove(self.tempdir + 'test_imports_future_stdlib.pyc')
            except OSError:
                pass

Example 17

Project: sqlalchemy-migrate
Source File: pathed.py
View license
    def tearDown(self):
        super(Pathed, self).tearDown()
        try:
            sys.path.remove(self.temp_usable_dir)
        except:
            pass # w00t?
        Pathed.purge(self.temp_usable_dir)

Example 18

View license
    def __exit__(self, exc_type, exc_val, exc_tb):
        """
        If an exception occurred, we leave the file for inspection.
        """
        sys.path.remove(self.tempdir)
        if exc_type is None:
            # No exception occurred
            os.remove(self.tempdir + 'test_imports_future_stdlib.py')
            try:
                os.remove(self.tempdir + 'test_imports_future_stdlib.pyc')
            except OSError:
                pass

Example 19

Project: irc3
Source File: test_template.py
View license
    def setUp(self):
        self.wd = tempfile.mkdtemp(prefix='irc3-template')
        self.addCleanup(os.chdir, os.getcwd())
        self.addCleanup(rmtree, self.wd)
        self.addCleanup(sys.path.remove, self.wd)
        sys.path.append(self.wd)
        os.chdir(self.wd)

Example 20

Project: python101
Source File: test_api_translator.py
View license
def teardown_module():
    sys.path.remove(test_roots / 'test-api-set-translator')

Example 21

Project: json-sempai
Source File: test_sempai.py
View license
    def tearDown(self):
        sys.path.remove(self.direc)
        shutil.rmtree(self.direc)

Example 22

Project: json-sempai
Source File: test_sempai.py
View license
    def tearDown(self):
        sys.path.remove(self.direc)
        shutil.rmtree(self.direc)

Example 23

Project: json-sempai
Source File: test_sempai.py
View license
    def tearDown(self):
        sys.path.remove(self.direc)
        shutil.rmtree(self.direc)

Example 24

Project: shellpy
Source File: test_locator.py
View license
    def tearDown(self):
        sys.path.remove(self.test_dir)

Example 25

Project: django-oscar
Source File: loading_tests.py
View license
    def tearDown(self):
        sys.path.remove('./tests/_site/')

Example 26

Project: shellpy
Source File: test_locator.py
View license
    def tearDown(self):
        sys.path.remove(self.test_dir)

Example 27

Project: python101
Source File: test_api_translator.py
View license
def teardown_module():
    sys.path.remove(test_roots / 'test-api-set-translator')

Example 28

View license
    def tearDown(self, unused=None):
        from _pydevd_bundle import pydevd_traceproperty
        pydevd_traceproperty.replace_builtin_property(self.old)
        sys.path.remove(self.tempdir)

Example 29

Project: socorro
Source File: i18n.py
View license
    def _clear_syspath(self):
        """Clean sys.path of the stuff that we put in it."""
        for path in self._sys_path_modifications:
            sys.path.remove(path)
        self._sys_path_modifications = []

Example 30

Project: sugar
Source File: test_webservice.py
View license
    def tearDown(self):
        sys.path.remove(config.ext_path)
        config.ext_path = self.save_ext_path

Example 31

Project: filmkodi
Source File: test_pydevd_property.py
View license
    def tearDown(self, unused=None):
        from _pydevd_bundle import pydevd_traceproperty
        pydevd_traceproperty.replace_builtin_property(self.old)
        sys.path.remove(self.tempdir)

Example 32

Project: filmkodi
Source File: test_pydevd_property.py
View license
    def tearDown(self, unused=None):
        from _pydevd_bundle import pydevd_traceproperty
        pydevd_traceproperty.replace_builtin_property(self.old)
        sys.path.remove(self.tempdir)

Example 33

Project: json-sempai
Source File: test_sempai.py
View license
    def tearDown(self):
        sys.path.remove(self.direc)
        shutil.rmtree(self.direc)

Example 34

Project: dexy
Source File: pydoc.py
View license
    def __exit__(self, type, value, traceback):
        for dirname in self.additional_dirs:
            sys.path.remove(dirname)

Example 35

Project: luigi
Source File: hadoop_test.py
View license
    def tearDown(self):
        sys.path.remove(os.path.join('test', 'create_packages_archive_root'))

Example 36

Project: python-git-orm
Source File: test_importer.py
View license
def teardown_module():
    sys.path.remove('{}/config'.format(PATH_PREFIX))
    sys.path_hooks.remove(GitImporter)

Example 37

Project: python-git-orm
Source File: test_importer.py
View license
def teardown_module():
    sys.path.remove('{}/config'.format(PATH_PREFIX))
    sys.path_hooks.remove(GitImporter)

Example 38

Project: socorro
Source File: i18n.py
View license
    def _clear_syspath(self):
        """Clean sys.path of the stuff that we put in it."""
        for path in self._sys_path_modifications:
            sys.path.remove(path)
        self._sys_path_modifications = []

Example 39

Project: mythbox
Source File: test_plugin.py
View license
    def test_newPluginsOnReadOnlyPath(self):
        """
        Verify that a failure to write the dropin.cache file on a read-only
        path will not affect the list of plugins returned.

        Note: this test should pass on both Linux and Windows, but may not
        provide useful coverage on Windows due to the different meaning of
        "read-only directory".
        """
        self.unlockSystem()
        self.sysplug.child('newstuff.py').setContent(pluginFileContents('one'))
        self.lockSystem()

        # Take the developer path out, so that the system plugins are actually
        # examined.
        sys.path.remove(self.devPath.path)

        # Sanity check to make sure we're only flushing the error logged
        # below...
        self.assertEqual(len(self.flushLoggedErrors()), 0)
        self.assertIn('one', self.getAllPlugins())
        self.assertEqual(len(self.flushLoggedErrors()), 1)

Example 40

Project: python-haystack
Source File: test_python.py
View license
    def tearDown(self):
        self.memory_handler.reset_mappings()
        self.memory_handler = None
        self.ctypes5_gen32 = None
        sys.path.remove('test/src/')

Example 41

Project: cgstudiomap
Source File: test_discovery.py
View license
    def test_discover_start_dir_is_package_calls_package_load_tests(self):
        # This test verifies that the package load_tests in a package is indeed
        # invoked when the start_dir is a package (and not the top level).
        # http://bugs.python.org/issue22457

        # Test data: we expect the following:
        # an isfile to verify the package, then importing and scanning
        # as per _find_tests' normal behaviour.
        # We expect to see our load_tests hook called once.
        vfs = {abspath('/toplevel'): ['startdir'],
               abspath('/toplevel/startdir'): ['__init__.py']}
        def list_dir(path):
            return list(vfs[path])
        self.addCleanup(setattr, os, 'listdir', os.listdir)
        os.listdir = list_dir
        self.addCleanup(setattr, os.path, 'isfile', os.path.isfile)
        os.path.isfile = lambda path: path.endswith('.py')
        self.addCleanup(setattr, os.path, 'isdir', os.path.isdir)
        os.path.isdir = lambda path: not path.endswith('.py')
        self.addCleanup(sys.path.remove, abspath('/toplevel'))

        class Module(object):
            paths = []
            load_tests_args = []

            def __init__(self, path):
                self.path = path

            def load_tests(self, loader, tests, pattern):
                return ['load_tests called ' + self.path]

            def __eq__(self, other):
                return self.path == other.path

        loader = unittest.TestLoader()
        loader._get_module_from_name = lambda name: Module(name)
        loader.suiteClass = lambda thing: thing

        suite = loader.discover('/toplevel/startdir', top_level_dir='/toplevel')

        # We should have loaded tests from the package __init__.
        # (normally this would be nested TestSuites.)
        self.assertEqual(suite,
                         [['load_tests called startdir']])

Example 42

Project: mythbox
Source File: test_rebuild.py
View license
    def tearDown(self):
        sys.path.remove(self.libPath)

Example 43

Project: cgstudiomap
Source File: test_discovery.py
View license
    def test_find_tests_customise_via_package_pattern(self):
        # This test uses the example 'do-nothing' load_tests from
        # https://docs.python.org/3/library/unittest.html#load-tests-protocol
        # to make sure that that actually works.
        # Housekeeping
        original_listdir = os.listdir
        def restore_listdir():
            os.listdir = original_listdir
        self.addCleanup(restore_listdir)
        original_isfile = os.path.isfile
        def restore_isfile():
            os.path.isfile = original_isfile
        self.addCleanup(restore_isfile)
        original_isdir = os.path.isdir
        def restore_isdir():
            os.path.isdir = original_isdir
        self.addCleanup(restore_isdir)
        self.addCleanup(sys.path.remove, abspath('/foo'))

        # Test data: we expect the following:
        # a listdir to find our package, and a isfile and isdir check on it.
        # a module-from-name call to turn that into a module
        # followed by load_tests.
        # then our load_tests will call discover() which is messy
        # but that finally chains into find_tests again for the child dir -
        # which is why we don't have a infinite loop.
        # We expect to see:
        # the module load tests for both package and plain module called,
        # and the plain module result nested by the package module load_tests
        # indicating that it was processed and could have been mutated.
        vfs = {abspath('/foo'): ['my_package'],
               abspath('/foo/my_package'): ['__init__.py', 'test_module.py']}
        def list_dir(path):
            return list(vfs[path])
        os.listdir = list_dir
        os.path.isdir = lambda path: not path.endswith('.py')
        os.path.isfile = lambda path: path.endswith('.py')

        class Module(object):
            paths = []
            load_tests_args = []

            def __init__(self, path):
                self.path = path
                self.paths.append(path)
                if path.endswith('test_module'):
                    def load_tests(loader, tests, pattern):
                        self.load_tests_args.append((loader, tests, pattern))
                        return [self.path + ' load_tests']
                else:
                    def load_tests(loader, tests, pattern):
                        self.load_tests_args.append((loader, tests, pattern))
                        # top level directory cached on loader instance
                        __file__ = '/foo/my_package/__init__.py'
                        this_dir = os.path.dirname(__file__)
                        pkg_tests = loader.discover(
                            start_dir=this_dir, pattern=pattern)
                        return [self.path + ' load_tests', tests
                            ] + pkg_tests
                self.load_tests = load_tests

            def __eq__(self, other):
                return self.path == other.path

        loader = unittest.TestLoader()
        loader._get_module_from_name = lambda name: Module(name)
        loader.suiteClass = lambda thing: thing

        loader._top_level_dir = abspath('/foo')
        # this time no '.py' on the pattern so that it can match
        # a test package
        suite = list(loader._find_tests(abspath('/foo'), 'test*.py'))

        # We should have loaded tests from both my_package and
        # my_pacakge.test_module, and also run the load_tests hook in both.
        # (normally this would be nested TestSuites.)
        self.assertEqual(suite,
                         [['my_package load_tests', [],
                          ['my_package.test_module load_tests']]])
        # Parents before children.
        self.assertEqual(Module.paths,
                         ['my_package', 'my_package.test_module'])

        # load_tests should have been called twice with loader, tests and pattern
        self.assertEqual(Module.load_tests_args,
                         [(loader, [], 'test*.py'),
                          (loader, [], 'test*.py')])

Example 44

Project: mythbox
Source File: test_plugin.py
View license
    def test_newPluginsOnReadOnlyPath(self):
        """
        Verify that a failure to write the dropin.cache file on a read-only
        path will not affect the list of plugins returned.

        Note: this test should pass on both Linux and Windows, but may not
        provide useful coverage on Windows due to the different meaning of
        "read-only directory".
        """
        self.unlockSystem()
        self.sysplug.child('newstuff.py').setContent(pluginFileContents('one'))
        self.lockSystem()

        # Take the developer path out, so that the system plugins are actually
        # examined.
        sys.path.remove(self.devPath.path)

        # Sanity check to make sure we're only flushing the error logged
        # below...
        self.assertEqual(len(self.flushLoggedErrors()), 0)
        self.assertIn('one', self.getAllPlugins())
        self.assertEqual(len(self.flushLoggedErrors()), 1)

Example 45

Project: cmt
Source File: mayaunittest.py
View license
def get_tests(directories=None, test=None, test_suite=None):
    """Get a unittest.TestSuite containing all the desired tests.

    @param directories: Optional list of directories with which to search for tests.  If omitted, use all "tests"
    directories of the modules found in the MAYA_MODULE_PATH.
    @param test: Optional test path to find a specific test such as 'test_mytest.SomeTestCase.test_function'.
    @param test_suite: Optional unittest.TestSuite to add the discovered tests to.  If omitted a new TestSuite will be
    created.
    @return: The populated TestSuite.
    """
    if directories is None:
        directories = maya_module_tests()

    # Populate a TestSuite with all the tests
    if test_suite is None:
        test_suite = unittest.TestSuite()

    if test:
        # Find the specified test to run
        directories_added_to_path = [p for p in directories if add_to_path(p)]
        discovered_suite = unittest.TestLoader().loadTestsFromName(test)
        if discovered_suite.countTestCases():
            test_suite.addTests(discovered_suite)
    else:
        # Find all tests to run
        directories_added_to_path = []
        for p in directories:
            discovered_suite = unittest.TestLoader().discover(p)
            if discovered_suite.countTestCases():
                test_suite.addTests(discovered_suite)

    # Remove the added paths.
    for path in directories_added_to_path:
        sys.path.remove(path)

    return test_suite

Example 46

Project: mythbox
Source File: test_rebuild.py
View license
    def tearDown(self):
        sys.path.remove(self.libPath)

Example 47

Project: clamp
Source File: build.py
View license
def build_jar(package_name, jar_name, clamp_setup, output_path=None):
    update_jar_pth = not(output_path)
    if output_path is None:
        jar_dir = init_jar_dir()
        output_path = os.path.join(jar_dir, jar_name)
        # Remove the old jar (if present) to prevent from being imported.
        #
        # Note that it will still be scanned by SysPackageManager,
        # because that happens before any user-level Python code (like
        # this module) can be run. This will be addressed when the
        # build preemptively creates such package cache data.
        try:
            sys.path.remove(output_path)
        except ValueError:
            pass
        try:
            os.remove(output_path)
        except OSError:
            pass

    with JarBuilder(output_path=output_path) as builder:
        with register_builder(builder):
            for module in clamp_setup.modules:
                __import__(module)

    if update_jar_pth:
        with JarPth() as paths:
            paths[package_name] = os.path.join("./jars", jar_name)

Example 48

View license
  def remove_path(self, path):
    correct_path = self._get_correct_path(path)
    sys.path.remove(correct_path)
    self.folder_cache.remove(correct_path)

Example 49

Project: deblaze
Source File: test_imports.py
View license
    def tearDown(self):
        sys.path.remove(self.path)

Example 50

Project: python-haystack
Source File: test_text.py
View license
    def tearDown(self):
        self.memory_handler.reset_mappings()
        self.memory_handler = None
        self.ctypes5_gen32 = None
        sys.path.remove('test/src/')