mirror of
https://github.com/samba-team/samba.git
synced 2025-03-09 08:58:35 +03:00
s4-python: Add convenience function for forcibly importing bundled
package.
This commit is contained in:
parent
bdf5a49cec
commit
636d8cfb42
@ -29,10 +29,8 @@ samba.ensure_external_module("subunit", "subunit/python")
|
||||
try:
|
||||
from subunit.run import SubunitTestRunner, TestProgram
|
||||
except ImportError:
|
||||
del sys.modules["subunit"]
|
||||
if "subunit.run" in sys.modules:
|
||||
del sys.modules["subunit.run"]
|
||||
samba.import_bundled_package("subunit", "subunit/python")
|
||||
samba.force_bundled_package("testtools", "testtools")
|
||||
samba.force_bundled_package("subunit", "subunit/python")
|
||||
from subunit.run import SubunitTestRunner, TestProgram
|
||||
import samba.getopt as options
|
||||
import samba.tests
|
||||
|
@ -324,6 +324,21 @@ def import_bundled_package(modulename, location):
|
||||
"samba.external.%s" % modulename, fromlist=["samba.external"])
|
||||
|
||||
|
||||
def force_bundled_package(packagename, location):
|
||||
"""Forcibly use the bundled package.
|
||||
|
||||
This will first unload the system module and then load the bundled one.
|
||||
|
||||
:param packagename: The package name
|
||||
:param location: Location to add to sys.path (can be relative to
|
||||
${srcdir}/lib)
|
||||
"""
|
||||
for m in sys.modules.keys():
|
||||
if m.startswith("%s." % packagename):
|
||||
del sys.modules[m]
|
||||
import_bundled_package(packagename, location)
|
||||
|
||||
|
||||
def ensure_external_module(modulename, location):
|
||||
"""Add a location to sys.path if an external dependency can't be found.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user