-
Notifications
You must be signed in to change notification settings - Fork 293
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
feat: Introduce requirePoetryLockFile
flag
#728
feat: Introduce requirePoetryLockFile
flag
#728
Conversation
lib/poetry.js
Outdated
const emitMsg = (msg) => { | ||
if (generateRequirementsProgress) { | ||
generateRequirementsProgress.update(msg) | ||
log.info(msg); | ||
} else { | ||
serverless.cli.log(msg); | ||
} | ||
} |
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.
I am less certain about this part. I extracted what looked like the logging logic.
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.
Hey @FinchPowers, thanks a lot for proposing this. I think the idea is good, however, I have a few comments and it seems like the CI builds are failing. Could you please look into that? Thanks!
lib/poetry.js
Outdated
} | ||
|
||
try { | ||
await spawn("test", ["-f", "poetry.lock"]) |
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.
Is that command cross-platform?
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.
I guess not! :) I'll have a look.
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.
thanks 🙇
lib/poetry.js
Outdated
emitMsg('Generating requirements.txt from poetry.lock...'); | ||
} catch (e) { | ||
if (options.requirePoetryLockFile) { | ||
throw new Error( |
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.
Let's not throw such errors, use the Error
class passed from the Serverless class (serverless.classes.Error
).
lib/poetry.js
Outdated
); | ||
} | ||
emitMsg( | ||
'Generating poetry.lock and requirements.txt from pyproject.toml...' |
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.
Let's not put the dots at the end - it can update an interactive spinner which already indicates that something is happening
And I forgot - it would be great to cover that functionality with a test case 💯 |
cf627ff
to
166ae65
Compare
@pgrzesik Thanks for the pointers, I've updated the code. For testing, I can, but I'll need some pointers. Is it using a testing framework? From a quick glance at the code it seems to be a custom implementation. How do you suggest I approach this? I see two options:
or
|
Hey @FinchPowers, thanks a lot 🙇 As for testing, it's using |
794a646
to
24e2d2c
Compare
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.
Hey @FinchPowers, it looks great overall 🙌 I have only two minor suggestions, please let me know what do you think 🙇
} | ||
}; | ||
|
||
if (fs.existsSync('poetry.lock')) { |
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.
Let's hide this check behind the requirePoetryLockFile
, there's no need to check if for users that don't even use this flag
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.
There are two different accurate logging messages with that check though. This is the thing that brought me to open this PR: When I started working with the serverless-python-requirements plugin and saw the former message, I was unsure what it was actually doing so I had to open the code to verify.
That being said, tell me what you want me to do. :)
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.
Hey @FinchPowers, I'm not sure I understand. Why do you think it makes sense to check it for each user, even the ones that don't use the introduced flag? Maybe I'm missing something here
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.
It's to provide accurate logging. Let's say the flag does not exist, that would still leave this
if (fs.existsSync('poetry.lock')) {
emitMsg('Generating requirements.txt from poetry.lock');
} else {
emitMsg('Generating poetry.lock and requirements.txt from pyproject.toml');
}
The distinction is important. In the former case, you end up with a predictable requirements.txt
which means that you have a repeatable build. In the later, you don't, it depends on what time the command was run and what was available of that time. (Unless all dependencies are locked to a specific version in pyproject.toml
, which is rarely the case.) So if you rebuild to troubleshoot, you may endup with different dependencies and not be able to reproduce.
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.
@pgrzesik Standing by: Tell me what you would like me to do. :)
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.
Hey @FinchPowers 👋 Sorry for not responding sooner, I was on a short vacation for pretty much the whole last week.
That makes a lot of sense, thanks for the explanation 👍
* Distinct logging whether the requirements.txt file is generated from poetry.lock vs pyproject.toml. * New boolean flag: requirePoetryLockFile - When set to true, fail the build when poetry.lock is missing. This helps with creating reproducible builds where you want to have a fixed poetry.lock file instead of one generated on the fly.
24e2d2c
to
3ddf189
Compare
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.
Looking great @FinchPowers, thanks a lot 🙇 Let's wait for tests to pass and I'll merge the PR
requirePoetryLockFile
flag
Follow up to #639