-
-
Notifications
You must be signed in to change notification settings - Fork 416
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 add / install - Update pdm.lock file incorrectly #2696
Comments
This is exactly what frustrates me as well 🫠 |
@mpaluch92 - I did come up with a script as a workaround that handles it for my use case. It's not perfect, but it does keep the unwanted dependencies out of the Downside is the unwanted dependencies are still installed any time you add a new package
Upside is they are not saved to the
Here's the script if you want it. You'll have to customize it a bit to your needs, but hopefully it's straight forward enough: try:
import tomlkit
noTomlKit = False
except:
noTomlKit = True
from pathlib import Path
dirPath = Path(__file__).parent
rootDir = str((dirPath / '../').resolve())
lockLoc = (rootDir + '/pdm.lock')
config = {
'lock': {
'packageKey': 'package',
},
'remove': [
"nvidia-cublas-cu12",
"nvidia-cuda-cupti-cu12",
"nvidia-cuda-nvrtc-cu12",
"nvidia-cuda-runtime-cu12",
"nvidia-cudnn-cu12",
"nvidia-cufft-cu12",
"nvidia-curand-cu12",
"nvidia-cusolver-cu12",
"nvidia-cusparse-cu12",
"nvidia-nccl-cu12",
"nvidia-nvjitlink-cu12",
"nvidia-nvtx-cu12",
"triton",
],
'deps': [
{
'name': 'torch',
'remove': [
"nvidia-cublas-cu12",
"nvidia-cuda-cupti-cu12",
"nvidia-cuda-nvrtc-cu12",
"nvidia-cuda-runtime-cu12",
"nvidia-cudnn-cu12",
"nvidia-cufft-cu12",
"nvidia-curand-cu12",
"nvidia-cusolver-cu12",
"nvidia-cusparse-cu12",
"nvidia-nccl-cu12",
"nvidia-nvjitlink-cu12",
"nvidia-nvtx-cu12",
"triton",
]
}
]
}
def loadLockFile():
"""Loads the PDM lockfile to be updated"""
content = Path(lockLoc).read_text()
return tomlkit.loads(content)
def saveLockFile(lockFile):
"""Save the update lockfile"""
updated = tomlkit.dumps(lockFile)
Path(lockLoc).write_text(updated)
def removePackages(lockFile={}, config={}):
"""Remove top level packages from the lockfile"""
packages = lockFile.get('package')
remove = config.get('remove')
updated = []
for package in packages:
if package.get('name') not in remove:
updated.append(package)
lockFile['package'] = updated
return lockFile
def removeDeps(lockFile={}, config={}):
"""Remove child dependencies from packages in the lockfile"""
packages = lockFile.get('package')
updated = []
cdeps = config.get('deps')
for cdep in cdeps:
name = cdep.get('name')
remove = cdep.get('remove')
for package in packages:
if package.get('name') != name:
updated.append(package)
continue
cleaned = []
deps = package.get('dependencies')
for dep in deps:
isMatch = False
for item in remove:
if dep.startswith(item):
isMatch = True
break
if not isMatch: cleaned.append(dep)
package['dependencies'] = cleaned
updated.append(package)
lockFile['package'] = updated
return lockFile
def main(config={}):
if noTomlKit:
return print('[Warning] Can not fix lockfile, missing required tomlkit dependency')
lockFile = loadLockFile()
updatedLock = removePackages(lockFile=lockFile, config=config)
finalLock = removeDeps(lockFile=updatedLock, config=config)
saveLockFile(lockFile=finalLock)
main(config=config) Then update your # ... rest of config file
[tool.pdm.scripts]
# ... other scripts
post_add = {cmd = "python path/to/fixLock.py"}
post_lock = {cmd = "python path/to/fixLock.py"}
post_install = {cmd = "python path/to/fixLock.py"}
# ... rest of config file
|
@lancetipton Awesome! Thank you very much ❤️ |
Make sure you run commands with
-v
flag before pasting the output.Steps to reproduce
pdm init
pyproject.toml
file to look like thispdm install
pdm.lock
file looks like:pdm add sentence-transformers -dG pipeline
pdm.lock
is updated, but thetorch
package has been updated to now include nvida / cuda dependenciessentence-transformers
package, it can be any package and it still happensActual behavior
torch
package even though it was originally installed without themExpected behavior
torch
package when it was originally installed without themEnvironment Information
The text was updated successfully, but these errors were encountered: