@@ -781,9 +781,30 @@ class AbstractHookResolver(AbstractResolver, CooldownMixin):
781781 supports_override_hooks : typing .ClassVar [bool ] = True
782782 """Hook resolvers support override hooks."""
783783
784+ hookless_provider : typing .ClassVar [str ]
785+ """Profile to suggest for packages without hooks."""
786+
787+ def _find_resolver_hook (self , req : Requirement ) -> typing .Callable | None :
788+ """Return the package resolver hook, or None to resolve on the index.
789+
790+ Resolving on the index needs a ``download_source`` hook to get the
791+ source. Raise when the package has neither hook.
792+ """
793+ hook = overrides .find_override_method (req .name , "get_resolver_provider" )
794+ if hook is None and not overrides .find_override_method (
795+ req .name , "download_source"
796+ ):
797+ raise ValueError (
798+ f"{ req .name } : source resolver { self .provider !r} requires a "
799+ "get_resolver_provider or download_source override hook; "
800+ f"use { self .hookless_provider !r} for a package without hooks"
801+ )
802+ return hook
803+
784804 def _resolver_provider_from_hook (
785805 self ,
786806 * ,
807+ hook : typing .Callable ,
787808 ctx : context .WorkContext ,
788809 req : Requirement ,
789810 req_type : requirements_file .RequirementType | None ,
@@ -792,14 +813,7 @@ def _resolver_provider_from_hook(
792813 include_wheels : bool ,
793814 ignore_platform : bool ,
794815 ) -> resolver .BaseProvider :
795- """Invoke the required package resolver hook and validate its result."""
796- hook = overrides .find_override_method (req .name , "get_resolver_provider" )
797- if hook is None :
798- raise ValueError (
799- f"{ req .name } : source resolver { self .provider !r} requires a "
800- "get_resolver_provider override hook"
801- )
802-
816+ """Invoke the package resolver hook and validate its result."""
803817 try :
804818 provider = overrides .invoke (
805819 hook ,
@@ -903,9 +917,11 @@ class HookSDistResolver(AbstractHookResolver):
903917 """Call resolver_provider and download_source hook, build from source
904918
905919 The ``hook-sdist`` provider delegates resolution and download to
906- plugin hooks. The downloaded artifact can be a source distribution,
907- a tarball, or a git checkout. Download hooks can return ``DownloadedSource``
908- with a concrete kind, or a legacy archive ``Path`` treated as an sdist.
920+ plugin hooks. Either hook is optional, but not both. Without a resolver
921+ hook, versions come from ``index_url``. The downloaded artifact can be a
922+ source distribution, a tarball, or a git checkout. Download hooks can
923+ return ``DownloadedSource`` with a concrete kind, or a legacy archive
924+ ``Path`` treated as an sdist.
909925 Without a download hook, the resolved URL is downloaded as an sdist.
910926 Specify ``build_sdist`` explicitly: ``tarball`` to repack an existing
911927 sdist, or ``pep517`` to build from a git checkout.
@@ -929,15 +945,32 @@ class HookSDistResolver(AbstractHookResolver):
929945 download_kinds : typing .ClassVar [DownloadKindSet ] = frozenset (
930946 {DownloadKind .sdist , DownloadKind .tarball , DownloadKind .git_checkout }
931947 )
948+ hookless_provider : typing .ClassVar [str ] = "pypi-sdist"
932949
933950 def resolver_provider (
934951 self ,
935952 ctx : context .WorkContext ,
936953 req : Requirement ,
937954 req_type : requirements_file .RequirementType | None ,
938955 ) -> resolver .BaseProvider :
939- """Return a source provider from the package resolver hook."""
956+ """Return a source provider from the resolver hook or the index.
957+
958+ Without a ``get_resolver_provider`` hook, find versions on
959+ ``index_url`` in sdists and wheels for any platform, like
960+ ``pypi-git``. The ``download_source`` hook then gets the source.
961+ """
962+ hook = self ._find_resolver_hook (req )
963+ if hook is None :
964+ return resolver .PyPIProvider (
965+ include_sdists = True ,
966+ include_wheels = True ,
967+ sdist_server_url = str (self .index_url ),
968+ constraints = ctx .constraints ,
969+ req_type = req_type ,
970+ ignore_platform = True ,
971+ )
940972 return self ._resolver_provider_from_hook (
973+ hook = hook ,
941974 ctx = ctx ,
942975 req = req ,
943976 req_type = req_type ,
@@ -964,10 +997,11 @@ class HookPrebuiltResolver(AbstractHookResolver):
964997 """Call resolver_provider and download_source hook, use pre-built wheel
965998
966999 The ``hook-prebuilt`` provider delegates resolution and download to
967- plugin hooks. The downloaded artifact must be a pre-built wheel. Download
968- hooks can return ``DownloadedSource`` with kind ``prebuilt_wheel`` or a
969- legacy wheel ``Path``. Without a download hook, the resolved URL is downloaded
970- into ``ctx.wheels_prebuilt``.
1000+ plugin hooks. Either hook is optional, but not both. Without a resolver
1001+ hook, versions come from ``index_url``. The downloaded artifact must be a
1002+ pre-built wheel. Download hooks can return ``DownloadedSource`` with kind
1003+ ``prebuilt_wheel`` or a legacy wheel ``Path``. Without a download hook,
1004+ the resolved URL is downloaded into ``ctx.wheels_prebuilt``.
9711005
9721006 Example::
9731007
@@ -986,15 +1020,32 @@ class HookPrebuiltResolver(AbstractHookResolver):
9861020 {DownloadKind .prebuilt_wheel }
9871021 )
9881022 resolves_prebuilt_wheel : typing .ClassVar [bool ] = True
1023+ hookless_provider : typing .ClassVar [str ] = "pypi-prebuilt"
9891024
9901025 def resolver_provider (
9911026 self ,
9921027 ctx : context .WorkContext ,
9931028 req : Requirement ,
9941029 req_type : requirements_file .RequirementType | None ,
9951030 ) -> resolver .BaseProvider :
996- """Return a pre-built wheel provider from the package resolver hook."""
1031+ """Return a pre-built wheel provider from the resolver hook or the index.
1032+
1033+ Without a ``get_resolver_provider`` hook, find versions on
1034+ ``index_url`` in wheels for this platform, like ``pypi-prebuilt``.
1035+ The ``download_source`` hook then gets the wheel.
1036+ """
1037+ hook = self ._find_resolver_hook (req )
1038+ if hook is None :
1039+ return resolver .PyPIProvider (
1040+ include_sdists = False ,
1041+ include_wheels = True ,
1042+ sdist_server_url = str (self .index_url ),
1043+ constraints = ctx .constraints ,
1044+ req_type = req_type ,
1045+ ignore_platform = False ,
1046+ )
9971047 return self ._resolver_provider_from_hook (
1048+ hook = hook ,
9981049 ctx = ctx ,
9991050 req = req ,
10001051 req_type = req_type ,
0 commit comments