-
Notifications
You must be signed in to change notification settings - Fork 293
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
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c7cd20b
basic cleanup aroudn slim option
dschep e96ed4c
clean up slim code using glob-all to make it more cross platform
dschep c25a855
fix use of Array.concat
dschep f374288
try omiting \\ in strip command. might need to differ command for win…
7f5d861
prettier
2ef8cae
use + with -exec for strip bc strip supports multiple files and + doe…
8886f21
doh prettier again
b87a3fc
damn... find in docker on widnows is finicky
4423205
Update README.md
dschep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,25 @@ | ||
const isWsl = require('is-wsl'); | ||
const glob = require('glob-all'); | ||
const fse = require('fs-extra'); | ||
|
||
/** | ||
* Get commands to slim the installed requirements | ||
* only for non-windows platforms: | ||
* works for docker builds and when run on UNIX platforms (wsl included) | ||
* @param {Object} options | ||
* @param {string} folderPath | ||
* @return {Array.<String>} | ||
*/ | ||
function getSlimPackageCommands(options, folderPath) { | ||
let stripCmd = []; | ||
const getStripCommand = (options, folderPath) => | ||
process.platform !== 'win32' || isWsl || options.dockerizePip | ||
? ` && find ${folderPath} -name "*.so" -exec strip {} +` | ||
: ''; | ||
|
||
// Default stripping is done for non-windows environments | ||
if (process.platform !== 'win32' || isWsl) { | ||
stripCmd = getDefaultSLimOptions(folderPath); | ||
|
||
// If specified any custom patterns to remove | ||
if (options.slimPatterns instanceof Array) { | ||
// Add the custom specified patterns to remove to the default commands | ||
const customPatterns = options.slimPatterns.map(pattern => { | ||
return getRemovalCommand(folderPath, pattern); | ||
}); | ||
stripCmd = stripCmd.concat(customPatterns); | ||
const deleteFiles = (options, folderPath) => { | ||
let patterns = ['**/*.py[c|o]', '**/__pycache__*', '**/*.dist-info*']; | ||
if (options.slimPatterns) { | ||
patterns = patterns.concat(options.slimPatterns); | ||
} | ||
for (const pattern of patterns) { | ||
for (const file of glob.sync(`${folderPath}/${pattern}`)) { | ||
fse.removeSync(file); | ||
} | ||
} | ||
return stripCmd; | ||
} | ||
|
||
/** | ||
* Gets the commands to slim the default (safe) files: | ||
* including removing caches, stripping compiled files, removing dist-infos | ||
* @param {String} folderPath | ||
* @return {Array} | ||
*/ | ||
function getDefaultSLimOptions(folderPath) { | ||
return [ | ||
`&& find ${folderPath} -name "*.so" -exec strip {} \\;`, | ||
`&& find ${folderPath} -name "*.py[c|o]" -exec rm -rf {} +`, | ||
`&& find ${folderPath} -type d -name "__pycache__*" -exec rm -rf {} +`, | ||
`&& find ${folderPath} -type d -name "*.dist-info*" -exec rm -rf {} +` | ||
]; | ||
} | ||
|
||
/** | ||
* Get the command created fromt he find and remove template: | ||
* returns a string in form `&& find <folder> -name "<match>" -exec rm -rf {} +` | ||
* @param {String} folderPath | ||
* @param {String} removalMatch | ||
* @return {String} | ||
*/ | ||
function getRemovalCommand(folderPath, removalMatch) { | ||
return `&& find ${folderPath} -type d -wholename "${removalMatch}" -exec rm -rf {} +`; | ||
} | ||
}; | ||
|
||
module.exports = { | ||
getSlimPackageCommands, | ||
getDefaultSLimOptions | ||
getStripCommand, | ||
deleteFiles | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
slimPatterns: | ||
- "*.egg-info*" | ||
- "**/*.egg-info*" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
slimPatterns: | ||
- "*.egg-info*" | ||
- "**/*.egg-info*" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 😅
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)There was a problem hiding this comment.
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.