Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_strip_suffix(self):
a = 'foo bar bar'
self.assertEqual(a, utils.strip_suffix(a, 'hello'))
self.assertEqual('foo bar ', utils.strip_suffix(a, 'bar'))
self.assertEqual(a, utils.strip_suffix(a, 'hbar'))
def test_strip_suffix(self):
a = 'foo bar bar'
self.assertEqual(a, utils.strip_suffix(a, 'hello'))
self.assertEqual('foo bar ', utils.strip_suffix(a, 'bar'))
self.assertEqual(a, utils.strip_suffix(a, 'hbar'))
self.env = env
cfg = env.config
self.pythonpath = self.env.pythonpath.split(':')
self.output_dir = cfg.output_dir
self.deps = cfg.deps
self.projects = cfg.projects
self.system_env = {
b'TYPESHED_HOME': env.typeshed_location.encode('utf-8')
}
self.pyi_dir = os.path.join(self.output_dir, 'pyi')
try:
os.makedirs(self.output_dir)
except:
pass
self.log_file = os.path.join(self.output_dir, 'pytype.log')
self.logger = utils.setup_logging('pytype', self.log_file)
def path_from_pythonpath(pythonpath):
"""Create an fs.Path object from a pythonpath string."""
path = fs.Path()
for p in pythonpath.split(os.pathsep):
path.add_path(utils.expand_path(p), 'os')
return path
def get_imports(filename, python_version):
if python_version == sys.version_info[0:2]:
# Invoke import_finder directly
try:
imports = import_finder.get_imports(filename)
except Exception:
raise ParseError(filename)
else:
# Call the appropriate python version in a subprocess
f = sys.modules['importlab.import_finder'].__file__
if f.rsplit('.', 1)[-1] == 'pyc':
# In host Python 2, importlab ships with .pyc files.
f = f[:-1]
ret, stdout, stderr = utils.run_py_file(python_version, f, filename)
if not ret:
if sys.version_info[0] == 3:
stdout = stdout.decode('ascii')
imports = import_finder.read_imports(stdout)
else:
if sys.version_info[0] == 3:
stderr = stderr.decode('ascii')
logging.info(stderr)
raise ParseError(filename)
return [ImportStatement(*imp) for imp in imports]
# Relative import in non-package
raise ImportException(name)
module_name = get_absolute_name(package_name, module_name)
if isinstance(self.current_module, System):
return System(f, module_name)
return Local(f, module_name, fs)
# If the module isn't found in the explicit pythonpath, see if python
# itself resolved it.
if item.source:
prefix, ext = os.path.splitext(item.source)
mod_name = name
# We need to check for importing a symbol here too.
if short_name:
mod = prefix.replace(os.path.sep, '.')
mod = utils.strip_suffix(mod, '.__init__')
if not mod.endswith(name) and mod.endswith(short_name):
mod_name = short_name
if ext == '.pyc':
pyfile = prefix + '.py'
if os.path.exists(pyfile):
return System(pyfile, mod_name)
elif not ext:
pyfile = os.path.join(prefix, "__init__.py")
if os.path.exists(pyfile):
return System(pyfile, mod_name)
return System(item.source, mod_name)
raise ImportException(name)