Skip to content

clean up slim code using glob-all to make it more cross platform #227

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

Merged
merged 9 commits into from
Aug 28, 2018

Conversation

dschep
Copy link
Contributor

@dschep dschep commented Aug 9, 2018

Could you try this out @sweepy84? Install this branch with:

npm i UnitedIncome/serverless-python-requirements#pureish-js-slim

closes #212

@dschep dschep changed the title clean up slim code using glob-all to make it more cross platform. closes #212 clean up slim code using glob-all to make it more cross platform Aug 9, 2018
@sweepy84
Copy link

hi @dschep - unfortunately getting an error now.

With:

slim:true
dockerizePip: true

It fails with error:

find: missing argument to `-exec'

With just:
slim:true

It runs without an error, partially works because the zip is considerably smaller, but still does not remove "test" folders and files. Even with regex pattern matching like a described in #212.

@dschep
Copy link
Contributor Author

dschep commented Aug 10, 2018

Thanks! Hmm. I'll have to look into the find issue when using dockerizePip. The correct syntax to delete the tset folder is now **/*test (note the **). But I could change this to have the plugin always prepend that.

@dschep
Copy link
Contributor Author

dschep commented Aug 10, 2018

Hmm. Looked a bit more.. I have no clue why you're getting that find exec error. The tests all pass in circle, and I'd expect this one would fail the way you described: https://github.com/UnitedIncome/serverless-python-requirements/blob/3e0980605be8f0e72bc49792907868ed7f7ef410/test.bats#L111-L122

@dee-me-tree-or-love
Copy link
Contributor

Wow, that's a really nice cleanup, thanks, it's cool to see and learn from refactoring
👍

lib/slim.js Outdated
let stripCmd = [];
const getStripCommand = (options, folderPath) =>
process.platform !== 'win32' || isWsl || options.dockerizePip
? ` && find ${folderPath} -name "*.so" -exec strip {} \\;`
Copy link
Contributor

Choose a reason for hiding this comment

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

I have noticed that again changing
` && find ${folderPath} -name "*.so" -exec strip {} \\; ` to
either ` && find ${folderPath} -name "*.so" -exec strip {} \;`
or ` && find ${folderPath} -name "*.so" -exec strip {} ;`
makes it run as expected on Win10.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. pushing a commit with out the \\ to see how it fares in circle. It might have to be a platform dependent thing. I'd assume WSL should be treated like a *nix tho because it's running in as *nix shell.

Copy link
Contributor

Choose a reason for hiding this comment

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

@dschep
Indeed, I was rather surprised too..
If it fails, could be interesting to also replace ; operator with +.

I did not have a good reason to use a semicolon, but it seems that + should also work and it does not generally need an escape: as mentioned here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good suggestion! Works great since strip supports getting multiple arguments.

lib/slim.js Outdated
stripCmd = stripCmd.concat(customPatterns);
const deleteFiles = (options, folderPath) => {
let patterns = [
'**/*.so',
Copy link
Contributor

Choose a reason for hiding this comment

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

Also deleteing the .so files might not necessarily be safe as these are extension modules.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

DoH! Good catch. I didn't mean to delete those. that's what strip is for!

@dschep
Copy link
Contributor Author

dschep commented Aug 23, 2018

I think it should work now. Could you please test @sweepy84 and @dee-me-tree-or-love? Thanks!

lib/slim.js Outdated
let stripCmd = [];
const getStripCommand = (options, folderPath) =>
process.platform !== 'win32' || isWsl || options.dockerizePip
? ` && find ${folderPath} -name "*.so" -exec strip {} +`
Copy link
Contributor

Choose a reason for hiding this comment

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

This again did not work on Win10 when I tried 😅

Serverless: Docker Image: lambci/lambda:build-python3.6
Error --------------------------------------------------
...
find: ‘strip’: No such file or directory

But now having changed it back to a semicolon with a different escape seems to work and supposedly should also be fine for *nix platforms... Could you try ` && find ${folderPath} -name "*.so" -exec strip {} ';' ` (yes, single quotes :D)
Sorry for making it so absurd to try different ways every time 😅

But it will call the strip command per each found .so file, whereas + should've processed as much files at once as possible (which might actually still be one per call)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's so odd. I'm fine with it being a strip call per .so. Just switched to ';'. Lets see if CI/*nix is happy. Windows should be happy per your experiments.

@dschep
Copy link
Contributor Author

dschep commented Aug 23, 2018

should work (for real this time)!

@dee-me-tree-or-love
Copy link
Contributor

Great! Worked well for me!
@sweepy84 ?

@sweepy84
Copy link

It works!!!
I had to use "**/test" as suggested by @dschep (which i think is different from documentation) but it works now!
thank you!

@dschep
Copy link
Contributor Author

dschep commented Aug 28, 2018

I've updated the readme too now 😃

@dschep dschep merged commit a7232c4 into master Aug 28, 2018
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.

Slim functionality failing on Windows
3 participants