serverless-python-requirements icon indicating copy to clipboard operation
serverless-python-requirements copied to clipboard

Can't use exclusion glob patterns in slimPatterns

Open mjpieters opened this issue 6 years ago • 6 comments

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*"
]

mjpieters avatar Jun 17 '19 17:06 mjpieters

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

ptrhck avatar Jul 15 '19 15:07 ptrhck

@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__*'

Adizx12 avatar Jul 25 '19 08:07 Adizx12

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

ptrhck avatar Jul 25 '19 09:07 ptrhck

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.

Adizx12 avatar Jul 25 '19 15:07 Adizx12

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.

ptrhck avatar Dec 02 '20 20:12 ptrhck

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/*

rishi-dhar avatar Sep 10 '21 16:09 rishi-dhar