-
-
Notifications
You must be signed in to change notification settings - Fork 643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Go source excludes; Cleanup old filespec matching #4350
Changes from 19 commits
430c5a1
405e119
055dbfc
227aa8c
f5a661f
40d37b5
62700f1
9664a29
a358cd6
495623e
f0f3513
25dfc5d
6b6cc3e
16a576a
9e83138
3213d70
0dc9db8
18c91d4
a501d6a
8a231a6
6e8e7dc
a8eb245
1ad6a97
39cba5a
db98f0b
25385a4
867057a
66ecd63
8435198
5df0d63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ def glob_to_regex(pattern): | |
:returns: A regex string that matches same paths as the input glob does. | ||
""" | ||
out = ['^'] | ||
components = pattern.strip('/').replace('.', '[.]').split('/') | ||
components = pattern.strip('/').replace('.', '[.]').replace('$', '[$]').split('/') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might make sense to consider a more general escape mechanism. This covers Initially I was thinking we could just drop Maybe on line: 37 https://github.com/pantsbuild/pants/pull/4350/files#diff-2d528bdfb8ee22a56a1b0660753b7a3cR37 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been operating under the assumption that this code doesn't need to live very long with the v2 engine on the way. But if it does, this should probably switch to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the time when this logic was introduced, pathspec was still using gitignore syntax which is different from glob matching syntax. I am not sure whether pathspec has evolved to support glob matching syntax since. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. Tried |
||
doublestar = False | ||
for component in components: | ||
if len(out) == 1: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,14 @@ | |
unicode_literals, with_statement) | ||
|
||
import os | ||
from abc import abstractproperty | ||
from abc import abstractmethod, abstractproperty | ||
from hashlib import sha1 | ||
|
||
from six import string_types | ||
from twitter.common.dirutil.fileset import Fileset | ||
|
||
from pants.base.build_environment import get_buildroot | ||
from pants.source.filespec import matches_filespec | ||
from pants.util.dirutil import fast_relpath | ||
from pants.util.memo import memoized_property | ||
from pants.util.meta import AbstractClass | ||
|
@@ -64,18 +65,17 @@ def __iter__(self): | |
def __getitem__(self, index): | ||
return self.files[index] | ||
|
||
@abstractmethod | ||
def iter_relative_paths(self): | ||
"""An alternative `__iter__` that joins files with the relative root.""" | ||
for f in self: | ||
yield os.path.join(self.rel_root, f) | ||
|
||
|
||
class EagerFilesetWithSpec(FilesetWithSpec): | ||
def __init__(self, rel_root, filespec, files, files_hash): | ||
""" | ||
:param rel_root: The root for the given filespec, relative to the buildroot. | ||
:param filespec: A filespec as generated by `FilesetRelPathWrapper`, which represents | ||
what globs or file list it came from. | ||
what globs or file list it came from. Must be relative to buildroot. | ||
:param files: A list of matched files, with declared order and duplicates preserved. | ||
:param files_hash: A string fingerprint for all files in the fileset. | ||
""" | ||
|
@@ -91,6 +91,11 @@ def files(self): | |
def files_hash(self): | ||
return self._files_hash | ||
|
||
def iter_relative_paths(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better to call this
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed. |
||
"""An alternative `__iter__` that joins files with the relative root.""" | ||
for f in self: | ||
yield os.path.join(self.rel_root, f) | ||
|
||
def __repr__(self): | ||
return 'EagerFilesetWithSpec(rel_root={!r}, files={!r})'.format(self.rel_root, self.files) | ||
|
||
|
@@ -120,6 +125,13 @@ def files_hash(self): | |
h.update(f.read()) | ||
return h.digest() | ||
|
||
def iter_relative_paths(self): | ||
"""An alternative `__iter__` that joins files with the relative root.""" | ||
for f in self: | ||
path_from_buildroot = os.path.join(self.rel_root, f) | ||
if matches_filespec(path_from_buildroot, self.filespec): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is redundant. The files in the collection are already guaranteed to match the filespec: the filespec is just metadata about how the fileset was constructed. The point of the What I was suggesting was an abstract method on
...and the implementation for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Corrected. Pushed |
||
yield path_from_buildroot | ||
|
||
|
||
class FilesetRelPathWrapper(AbstractClass): | ||
KNOWN_PARAMETERS = frozenset(['exclude', 'follow_links']) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this is a legal glob... should it be
*/**/*
? Should check that it still compiles in latest master now that v2 is enabled.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test case added to prove the case.