Skip to content

Commit

Permalink
ran prettier and pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jax-b committed Feb 25, 2024
1 parent ce2cc61 commit ba19f19
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 129 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.js text eol=lf
*.json text eol=lf
*.json text eol=lf
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
python-version: '3.10'

- name: Install Node.js and npm
uses: actions/setup-node@v1
Expand Down
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
2 changes: 1 addition & 1 deletion example_native_deps/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
numpy==1.13.3
scipy==1.0.0
sklearn==0.0
sklearn==0.0
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ServerlessPythonRequirements {
},
(this.serverless.service.custom &&
this.serverless.service.custom.pythonRequirements) ||
{}
{},
);
if (
options.pythonBin === this.serverless.service.provider.runtime &&
Expand Down Expand Up @@ -94,19 +94,19 @@ class ServerlessPythonRequirements {
if (!this.warningLogged) {
if (this.log) {
this.log.warning(
'You provided a docker related option but dockerizePip is set to false.'
'You provided a docker related option but dockerizePip is set to false.',
);
} else {
this.serverless.cli.log(
'WARNING: You provided a docker related option but dockerizePip is set to false.'
'WARNING: You provided a docker related option but dockerizePip is set to false.',
);
}
this.warningLogged = true;
}
}
if (options.dockerImage && options.dockerFile) {
throw new Error(
'Python Requirements: you can provide a dockerImage or a dockerFile option, not both.'
'Python Requirements: you can provide a dockerImage or a dockerFile option, not both.',
);
}

Expand Down Expand Up @@ -243,8 +243,8 @@ class ServerlessPythonRequirements {
.then(() =>
injectAllRequirements.bind(this)(
arguments[1].functionObj &&
arguments[1].functionObj.package.artifact
)
arguments[1].functionObj.package.artifact,
),
);
};

Expand Down
6 changes: 3 additions & 3 deletions lib/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ function cleanup() {

return BbPromise.all(
artifacts.map((artifact) =>
fse.removeAsync(path.join(this.servicePath, artifact))
)
fse.removeAsync(path.join(this.servicePath, artifact)),
),
);
}

Expand Down Expand Up @@ -58,7 +58,7 @@ function cleanupCache() {
promises.push(fse.removeAsync(file));
});
return BbPromise.all(promises).finally(
() => cleanupProgress && cleanupProgress.remove()
() => cleanupProgress && cleanupProgress.remove(),
);
} else {
if (this.serverless) {
Expand Down
6 changes: 3 additions & 3 deletions lib/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function dockerCommand(options, pluginInstance) {
) {
throw new pluginInstance.serverless.classes.Error(
'docker not found! Please install it.',
'PYTHON_REQUIREMENTS_DOCKER_NOT_FOUND'
'PYTHON_REQUIREMENTS_DOCKER_NOT_FOUND',
);
}
throw e;
Expand All @@ -42,7 +42,7 @@ async function buildImage(dockerFile, extraArgs, pluginInstance) {
} else {
throw new pluginInstance.serverless.classes.Error(
'dockerRunCmdExtraArgs option must be an array',
'PYTHON_REQUIREMENTS_INVALID_DOCKER_EXTRA_ARGS'
'PYTHON_REQUIREMENTS_INVALID_DOCKER_EXTRA_ARGS',
);
}

Expand Down Expand Up @@ -72,7 +72,7 @@ function findTestFile(servicePath, pluginInstance) {
}
throw new pluginInstance.serverless.classes.Error(
'Unable to find serverless.{yml|yaml|json} or requirements.txt for getBindPath()',
'PYTHON_REQUIREMENTS_MISSING_GET_BIND_PATH_FILE'
'PYTHON_REQUIREMENTS_MISSING_GET_BIND_PATH_FILE',
);
}

Expand Down
34 changes: 17 additions & 17 deletions lib/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function injectRequirements(
requirementsPath,
packagePath,
injectionRelativePath,
options
options,
) {
const noDeploy = new Set(options.noDeploy || []);

Expand All @@ -33,31 +33,31 @@ function injectRequirements(
glob.sync([path.join(requirementsPath, '**')], {
mark: true,
dot: true,
})
}),
)
.map((file) => [
file,
path.join(
injectionRelativePath,
path.relative(requirementsPath, file)
path.relative(requirementsPath, file),
),
])
.filter(
([file, relativeFile]) =>
!file.endsWith('/') &&
!relativeFile.match(/^__pycache__[\\/]/) &&
!noDeploy.has(relativeFile.split(/([-\\/]|\.py$|\.pyc$)/, 1)[0])
!noDeploy.has(relativeFile.split(/([-\\/]|\.py$|\.pyc$)/, 1)[0]),
)
.map(([file, relativeFile]) =>
Promise.all([file, relativeFile, fse.statAsync(file)])
Promise.all([file, relativeFile, fse.statAsync(file)]),
)
.mapSeries(([file, relativeFile, fileStat]) =>
zipFile(zip, relativeFile, fse.readFileAsync(file), {
unixPermissions: fileStat.mode,
createFolders: false,
})
}),
)
.then(() => writeZip(zip, packagePath))
.then(() => writeZip(zip, packagePath)),
);
}

Expand All @@ -79,17 +79,17 @@ function moveModuleUp(source, target, module) {
(file) =>
file.startsWith(module + '/') ||
file.startsWith('serverless_sdk/') ||
file.match(/^s_.*\.py/) !== null
)
file.match(/^s_.*\.py/) !== null,
),
)
.map((srcZipObj) =>
zipFile(
targetZip,
srcZipObj.name.startsWith(module + '/')
? srcZipObj.name.replace(module + '/', '')
: srcZipObj.name,
srcZipObj.async('nodebuffer')
)
srcZipObj.async('nodebuffer'),
),
)
.then(() => writeZip(targetZip, target));
}
Expand Down Expand Up @@ -123,8 +123,8 @@ async function injectAllRequirements(funcArtifact) {
await BbPromise.resolve(this.targetFuncs)
.filter((func) =>
(func.runtime || this.serverless.service.provider.runtime).match(
/^python.*/
)
/^python.*/,
),
)
.map((func) => {
if (!get(func, 'module')) {
Expand All @@ -139,11 +139,11 @@ async function injectAllRequirements(funcArtifact) {
: funcArtifact;
const newArtifact = path.join(
'.serverless',
`${func.module}-${func.name}.zip`
`${func.module}-${func.name}.zip`,
);
func.package.artifact = newArtifact;
return moveModuleUp(artifact, newArtifact, func.module).then(
() => func
() => func,
);
} else {
return func;
Expand All @@ -156,15 +156,15 @@ async function injectAllRequirements(funcArtifact) {
path.join('.serverless', func.module, 'requirements'),
func.package.artifact,
injectionRelativePath,
this.options
this.options,
);
});
} else if (!this.options.zip) {
await injectRequirements(
path.join('.serverless', 'requirements'),
this.serverless.service.package.artifact || funcArtifact,
injectionRelativePath,
this.options
this.options,
);
}
} finally {
Expand Down
12 changes: 6 additions & 6 deletions lib/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function zipRequirements() {
reqChecksum,
targetZipPath,
this.options,
this.serverless
this.serverless,
);

const promises = [];
Expand All @@ -28,12 +28,12 @@ function zipRequirements() {
if (this.progress && this.log) {
layerProgress = this.progress.get('python-layer-requirements');
layerProgress.update(
'Using cached Python Requirements Lambda Layer file'
'Using cached Python Requirements Lambda Layer file',
);
this.log.info('Found cached Python Requirements Lambda Layer file');
} else {
this.serverless.cli.log(
'Found cached Python Requirements Lambda Layer file'
'Found cached Python Requirements Lambda Layer file',
);
}
} else {
Expand All @@ -42,8 +42,8 @@ function zipRequirements() {

promises.push(
addTree(rootZip.folder(runtimepath), src).then(() =>
writeZip(rootZip, zipCachePath)
)
writeZip(rootZip, zipCachePath),
),
);
}
return BbPromise.all(promises).then(() => {
Expand Down Expand Up @@ -75,7 +75,7 @@ function createLayers() {
'Python requirements generated by serverless-python-requirements.',
compatibleRuntimes: [this.serverless.service.provider.runtime],
},
this.options.layer
this.options.layer,
);

return BbPromise.resolve();
Expand Down
Loading

0 comments on commit ba19f19

Please sign in to comment.