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

Improve .couchappignore #204

Open
Tracked by #226
BigBlueHat opened this issue Nov 21, 2015 · 11 comments
Open
Tracked by #226

Improve .couchappignore #204

BigBlueHat opened this issue Nov 21, 2015 · 11 comments

Comments

@BigBlueHat
Copy link
Member

People still get confused...
http://stackoverflow.com/questions/11334089/ignore-folders-in-couchappignore

@awgrover
Copy link

awgrover commented Apr 4, 2016

It appears that in .couchappignore, the regex is matching from the head of the filename. A "^" is redundant (but implied). And, of course it's each element of the filename, e.g. "views/bob.txt" and "bob.txt" will both be matched by ".*\.txt". "\.txt" will not match either.

@iblislin
Copy link
Collaborator

iblislin commented Apr 5, 2016

@awgrover
How about this patch?
This will remove the implied "^".

diff --git a/couchapp/localdoc.py b/couchapp/localdoc.py
index e095bf5..61a7d92 100644
--- a/couchapp/localdoc.py
+++ b/couchapp/localdoc.py
@@ -281,7 +281,7 @@ class LocalDoc(object):

     def check_ignore(self, item):
         for i in self.ignores:
-            match = re.match(i, item)
+            match = re.search(i, item)
             if match:
                 logger.debug("ignoring %s" % item)
                 return True

iblislin added a commit that referenced this issue Jan 31, 2017
New helper funcs with doc testing included:
- LocalDoc._combine_path
- LocalDoc._combine_dir

Ref: #204
iblislin added a commit that referenced this issue Jan 31, 2017
@iblislin
Copy link
Collaborator

iblislin commented Feb 1, 2017

@BigBlueHat please checkout PR #243 ... and there are tons of test cases.

@natevw
Copy link

natevw commented Oct 13, 2017

Any plans for this? I'm hoping to add .couchappignore support to a simple little node.js helper and realizing the current format is pretty limited. What I might do with my app is simply match against the full (well, relative to the ddoc root) path.

This would allow the user pretty much full control (e.g. choose whether to ^ anchor, patterns for subfolder combinations, etc.) and also without having to generate tons of combinatoric path parts like PR #243 does.

Obviously not 100% compatible with the original (current) behavior here but I don't foresee much trouble with it in practice. I reviewed a few couchappignore files through github search and most were fairly simple.

@iblislin
Copy link
Collaborator

@natevw I can merge #243 into master branch, and let you start to work on your proposal.
(although, I still have no idea about the node.js helper is)

@iblislin iblislin reopened this Oct 15, 2017
@iblislin
Copy link
Collaborator

The changes in #243 got merged

@natevw
Copy link

natevw commented Oct 16, 2017

@iblis17 Thanks. What do you think of simplifying that to just pass the relative path?

I did this in my putdoc helper which I mentioned above. It does just the push part for some simple couchapps. I think it is the most flexible.

By passing the relative path to the regex (and using re.search instead of re.match in Python), the benefits are:

  • very simple to implement, don't need to test each individual path component combination
  • still behaves the same with simple strings like "node_modules" or "\\.*.exe"
  • allows the author to control whether it anchors ^ or not
  • also gives more control over subdirectories and stuff

So I hope the real couchapp tool might consider doing the same, e.g. just testing the whole relative path like "node_modules/.bin/some_install" once against a regex to exclude node_modules/\\.bin.

@iblislin
Copy link
Collaborator

@natevw well, I think I already implemented some in #243, like relative path matching. But it's quite long time ago, and I cannot recall what already support in master :p.

@natevw
Copy link

natevw commented Oct 19, 2017

It looks like in #243 you now check against a lot of combinations instead of changing the anchoring behavior.

I might be reading the code wrong but AFAICT, by the time it gets to "foo/bar/baz.json" it uses (anchored) re.match against a whole bunch of things.

When entering foo:

  • foo
  • /foo

When entering bar:

  • foo
  • foo/bar
  • /foo
  • /foo/bar

When reaching baz.json:

  • foo
  • foo/bar
  • foo/bar/baz.json
  • bar
  • bar/baz.json
  • baz.json
  • /foo
  • /foo/bar
  • /foo/bar/baz.json
  • /bar
  • /bar/baz.json
  • /baz.json

I'd recommend switching to re.search (which is anchored only if RegEx wants it) as you proposed earlier, and then only test one string (the full relative path) at each level:

Enter foo:

  • foo

Enter bar:

  • foo/bar

Reach baz.json:

  • foo/bar/baz.json

Maybe we should pass directories as foo/ and foo/bar/ when entering them?

@iblislin
Copy link
Collaborator

I'd recommend switching to re.search (which is anchored only if RegEx wants it) as you proposed earlier, and then only test one string (the full relative path) at each level:

I don't get "only test one string at each level". Just want to get rid of input like "/..." only?

Would you send a PR to clearify it, and at the sometime, do not need to change test cases, then we can check which test cases in master failed/might change.

natevw added a commit to natevw/couchapp that referenced this issue Oct 21, 2017
…path (instead of re.match and filename). related to couchapp#204
@natevw
Copy link

natevw commented Oct 21, 2017

@iblis17 I submitted #246 to show what I'm talking about. I wasn't able to run tests locally, but hopefully you can take a look?

This is similar to your original suggestion at #204 (comment) and I think it's going to work much better now that check_ignores is getting passed the rel_path instead of filename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants