Skip to content
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

Merged
merged 4 commits into from Aug 13, 2020

Conversation

jameinel
Copy link
Member

This adds the ability for JujuIgnore to pull in the default ignores and extend them with .jujuignore contents.

I don't have tests around the walk functionality, but I figured I would leave it in there to show you how I was thinking it would look.

Copy link
Contributor

@facundobatista facundobatista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Some small easy changes, thanks!

ignore.extend_patterns(ignores)
return ignore

def _walk_unignored(self, topdir):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.

Anyway, I need to implement the "walk" outside, as it will be ignoring different stuff (a part of which is jujuignored).

So I think this shouldn't be included in this layer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reduce this to only one blank line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

def _compile_from(self, patterns):
def extend_patterns(self, patterns: typing.Iterable[str]) -> None:
"""Add more patterns to the ignore list.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please close the docstring in the same line above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -26,6 +26,7 @@

from charmcraft.cmdbase import BaseCommand, CommandError
from .utils import make_executable
from .jujuignore import JujuIgnore, default_juju_ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect flake8 will fail on these...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it was supposed to be "..jujuignore" since it is in the parent directory, but flake8 doesn't complain at that point.

ignore = JujuIgnore(default_juju_ignore)
path = self.charmdir / '.jujuignore'
if path.exists():
with path.open() as ignores:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we specify the encoding here? Which is the expected encoding for the .jujuignore file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.gitignore is officially UTF-8, I don't know that Juju specifically declares an encoding, but there isn't any reason to believe it anything but UTF-8.

@@ -109,11 +111,20 @@ def _link_to_buildpath(self, srcpath):
destpath.symlink_to(srcpath)
return destpath

def _load_juju_ignore(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function needs tests.

@@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'll use this also from tests!

Copy link
Contributor

@facundobatista facundobatista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks!!

@@ -26,6 +26,7 @@

from charmcraft.cmdbase import BaseCommand, CommandError
from .utils import make_executable
from ..jujuignore import JujuIgnore, default_juju_ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not from charmcraft.jujuignore as we do for the rest?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird. I like from . import foo and from .foo import bar and even from .. import foo, but not from ..foo import bar.

@jameinel
Copy link
Member Author

jameinel commented Aug 12, 2020 via email

Copy link
Contributor

@chipaca chipaca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve.

@@ -26,6 +26,7 @@

from charmcraft.cmdbase import BaseCommand, CommandError
from .utils import make_executable
from ..jujuignore import JujuIgnore, default_juju_ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's weird. I like from . import foo and from .foo import bar and even from .. import foo, but not from ..foo import bar.

Cleanup a bunch of small issues found in review. (whitespace, bad
imports, etc.)
Add tests for _load_jujuignore and its behavior around default ignores
and extending those ignores with the content of .jujuignore, as well as
clarify the encoding of the file.
@jameinel jameinel merged commit b9c265a into canonical:master Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants