AdithyaSK's picture
AdithyaSK HF Staff
Publish 100 swe_next Harbor tasks
d40299b verified
|
Raw History Blame
2.37 kB
## `Pylock.select()` does not support `prefer_sdist_predicate` argument
When calling `Pylock.select()` with a `prefer_sdist_predicate` keyword argument, a `TypeError` is raised because the method does not accept that parameter.
The expected behavior is that `prefer_sdist_predicate` should be a callable that takes a normalized package name and returns `True` if the source distribution should be preferred over available wheels for that package. If no sdist is available for a package, the predicate should not be called and wheel selection should proceed as normal.
### Example
```python
from packaging.pylock import Package, PackageSdist, PackageWheel, Pylock
from packaging.tags import sys_tags
from packaging.version import Version
from typing import cast
pylock = Pylock(
lock_version=Version("1.0"),
created_by="some_tool",
packages=[
Package(
name=cast("NormalizedName", "foo"),
sdist=PackageSdist(path="foo-1.0.tar.gz", hashes={"sha256": "abc123"}),
wheels=[
PackageWheel(path="./foo-1.0-py3-none-any.whl", hashes={"sha256": "abc123"})
],
)
],
)
pylock.validate()
def prefer_sdist(name):
return True # always prefer source distributions
result = list(pylock.select(prefer_sdist_predicate=prefer_sdist))
```
Running this raises:
```
TypeError: Pylock.select() got an unexpected keyword argument 'prefer_sdist_predicate'
```
### Expected behavior
`Pylock.select()` should accept a `prefer_sdist_predicate` callable. When the predicate returns `True` for a given package name and an sdist is available, the sdist should be yielded instead of a compatible wheel. If no sdist is available for a package, the predicate should not be called and normal wheel selection should apply. When no wheels exist and the predicate returns `False`, the sdist should still be selected as a fallback.
### Actual behavior
`Pylock.select()` raises `TypeError: Pylock.select() got an unexpected keyword argument 'prefer_sdist_predicate'` regardless of the arguments passed.
Work in `/workspace`. Submit your fix in the existing Python source files under `src/packaging`. Preserve the other public behavior. The environment is offline; dependencies are preinstalled. Grading runs the repository's test suite in a fresh environment, using your submitted source files.