Skip to content

Commit

Permalink
refactor: Ensure proper verbose progress logs
Browse files Browse the repository at this point in the history
  • Loading branch information
pgrzesik committed Nov 25, 2021
1 parent d70ca21 commit 44b9591
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 22 deletions.
7 changes: 3 additions & 4 deletions lib/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ function cleanupCache() {
if (fse.existsSync(cacheLocation)) {
let cleanupProgress;
if (this.serverless) {
if (this.progress) {
if (this.progress && this.log) {
cleanupProgress = this.progress.get('python-cleanup-cache');
cleanupProgress.notice(`Removing static caches at: ${cacheLocation}`, {
isMainEvent: true,
});
cleanupProgress.notice('Removing static caches');
this.log.info(`Removing static caches at: ${cacheLocation}`);
} else {
this.serverless.cli.log(`Removing static caches at: ${cacheLocation}`);
}
Expand Down
7 changes: 3 additions & 4 deletions lib/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ function injectAllRequirements(funcArtifact) {
}

let injectProgress;
if (this.progress) {
if (this.progress && this.log) {
injectProgress = this.progress.get('python-inject-requirements');
injectProgress.update('Injecting required Python packages to package', {
isMainEvent: true,
});
injectProgress.update('Injecting required Python packages to package');
this.log.info('Injecting required Python packages to package');
} else {
this.serverless.cli.log('Injecting required Python packages to package...');
}
Expand Down
7 changes: 3 additions & 4 deletions lib/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ function layerRequirements() {
}

let layerProgress;
if (this.progress) {
if (this.progress && this.log) {
layerProgress = this.progress.get('python-layer-requirements');
layerProgress.update('Packaging Python Requirements Lambda Layer', {
isMainEvent: true,
});
layerProgress.update('Packaging Python Requirements Lambda Layer');
this.log.info('Packaging Python Requirements Lambda Layer');
} else {
this.serverless.cli.log('Packaging Python Requirements Lambda Layer...');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/pip.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ async function installAllRequirements() {
const reqsInstalledAt = await installRequirementsIfNeeded(
f.module,
f,
this.serverless
this
);
// Add modulePath into .serverless for each module so it's easier for injecting and for users to see where reqs are
let modulePath = path.join(
Expand Down
6 changes: 3 additions & 3 deletions lib/pipenv.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ async function pipfileToRequirements() {
}

let generateRequirementsProgress;
if (this.progress) {
if (this.progress && this.log) {
generateRequirementsProgress = this.progress.get(
'python-generate-requirements-pipfile'
);
generateRequirementsProgress.update(
'Generating requirements.txt from Pipfile',
{ isMainEvent: true }
'Generating requirements.txt from Pipfile'
);
this.log.info('Generating requirements.txt from Pipfile');
} else {
this.serverless.cli.log('Generating requirements.txt from Pipfile...');
}
Expand Down
6 changes: 3 additions & 3 deletions lib/poetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ async function pyprojectTomlToRequirements() {
}

let generateRequirementsProgress;
if (this.progress) {
if (this.progress && this.log) {
generateRequirementsProgress = this.progress.get(
'python-generate-requirements-toml'
);
generateRequirementsProgress.update(
'Generating requirements.txt from "pyproject.toml"',
{ isMainEvent: true }
'Generating requirements.txt from "pyproject.toml"'
);
this.log.info('Generating requirements.txt from "pyproject.toml"');
} else {
this.serverless.cli.log(
'Generating requirements.txt from pyproject.toml...'
Expand Down
6 changes: 3 additions & 3 deletions lib/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ function packRequirements() {
.then((funcs) => uniqBy(funcs, (f) => f.module))
.map((f) => {
let packProgress;
if (this.progress) {
if (this.progress && this.log) {
packProgress = this.progress.get(
`python-pack-requirements-${f.module}`
);
packProgress.update(
`Zipping required Python packages for ${f.module}`,
{ isMainEvent: true }
`Zipping required Python packages for ${f.module}`
);
this.log.info(`Zipping required Python packages for ${f.module}`);
} else {
this.serverless.cli.log(
`Zipping required Python packages for ${f.module}...`
Expand Down

0 comments on commit 44b9591

Please sign in to comment.