Skip to content
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

Write lockfile before calling the "post_lock" hook #1224

Closed
lecardozo opened this issue Jul 15, 2022 · 3 comments · Fixed by #1225
Closed

Write lockfile before calling the "post_lock" hook #1224

lecardozo opened this issue Jul 15, 2022 · 3 comments · Fixed by #1225
Labels
⭐ enhancement Improvements for existing features 💝 good first issue Good for newcomers ❓ help wanted Extra attention is needed

Comments

@lecardozo
Copy link
Contributor

Is your feature request related to a problem? Please describe.

First, thanks for the nice work with PDM. 😄

I've been trying to come up with a way to pdm export a requirements.txt file every time an update to the lockfile happens. As some vulnerability scanning services and other CI tools do not yet support parsing/reading/interpreting pdm.lock files, this would allow us to adopt the PDM without compromising other parts of the workflow.

At first, we thought using PDM lifecycle hooks functionality would suffice. Something like

[tool.pdm.scripts]
post_lock = {shell = "pdm export -f requirements > requirements.txt"}

Unfortunately, that did not work, as the post_lock hook is called before the lockfile is written to the disk (snippet below)

pdm/pdm/cli/actions.py

Lines 120 to 125 in 7d9c0f3

else:
data = format_lockfile(project, mapping, dependencies)
ui.echo(f"{termui.Emoji.LOCK} Lock successful")
hooks.try_emit("post_lock", resolution=mapping, dry_run=dry_run)
project.write_lockfile(data, write=not dry_run)

Describe the solution you'd like

Having the lockfile written to the disk before calling the post_lock hook would enable this functionality and make PDM's adoption easier for workflows that rely, at some point, on the standard requirements.txt file. 😃

@lecardozo lecardozo added the ⭐ enhancement Improvements for existing features label Jul 15, 2022
@thiagoazeredo-quintoandar

+1

@frostming
Copy link
Collaborator

I think this is a good issue for a new contributor 👍

@frostming frostming added ❓ help wanted Extra attention is needed 💝 good first issue Good for newcomers labels Jul 15, 2022
@lecardozo
Copy link
Contributor Author

Nice! I'll tackle that 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ enhancement Improvements for existing features 💝 good first issue Good for newcomers ❓ help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants