Skip to content

Can't use exclusion glob patterns in slimPatterns #372

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

Open
mjpieters opened this issue Jun 17, 2019 · 6 comments
Open

Can't use exclusion glob patterns in slimPatterns #372

mjpieters opened this issue Jun 17, 2019 · 6 comments

Comments

@mjpieters
Copy link

Currently the strip option runs each pattern through glob-all.glob.sync() separately:

https://github.com/UnitedIncome/serverless-python-requirements/blob/f39e166e8221171ec040ca37fe0f98b6ed89ad75/lib/slim.js#L48-L52

This means we can't make use of the glob-all feature giving you exclude patterns.

Can this be updated to map all patterns to their ${folderPath}/${pattern} form and then pass the whole list as one to glob-all.glob.sync()?

I realise that this requires hoisting up the ! at the start of negation patterns pattern, e.g.

slimPatterns:
- "**/*.dist-info*"
- "!**/specific_package.dist-info*"

needs to be translated (given folderPath = "/foo/bar/") to

patterns = [
    "/foo/bar/**/*.dist-info*",
    "!/foo/bar/**/specific_package.dist-info*"
]
@ptrhck
Copy link

ptrhck commented Jul 15, 2019

As far as I understand, I cannot use "!**/specific_package.dist-info*" to exclude that folder right? Is there a workaround currently?

@Adizx12
Copy link

Adizx12 commented Jul 25, 2019

@ptrhck
I have found a workaround, sadly it's a bit inconvenient to use 😞 At least it works 👍

    slim: true
    slimPatternsAppendDefaults: false # we need to overwrite default dist-info
    slimPatterns:
      # "normal" exclusions:
      - '**/tests/*'
      # default dist-info with !(lib_name*) - matches only if name is not present:
      - "**/!(lib_name*)*.dist-info/*"
      # the rest of defaults:
      - '**/*.py[c|o]'
      - '**/__pycache__*'

@ptrhck
Copy link

ptrhck commented Jul 25, 2019

If I do "**/!(numpy*)*.dist-info/*", all .dist-info files will be removed except for the numpy package?

@Adizx12
Copy link

Adizx12 commented Jul 25, 2019

Yes, everything in this list will be excluded (ie. matches will be deleted) , So it works like that:

  1. **/ - Match any directory
  2. ! (numpy*) - don't match anything beginning with numpy (for numpy will ignore it here, otherwise goes on)
  3. *.dist-info... - Match anything having dist-info (numpy was thrown out previously)

Theoretically you could chain more !(...) to exclude more names, though haven't tested it.

@ptrhck
Copy link

ptrhck commented Dec 2, 2020

Yes, everything in this list will be excluded (ie. matches will be deleted) , So it works like that:

  1. **/ - Match any directory
  2. ! (numpy*) - don't match anything beginning with numpy (for numpy will ignore it here, otherwise goes on)
  3. *.dist-info... - Match anything having dist-info (numpy was thrown out previously)

Theoretically you could chain more !(...) to exclude more names, though haven't tested it.

How can you chain to exclude more names? **/!(lib_name1*)!(lib_name1*)*.dist-info/* does not work.

@rishi-dhar
Copy link

Yes, everything in this list will be excluded (ie. matches will be deleted) , So it works like that:

  1. **/ - Match any directory
  2. ! (numpy*) - don't match anything beginning with numpy (for numpy will ignore it here, otherwise goes on)
  3. *.dist-info... - Match anything having dist-info (numpy was thrown out previously)

Theoretically you could chain more !(...) to exclude more names, though haven't tested it.

How can you chain to exclude more names? **/!(lib_name1*)!(lib_name1*)*.dist-info/* does not work.

If you are still wondering you can do this
**/!(lib_name1*|lib_name2*|lib_name3*)*.dist-info/*

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

No branches or pull requests

4 participants