本文整理汇总了Python中mozpack.path.abspath函数的典型用法代码示例。如果您正苦于以下问题:Python abspath函数的具体用法?Python abspath怎么用?Python abspath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了abspath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self,
topsrcdir='/path/to/topsrcdir',
extra_substs={},
error_is_fatal=True,
):
self.topsrcdir = mozpath.abspath(topsrcdir)
self.topobjdir = mozpath.abspath('/path/to/topobjdir')
self.substs = ReadOnlyDict({
'MOZ_FOO': 'foo',
'MOZ_BAR': 'bar',
'MOZ_TRUE': '1',
'MOZ_FALSE': '',
'DLL_PREFIX': 'lib',
'DLL_SUFFIX': '.so'
}, **extra_substs)
self.substs_unicode = ReadOnlyDict({k.decode('utf-8'): v.decode('utf-8',
'replace') for k, v in self.substs.items()})
self.defines = self.substs
self.external_source_dir = None
self.lib_prefix = 'lib'
self.lib_suffix = '.a'
self.import_prefix = 'lib'
self.import_suffix = '.so'
self.dll_prefix = 'lib'
self.dll_suffix = '.so'
self.error_is_fatal = error_is_fatal
示例2: __init__
def __init__(self, paths, config, environ, *args, **kwargs):
self._search_path = environ.get('PATH', '').split(os.pathsep)
self._subprocess_paths = {
mozpath.abspath(k): v for k, v in paths.iteritems() if v
}
paths = paths.keys()
environ = dict(environ)
if 'CONFIG_SHELL' not in environ:
environ['CONFIG_SHELL'] = mozpath.abspath('/bin/sh')
self._subprocess_paths[environ['CONFIG_SHELL']] = self.shell
paths.append(environ['CONFIG_SHELL'])
self._environ = copy.copy(environ)
vfs = ConfigureTestVFS(paths)
self.OS = ReadOnlyNamespace(path=ReadOnlyNamespace(**{
k: v if k not in ('exists', 'isfile')
else getattr(vfs, k)
for k, v in ConfigureSandbox.OS.path.__dict__.iteritems()
}))
super(ConfigureTestSandbox, self).__init__(config, environ, *args,
**kwargs)
示例3: __init__
def __init__(self, paths, config, environ, *args, **kwargs):
self._search_path = environ.get('PATH', '').split(os.pathsep)
self._subprocess_paths = {
mozpath.abspath(k): v for k, v in paths.iteritems() if v
}
paths = paths.keys()
environ = dict(environ)
if 'CONFIG_SHELL' not in environ:
environ['CONFIG_SHELL'] = mozpath.abspath('/bin/sh')
self._subprocess_paths[environ['CONFIG_SHELL']] = self.shell
paths.append(environ['CONFIG_SHELL'])
self._environ = copy.copy(environ)
vfs = ConfigureTestVFS(paths)
os_path = {
k: getattr(vfs, k) for k in dir(vfs) if not k.startswith('_')
}
os_path.update(self.OS.path.__dict__)
self.imported_os = ReadOnlyNamespace(path=ReadOnlyNamespace(**os_path))
super(ConfigureTestSandbox, self).__init__(config, environ, *args,
**kwargs)
示例4: test_mismatched_compiler
def test_mismatched_compiler(self):
self.do_toolchain_test(self.PATHS, {
'c_compiler': self.GCC_4_9_RESULT,
'cxx_compiler': (
'The target C compiler is gcc, while the target C++ compiler '
'is clang. Need to use the same compiler suite.'),
}, environ={
'CXX': 'clang++',
})
self.do_toolchain_test(self.PATHS, {
'c_compiler': self.GCC_4_9_RESULT,
'cxx_compiler': self.GXX_4_9_RESULT,
'host_c_compiler': self.GCC_4_9_RESULT,
'host_cxx_compiler': (
'The host C compiler is gcc, while the host C++ compiler '
'is clang. Need to use the same compiler suite.'),
}, environ={
'HOST_CXX': 'clang++',
})
self.do_toolchain_test(self.PATHS, {
'c_compiler': '`%s` is not a C compiler.'
% mozpath.abspath('/usr/bin/g++'),
}, environ={
'CC': 'g++',
})
self.do_toolchain_test(self.PATHS, {
'c_compiler': self.GCC_4_9_RESULT,
'cxx_compiler': '`%s` is not a C++ compiler.'
% mozpath.abspath('/usr/bin/gcc'),
}, environ={
'CXX': 'gcc',
})
示例5: setUpClass
def setUpClass(cls):
class Config(object):
pass
cls.config = config = Config()
config.topsrcdir = mozpath.abspath(os.curdir)
config.topobjdir = mozpath.abspath("obj")
config.external_source_dir = None
示例6: test_exec_source_success
def test_exec_source_success(self):
sandbox = self.sandbox()
context = sandbox._context
sandbox.exec_source("foo = True", mozpath.abspath("foo.py"))
self.assertNotIn("foo", context)
self.assertEqual(context.main_path, mozpath.abspath("foo.py"))
self.assertEqual(context.all_paths, set([mozpath.abspath("foo.py")]))
示例7: test_exec_compile_error
def test_exec_compile_error(self):
sandbox = self.sandbox()
with self.assertRaises(SandboxExecutionError) as se:
sandbox.exec_source("2f23;k;asfj", mozpath.abspath("foo.py"))
self.assertEqual(se.exception.file_stack, [mozpath.abspath("foo.py")])
self.assertIsInstance(se.exception.exc_value, SyntaxError)
self.assertEqual(sandbox._context.main_path, mozpath.abspath("foo.py"))
示例8: test_default_state
def test_default_state(self):
sandbox = self.sandbox()
config = sandbox.config
self.assertEqual(sandbox['TOPSRCDIR'], config.topsrcdir)
self.assertEqual(sandbox['TOPOBJDIR'],
mozpath.abspath(config.topobjdir))
self.assertEqual(sandbox['RELATIVEDIR'], '')
self.assertEqual(sandbox['SRCDIR'], config.topsrcdir)
self.assertEqual(sandbox['OBJDIR'],
mozpath.abspath(config.topobjdir).replace(os.sep, '/'))
示例9: test_compiler_result
def test_compiler_result(self):
result = CompilerResult()
self.assertEquals(result.__dict__, {
'wrapper': [],
'compiler': mozpath.abspath(''),
'version': '',
'type': '',
'language': '',
'flags': [],
})
result = CompilerResult(
compiler='/usr/bin/gcc',
version='4.2.1',
type='gcc',
language='C',
flags=['-std=gnu99'],
)
self.assertEquals(result.__dict__, {
'wrapper': [],
'compiler': mozpath.abspath('/usr/bin/gcc'),
'version': '4.2.1',
'type': 'gcc',
'language': 'C',
'flags': ['-std=gnu99'],
})
result2 = result + {'flags': ['-m32']}
self.assertEquals(result2.__dict__, {
'wrapper': [],
'compiler': mozpath.abspath('/usr/bin/gcc'),
'version': '4.2.1',
'type': 'gcc',
'language': 'C',
'flags': ['-std=gnu99', '-m32'],
})
# Original flags are untouched.
self.assertEquals(result.flags, ['-std=gnu99'])
result3 = result + {
'compiler': '/usr/bin/gcc-4.7',
'version': '4.7.3',
'flags': ['-m32'],
}
self.assertEquals(result3.__dict__, {
'wrapper': [],
'compiler': mozpath.abspath('/usr/bin/gcc-4.7'),
'version': '4.7.3',
'type': 'gcc',
'language': 'C',
'flags': ['-std=gnu99', '-m32'],
})
示例10: _get_files_info
def _get_files_info(self, paths):
from mozpack.files import FileFinder
# Normalize to relative from topsrcdir.
relpaths = []
for p in paths:
a = mozpath.abspath(p)
if not mozpath.basedir(a, [self.topsrcdir]):
raise InvalidPathException('path is outside topsrcdir: %s' % p)
relpaths.append(mozpath.relpath(a, self.topsrcdir))
finder = FileFinder(self.topsrcdir, find_executables=False)
# Expand wildcards.
allpaths = []
for p in relpaths:
if '*' not in p:
if p not in allpaths:
allpaths.append(p)
continue
for path, f in finder.find(p):
if path not in allpaths:
allpaths.append(path)
reader = self._get_reader()
return reader.files_info(allpaths)
示例11: include_file
def include_file(self, path):
'''Include one file in the sandbox. Users of this class probably want
Note: this will execute all template invocations, as well as @depends
functions that depend on '--help', but nothing else.
'''
if self._paths:
path = mozpath.join(mozpath.dirname(self._paths[-1]), path)
path = mozpath.normpath(path)
if not mozpath.basedir(path, (mozpath.dirname(self._paths[0]),)):
raise ConfigureError(
'Cannot include `%s` because it is not in a subdirectory '
'of `%s`' % (path, mozpath.dirname(self._paths[0])))
else:
path = mozpath.realpath(mozpath.abspath(path))
if path in self._all_paths:
raise ConfigureError(
'Cannot include `%s` because it was included already.' % path)
self._paths.append(path)
self._all_paths.add(path)
source = open(path, 'rb').read()
code = compile(source, path, 'exec')
exec_(code, self)
self._paths.pop(-1)
示例12: test_imply_option_immediate_value
def test_imply_option_immediate_value(self):
def get_config(*args):
return self.get_config(
*args, configure='imply_option/imm.configure')
help, config = get_config(['--help'])
self.assertEquals(config, {})
config = get_config([])
self.assertEquals(config, {})
config_path = mozpath.abspath(
mozpath.join(test_data_path, 'imply_option', 'imm.configure'))
with self.assertRaisesRegexp(InvalidOptionError,
"--enable-foo' implied by 'imply_option at %s:7' conflicts with "
"'--disable-foo' from the command-line" % config_path):
get_config(['--disable-foo'])
with self.assertRaisesRegexp(InvalidOptionError,
"--enable-bar=foo,bar' implied by 'imply_option at %s:16' conflicts"
" with '--enable-bar=a,b,c' from the command-line" % config_path):
get_config(['--enable-bar=a,b,c'])
with self.assertRaisesRegexp(InvalidOptionError,
"--enable-baz=BAZ' implied by 'imply_option at %s:25' conflicts"
" with '--enable-baz=QUUX' from the command-line" % config_path):
get_config(['--enable-baz=QUUX'])
示例13: which
def which(self, command, path=None):
for parent in (path or self._search_path):
c = mozpath.abspath(mozpath.join(parent, command))
for candidate in (c, ensure_exe_extension(c)):
if self.imported_os.path.exists(candidate):
return candidate
raise WhichError()
示例14: isfile
def isfile(self, path):
path = mozpath.abspath(path)
if path in self._paths:
return True
if mozpath.basedir(path, [topsrcdir, topobjdir]):
return os.path.isfile(path)
return False
示例15: do_toolchain_test
def do_toolchain_test(self, paths, results, args=[], environ={}):
'''Helper to test the toolchain checks from toolchain.configure.
- `paths` is a dict associating compiler paths to FakeCompiler
definitions from above.
- `results` is a dict associating result variable names from
toolchain.configure (c_compiler, cxx_compiler, host_c_compiler,
host_cxx_compiler) with a result.
The result can either be an error string, or a dict with the
following items: flags, version, type, compiler, wrapper. (wrapper
can be omitted when it's empty). Those items correspond to the
attributes of the object returned by toolchain.configure checks
and will be compared to them.
When the results for host_c_compiler are identical to c_compiler,
they can be omitted. Likewise for host_cxx_compiler vs.
cxx_compiler.
'''
environ = dict(environ)
if 'PATH' not in environ:
environ['PATH'] = os.pathsep.join(
mozpath.abspath(p) for p in ('/bin', '/usr/bin'))
sandbox = self.get_sandbox(paths, {}, args, environ,
logger=self.logger)
for var in ('c_compiler', 'cxx_compiler', 'host_c_compiler',
'host_cxx_compiler'):
if var in results:
result = results[var]
elif var.startswith('host_'):
result = results.get(var[5:], {})
else:
result = {}
if isinstance(result, dict):
result = dict(result)
result.setdefault('wrapper', [])
result['compiler'] = mozpath.abspath(result['compiler'])
try:
self.out.truncate(0)
compiler = sandbox._value_for(sandbox[var])
# Add var on both ends to make it clear which of the
# variables is failing the test when that happens.
self.assertEquals((var, compiler.__dict__), (var, result))
except SystemExit:
self.assertEquals((var, result),
(var, self.out.getvalue().strip()))
return