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

pdm: Adds basic lock file invalidation #1035

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions modules/dream2nix/WIP-python-pdm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,43 @@

pyproject = libpdm.loadPdmPyProject (lib.importTOML config.pdm.pyproject);

invalidatianData = {
dependencies = pyproject.pyproject.project.dependencies or [];
"dev-dependencies" = pyproject.pyproject.tool.pdm."dev-dependencies" or {};
"optional-dependencies" = pyproject.pyproject.project."optional-dependencies" or {};
sources = pyproject.pyproject.tool.pdm.source or [];
"requires-python" = pyproject.pyproject.project."requires-python" or "";
overrides = pyproject.pyproject.tool.pdm.resolution.overrides or {};
};
lockstr = lib.replaceStrings [":" ","] [": " ", "] (builtins.toString (builtins.toJSON invalidatianData));
lock_hash = "sha256:" + builtins.hashString "sha256" lockstr;
lockIsValid = lock_hash == lock_data.metadata.content_hash;

updateHint = ''
To create or update the lock file, run:

bash -c $(nix-build ${config.lock.refresh.drvPath} --no-link)/bin/refresh

Alternatively `nix run` the .lock attribute of your package, or run 'pdm lock'.
'';

errorOutdated = ''
The lock file ${config.pdm.lockfile}
for drv-parts module '${config.name}' is outdated.

${updateHint}
'';

groups_with_deps = libpdm.groupsWithDeps {
inherit environ pyproject;
};
parsed_lock_data = libpdm.parseLockData {
inherit environ lock_data;
};
parsed_lock_data =
if ! lockIsValid
then throw errorOutdated
else
libpdm.parseLockData {
inherit environ lock_data;
};
buildSystemNames =
map
(name: (libpyproject.pep508.parseString name).name)
Expand Down