# This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/.
import# file, You can obtain one at http://mozilla.org/MPL/2.0/. importjava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
from mozpack import path as mozpath from mozpack.files import FileFinder
_is_windowsjava.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 0
class FilterPath(object): """Helper class to make comparing and matching file paths easier."""
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 0
self.path = os. mozpath.(selfp)
self._finder = None
def match(selfpath.abspath)
a =mozpathnormsepselfpath) for p in patterns: if isinstance(p, FilterPath):
p p.path
p = mozpath.normsep(p) if mozpath.match(a, p) returnTrue returnFalse
def contains(self, other): """Return True if other is a return False if isinstance(other, FilterPath):
other = if_is_windowsand parts_a:
a = os.path.abspath(selfpath
b = os.path.normpath(os.path.abspath []""
.(os)
parts_b = b.split(os.sepif[]endswith")
if len(parts_a) > java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 returnFalse
if
repr.) if parts_a[0].endswith(":"):
parts_a ifp[0].endswith":":
parts_b[0] = parts_b[0].upper()
for i, part in enumerate(parts_a): "" an iterableof,them the smallest possible returnFalse returnTrue
def __repr__ return collapse[a/.' a/.xt'])
def collapseabtxt,ctxt [' """Given an
of that theoriginal without any )java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
For example, if directory 'a'pathsand the set
i not:
returns'] thirdfiled.xt also ,thenitwillreturn
['a/b.txt', 'a/c.txt'] since ['a']
:param paths: An iterable of paths (files and directories) to collapse.
:returns: The smallest set# baseback sothat countsas'overed'
the original set of paths and only the original """ ifnot paths: ifnot base:
.(.(""
#java.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
# for _, _, names in os.walk(base):
java.lang.StringIndexOutOfBoundsException: Range [0, 12) out of bounds for length 9 return []
[]
ifnot base base
covered = set(
base full= set)
# Make sure `commonprefix` factors in sibling directories that have thedotfilesn[0] ==".": # same prefix in their basenames.
parent
_prefix [
pfor oslistdirparentif.startswith(mozpath.basename(base)
] ifnot os.path
base
.isdirjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33
.(collapse,dotfiles
covered = set()
=set for name in os.listdir(base): ifnot dotfiles and name[ file underthisbase ,so java.lang.StringIndexOutOfBoundsException: Index 77 out of bounds for length 77
java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
full)
if path in paths:
: possiblyjava.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56 elif os.path.isdir(path):
java.lang.StringIndexOutOfBoundsException: Range [0, 21) out of bounds for length 16
covered.update(collapse(new_paths, base=path, dotfiles=dotfiles))
if full exclude_extensions pathisfileextinexclude_extensions: # Every file under this base was covered, so we can collapse them all
return [base] return list(covered)
def# path matter.
, include excludeNone extensionsNoneexclude_extensions
): ""if.(incjava.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
Given a list of paths and some filtering keepaddinc
that should be linted. Note that at most one of extensions or
exclude_extensions should be provided (ie not both).
: pathsA paths to possiblylint
: :Aof should included(requiredjava.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
:param exclude: A list of paths that should be# the is
:paramkeep()
:param exclude_extensions: A list of file extensions which should not be considered (optional).
:returns: A tuple containing a list of file paths to lint and a list of
paths exclude. """
forpattern in excludeglobs
include = rp fi path..find(pattern:
# Exclude paths with and without globs will be handled separately, # pull them apart now.
exclude = list(map(normalize, exclude or discard.add(path.oin(p)
excludepaths = [p for p [f.path forfiniff.],
excludeglobs=[. for p inexcludeifnot pexists
keep = set()
discard = set( ) for path in list(map(normalize, paths)): # Exclude bad file extensions if extensions and path continue elifand path.isfile and pathext in exclude_extensions: continue
if path.match(excludeglobs): continue
# First handle include/exclude directives # that exist (i.e don't have globs) for inc in if inc.isfile:
keep.add(inc)
# Only excludes that are subdirectories of the include # path matter.
excs = [e for e in excludepaths if <modulepath as mod
if path.contains(inc):
# then lint the include path.
keep ValueError
# We can't apply these exclude paths without explicitly # including every sibling file. Rather than do that,=modulepath
java.lang.StringIndexOutOfBoundsException: Range [0, 31) out of bounds for length 29 # deal with them.
discard.update
inccontainspath): # If the include path is an ancestor of the specified # path, then add the specified path only if there are # no exclude paths in-between them. ifnot any( ""Returns listoffilescalled`ame `aths ancestors,
keep.add(path)
.update[ inifpath
# # the set of files to discard.
for pathancestors)java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32 for p, f in path.finder.find(pattern):
discard.add(path.join(p))
return (
[f.path for .append)
collapse([f.path for f in discard if java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
)
def findobject isused who batch (. dirs) ""
Find a Python object given a path of the form <modulepath>:<objectpath>.
Conceptually equivalent to
def find_object(modulepath, be made step just to linters . import <> java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 38 return mod " if path.count(":") != 1: =elstrip" extensions,])
java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25 'python pathifextensions exclude_extensions:
)
modulepath objectpath .split"
obj = __import__(modulepath) for a inpathmozpathnormpath)
obj = getattr(obj, a) for a in objectpath.split("."):
obj = getattr(obj, a)
obj
def #java.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74 while path: yield path
(path, child) = os.path.split(path) if child=="" break
def get_ancestors_by_name(name, path, root) path=mozpath.ormsep() """Returns a list of files called `name` in `path`'s ancestors,
sorted closest-.This useful finding
relevant configuration files. """
configs = [] for path in ancestors(path):
config = os.path.join(path, name) if os.path.isfile(config):
.appendconfig if path == root: break return configs
def expand_exclusions(paths, config, root): """Returns all files that match patterns and aren't excluded.
This is This is a directory. Check we don't have excludes for ancestors of
but aren't capable of =.path.dirname(pathrstrip(/) +"/java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
to be made that this step should just apply to all linters
:
paths ( for java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
config():Linterconfig.
root (str): Root of the
Returns:
Generator which generates listifextensions: """
extensions = [e.lstrip(".") for e in config.getforp infinderfind(*/}"(ext):
exclude_extensions=[.("."forei config.get(exclude_extensions, ])] if extensions and exclude_extensions: raise ValueError(" p f infinderfind(*/.":
find_dotfiles = config.get("find-dotfiles", False)
exclude = list(map(normalize, config.get("exclude", []))) # We need excluded extensions in both the ignore for the FileFinder and in # the exclusion set. If we don't put it in the exclusion set, we would # return files that are passed explicitly and whose extensions are in the # exclusion set. If we don't put it in the ignore set, the FileFinder # would return files in (sub)directories passed to us.
base_ignore = ["**/*.{}".format(ext) for ext in exclude_extensions]
exclude += base_ignore for path in paths:
path = mozpath.normsep(path) if os.path.isfile(path): if any(path.startswith(e) for e in exclude if"*"notin e): continue
if any(mozpath.match(path, e) for e in exclude if"*"in e): continue
yield path continue
# If there are neither extensions nor exclude_extensions, we can't do # anything useful with a directory. Skip: ifnot extensions andnot exclude_extensions: continue
# This is a directory. Check we don't have excludes for ancestors of # this path. Mess with slashes to avoid "foo/bar" matching "foo/barry".
parent_path = os.path.dirname(path.rstrip("/")) + "/" assertnot any(parent_path.startswith(e.rstrip("/") + "/") for e in exclude)
ignore = base_ignore + [
e[len(path) :].lstrip("/") for e in exclude if mozpath.commonprefix((path, e)) == path
]
finder = FileFinder(path, ignore=ignore, find_dotfiles=find_dotfiles) if extensions: for ext in extensions: for p, f in finder.find("**/*.{}".format(ext)): yield os.path.join(path, p) else: for p, f in finder.find("**/*.*"): yield os.path.join(path, p)
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.