-
Notifications
You must be signed in to change notification settings - Fork 67
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
charmcraft/jujuignore.py: Allow extending the list of patterns. #99
Changes from all commits
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import yaml | ||
|
||
from charmcraft.cmdbase import BaseCommand, CommandError | ||
from charmcraft.jujuignore import JujuIgnore, default_juju_ignore | ||
from .utils import make_executable | ||
|
||
logger = logging.getLogger(__name__) | ||
|
@@ -87,6 +88,7 @@ def __init__(self, args): | |
self.requirement_paths = args['requirement'] | ||
|
||
self.buildpath = self.charmdir / BUILD_DIRNAME | ||
self.ignore_rules = self._load_juju_ignore() | ||
|
||
def run(self): | ||
"""Main building process.""" | ||
|
@@ -110,11 +112,20 @@ def _link_to_buildpath(self, srcpath): | |
destpath.symlink_to(srcpath) | ||
return destpath | ||
|
||
def _load_juju_ignore(self): | ||
ignore = JujuIgnore(default_juju_ignore) | ||
path = self.charmdir / '.jujuignore' | ||
if path.exists(): | ||
with path.open('r', encoding='utf-8') as ignores: | ||
ignore.extend_patterns(ignores) | ||
return ignore | ||
|
||
def handle_code(self): | ||
"""Handle basic files and the charm source code.""" | ||
# basic files | ||
logger.debug("Linking in basic files and charm code") | ||
self._link_to_buildpath(self.charmdir / CHARM_METADATA) | ||
|
||
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. Please reduce this to only one blank line. 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. 👍 |
||
for fn in CHARM_OPTIONAL: | ||
path = self.charmdir / fn | ||
if path.exists(): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,7 +151,11 @@ def __init__(self, patterns: typing.Iterable[str]): | |
self._matchers = [] | ||
self._compile_from(patterns) | ||
|
||
def _compile_from(self, patterns): | ||
def extend_patterns(self, patterns: typing.Iterable[str]) -> None: | ||
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. Thanks! I'll use this also from tests! |
||
"""Add more patterns to the ignore list.""" | ||
self._compile_from(patterns) | ||
|
||
def _compile_from(self, patterns: typing.Iterable[str]): | ||
for line_num, rule in enumerate(patterns, 1): | ||
orig_rule = rule | ||
rule = rule.lstrip().rstrip('\r\n') | ||
|
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.
This function needs tests.