本文整理汇总了Python中pylint.config.find_pylintrc函数的典型用法代码示例。如果您正苦于以下问题:Python find_pylintrc函数的具体用法?Python find_pylintrc怎么用?Python find_pylintrc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find_pylintrc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pylintrc_parentdir_no_package
def test_pylintrc_parentdir_no_package(self):
chroot = tempfile.mkdtemp()
# Get real path of tempfile, otherwise test fail on mac os x
cdir = getcwd()
chdir(chroot)
chroot = abspath('.')
chdir(cdir)
fake_home = tempfile.mkdtemp('fake-home')
home = os.environ['HOME']
os.environ['HOME'] = fake_home
try:
create_files(['a/pylintrc', 'a/b/pylintrc', 'a/b/c/d/__init__.py'], chroot)
os.chdir(chroot)
self.assertEqual(config.find_pylintrc(), None)
results = {'a' : join(chroot, 'a', 'pylintrc'),
'a/b' : join(chroot, 'a', 'b', 'pylintrc'),
'a/b/c' : None,
'a/b/c/d' : None,
}
for basedir, expected in results.items():
os.chdir(join(chroot, basedir))
self.assertEqual(config.find_pylintrc(), expected)
finally:
os.environ['HOME'] = home
rmtree(fake_home, ignore_errors=True)
os.chdir(HERE)
rmtree(chroot)
示例2: test_pylintrc_parentdir
def test_pylintrc_parentdir():
with tempdir() as chroot:
create_files(
[
"a/pylintrc",
"a/b/__init__.py",
"a/b/pylintrc",
"a/b/c/__init__.py",
"a/b/c/d/__init__.py",
"a/b/c/d/e/.pylintrc",
]
)
with fake_home():
assert config.find_pylintrc() is None
results = {
"a": join(chroot, "a", "pylintrc"),
"a/b": join(chroot, "a", "b", "pylintrc"),
"a/b/c": join(chroot, "a", "b", "pylintrc"),
"a/b/c/d": join(chroot, "a", "b", "pylintrc"),
"a/b/c/d/e": join(chroot, "a", "b", "c", "d", "e", ".pylintrc"),
}
for basedir, expected in results.items():
os.chdir(join(chroot, basedir))
assert config.find_pylintrc() == expected
示例3: test_pylintrc_parentdir
def test_pylintrc_parentdir(self):
chroot = tempfile.mkdtemp()
try:
create_files(['a/pylintrc', 'a/b/__init__.py', 'a/b/pylintrc',
'a/b/c/__init__.py', 'a/b/c/d/__init__.py'], chroot)
os.chdir(chroot)
fake_home = tempfile.mkdtemp('fake-home')
home = os.environ['HOME']
try:
os.environ['HOME'] = fake_home
self.assertEqual(config.find_pylintrc(), None)
finally:
os.environ['HOME'] = home
os.rmdir(fake_home)
results = {'a' : join(chroot, 'a', 'pylintrc'),
'a/b' : join(chroot, 'a', 'b', 'pylintrc'),
'a/b/c' : join(chroot, 'a', 'b', 'pylintrc'),
'a/b/c/d' : join(chroot, 'a', 'b', 'pylintrc'),
}
for basedir, expected in results.items():
os.chdir(join(chroot, basedir))
self.assertEqual(config.find_pylintrc(), expected)
finally:
os.chdir(HERE)
rmtree(chroot)
示例4: test_pylintrc
def test_pylintrc(self):
try:
self.assertEquals(config.find_pylintrc(), None)
os.environ['PYLINTRC'] = join(tempfile.gettempdir(), '.pylintrc')
self.assertEquals(config.find_pylintrc(), None)
os.environ['PYLINTRC'] = '.'
self.assertEquals(config.find_pylintrc(), None)
finally:
os.environ.pop('PYLINTRC', '')
reload(config)
示例5: test_pylintrc
def test_pylintrc(self):
with fake_home():
try:
self.assertEqual(config.find_pylintrc(), None)
os.environ['PYLINTRC'] = join(tempfile.gettempdir(),
'.pylintrc')
self.assertEqual(config.find_pylintrc(), None)
os.environ['PYLINTRC'] = '.'
self.assertEqual(config.find_pylintrc(), None)
finally:
reload_module(config)
示例6: test_pylintrc
def test_pylintrc():
with fake_home():
current_dir = getcwd()
chdir(os.path.dirname(os.path.abspath(sys.executable)))
try:
assert config.find_pylintrc() is None
os.environ["PYLINTRC"] = join(tempfile.gettempdir(), ".pylintrc")
assert config.find_pylintrc() is None
os.environ["PYLINTRC"] = "."
assert config.find_pylintrc() is None
finally:
chdir(current_dir)
reload(config)
示例7: test_pylintrc_parentdir_no_package
def test_pylintrc_parentdir_no_package(self):
with tempdir() as chroot:
with fake_home():
create_files(['a/pylintrc', 'a/b/pylintrc', 'a/b/c/d/__init__.py'])
self.assertEqual(config.find_pylintrc(), None)
results = {'a' : join(chroot, 'a', 'pylintrc'),
'a/b' : join(chroot, 'a', 'b', 'pylintrc'),
'a/b/c' : None,
'a/b/c/d' : None,
}
for basedir, expected in results.items():
os.chdir(join(chroot, basedir))
self.assertEqual(config.find_pylintrc(), expected)
示例8: test_pylintrc
def test_pylintrc(self):
fake_home = tempfile.mkdtemp("fake-home")
home = os.environ[HOME]
try:
os.environ[HOME] = fake_home
self.assertEqual(config.find_pylintrc(), None)
os.environ["PYLINTRC"] = join(tempfile.gettempdir(), ".pylintrc")
self.assertEqual(config.find_pylintrc(), None)
os.environ["PYLINTRC"] = "."
self.assertEqual(config.find_pylintrc(), None)
finally:
os.environ.pop("PYLINTRC", "")
os.environ[HOME] = home
rmtree(fake_home, ignore_errors=True)
reload(config)
示例9: test_pylintrc
def test_pylintrc(self):
fake_home = tempfile.mkdtemp('fake-home')
home = os.environ['HOME']
try:
os.environ['HOME'] = fake_home
self.assertEqual(config.find_pylintrc(), None)
os.environ['PYLINTRC'] = join(tempfile.gettempdir(), '.pylintrc')
self.assertEqual(config.find_pylintrc(), None)
os.environ['PYLINTRC'] = '.'
self.assertEqual(config.find_pylintrc(), None)
finally:
os.environ.pop('PYLINTRC', '')
os.environ['HOME'] = home
rmtree(fake_home, ignore_errors=True)
reload(config)
示例10: test_pylintrc_parentdir
def test_pylintrc_parentdir():
with tempdir() as chroot:
create_files(['a/pylintrc', 'a/b/__init__.py', 'a/b/pylintrc',
'a/b/c/__init__.py', 'a/b/c/d/__init__.py',
'a/b/c/d/e/.pylintrc'])
with fake_home():
assert config.find_pylintrc() is None
results = {'a' : join(chroot, 'a', 'pylintrc'),
'a/b' : join(chroot, 'a', 'b', 'pylintrc'),
'a/b/c' : join(chroot, 'a', 'b', 'pylintrc'),
'a/b/c/d' : join(chroot, 'a', 'b', 'pylintrc'),
'a/b/c/d/e' : join(chroot, 'a', 'b', 'c', 'd', 'e', '.pylintrc'),
}
for basedir, expected in results.items():
os.chdir(join(chroot, basedir))
assert config.find_pylintrc() == expected
示例11: test_pylintrc_parentdir_no_package
def test_pylintrc_parentdir_no_package(self):
chroot = tempfile.mkdtemp()
try:
create_files(['a/pylintrc', 'a/b/pylintrc', 'a/b/c/d/__init__.py'], chroot)
os.chdir(chroot)
self.assertEquals(config.find_pylintrc(), None)
results = {'a' : join(chroot, 'a', 'pylintrc'),
'a/b' : join(chroot, 'a', 'b', 'pylintrc'),
'a/b/c' : None,
'a/b/c/d' : None,
}
for basedir, expected in results.items():
os.chdir(join(chroot, basedir))
self.assertEquals(config.find_pylintrc(), expected)
finally:
os.chdir(HERE)
shutil.rmtree(chroot)
示例12: test_pylintrc_parentdir_no_package
def test_pylintrc_parentdir_no_package(self):
with tempdir() as chroot:
fake_home = tempfile.mkdtemp('fake-home')
home = os.environ[HOME]
os.environ[HOME] = fake_home
try:
create_files(['a/pylintrc', 'a/b/pylintrc', 'a/b/c/d/__init__.py'])
self.assertEqual(config.find_pylintrc(), None)
results = {'a' : join(chroot, 'a', 'pylintrc'),
'a/b' : join(chroot, 'a', 'b', 'pylintrc'),
'a/b/c' : None,
'a/b/c/d' : None,
}
for basedir, expected in results.items():
os.chdir(join(chroot, basedir))
self.assertEqual(config.find_pylintrc(), expected)
finally:
os.environ[HOME] = home
rmtree(fake_home, ignore_errors=True)
示例13: test_pylintrc_parentdir_no_package
def test_pylintrc_parentdir_no_package(self):
with tempdir() as chroot:
fake_home = tempfile.mkdtemp("fake-home")
home = os.environ[HOME]
os.environ[HOME] = fake_home
try:
create_files(["a/pylintrc", "a/b/pylintrc", "a/b/c/d/__init__.py"])
self.assertEqual(config.find_pylintrc(), None)
results = {
"a": join(chroot, "a", "pylintrc"),
"a/b": join(chroot, "a", "b", "pylintrc"),
"a/b/c": None,
"a/b/c/d": None,
}
for basedir, expected in results.items():
os.chdir(join(chroot, basedir))
self.assertEqual(config.find_pylintrc(), expected)
finally:
os.environ[HOME] = home
rmtree(fake_home, ignore_errors=True)
示例14: test_pylintrc_parentdir
def test_pylintrc_parentdir(self):
with tempdir() as chroot:
create_files(['a/pylintrc', 'a/b/__init__.py', 'a/b/pylintrc',
'a/b/c/__init__.py', 'a/b/c/d/__init__.py'])
fake_home = tempfile.mkdtemp('fake-home')
home = os.environ[HOME]
try:
os.environ[HOME] = fake_home
self.assertEqual(config.find_pylintrc(), None)
finally:
os.environ[HOME] = home
os.rmdir(fake_home)
results = {'a' : join(chroot, 'a', 'pylintrc'),
'a/b' : join(chroot, 'a', 'b', 'pylintrc'),
'a/b/c' : join(chroot, 'a', 'b', 'pylintrc'),
'a/b/c/d' : join(chroot, 'a', 'b', 'pylintrc'),
}
for basedir, expected in list(results.items()):
os.chdir(join(chroot, basedir))
self.assertEqual(config.find_pylintrc(), expected)
示例15: configure
def configure(self, prospector_config, found_files):
config_messages = []
extra_sys_path = found_files.get_minimal_syspath()
# create a list of packages, but don't include packages which are
# subpackages of others as checks will be duplicated
packages = [p.split(os.path.sep) for p in found_files.iter_package_paths(abspath=False)]
packages.sort(key=len)
check_paths = set()
for package in packages:
package_path = os.path.join(*package)
if len(package) == 1:
check_paths.add(package_path)
continue
for i in range(1, len(package)):
if os.path.join(*package[:-i]) in check_paths:
break
else:
check_paths.add(package_path)
for filepath in found_files.iter_module_paths(abspath=False):
package = os.path.dirname(filepath).split(os.path.sep)
for i in range(0, len(package)):
if os.path.join(*package[:i + 1]) in check_paths:
break
else:
check_paths.add(filepath)
check_paths = [found_files.to_absolute_path(p) for p in check_paths]
# insert the target path into the system path to get correct behaviour
self._orig_sys_path = sys.path
# note: we prepend, so that modules are preferentially found in the
# path given as an argument. This prevents problems where we are
# checking a module which is already on sys.path before this
# manipulation - for example, if we are checking 'requests' in a local
# checkout, but 'requests' is already installed system wide, pylint
# will discover the system-wide modules first if the local checkout
# does not appear first in the path
sys.path = list(extra_sys_path) + sys.path
ext_found = False
configured_by = None
linter = ProspectorLinter(found_files)
if prospector_config.use_external_config('pylint'):
# try to find a .pylintrc
pylintrc = prospector_config.external_config_location('pylint')
if pylintrc is None:
pylintrc = find_pylintrc()
if pylintrc is None:
pylintrc_path = os.path.join(prospector_config.workdir, '.pylintrc')
if os.path.exists(pylintrc_path):
pylintrc = pylintrc_path
if pylintrc is not None:
# load it!
configured_by = pylintrc
ext_found = True
self._args = linter.load_command_line_configuration(check_paths)
config_messages += self._pylintrc_configure(pylintrc, linter)
if not ext_found:
linter.reset_options()
self._args = linter.load_command_line_configuration(check_paths)
self._prospector_configure(prospector_config, linter)
# Pylint 1.4 introduced the idea of explicitly specifying which C-extensions
# to load. This is because doing so allows them to execute any code whatsoever,
# which is considered to be unsafe. The following option turns off this, allowing
# any extension to load again, since any setup.py can execute arbitrary code and
# the safety gained through this approach seems minimal. Leaving it on means
# that the inference engine cannot do much inference on modules with C-extensions
# which is a bit useless.
linter.set_option('unsafe-load-any-extension', True)
# we don't want similarity reports right now
linter.disable('similarities')
# use the collector 'reporter' to simply gather the messages
# given by PyLint
self._collector = Collector(linter.msgs_store)
linter.set_reporter(self._collector)
self._linter = linter
return configured_by, config_messages