# Copyright Kevin Deldycke <kevin@deldycke.com> and contributors.## This program is Free Software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# of the License, or (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."""Utilities and helper to organize, inspect and audit the capabilities of mpm andpackage managers."""from__future__importannotationsimportloggingfromfunctoolsimportwrapsfromtypingimportTYPE_CHECKING,Callable,Iterator,ParamSpec,TypeVarifTYPE_CHECKING:from.baseimportPackage,PackageManagerP=ParamSpec("P")T=TypeVar("T")
[docs]defsearch_capabilities(extended_support:bool=True,exact_support:bool=True):"""Decorator factory to be used on ``search()`` operations to signal ``mpm`` framework manager's capabilities."""defdecorator(function):@wraps(function)defwrapper(self:PackageManager,query:str,extended:bool,exact:bool,)->Iterator[Package]:refilter=Falseifexactandnotexact_support:refilter=Truelogging.warning(f"{self.id} does not implement exact search operation.",)ifextendedandnotextended_support:refilter=Truelogging.warning(f"{self.id} does not implement extended search operation.",)ifrefilter:logging.warning("Refiltering of raw results has been activated.")returnfunction(self,query,extended,exact)# type: ignorereturnwrapperreturndecorator
[docs]defversion_not_implemented(func:Callable[P,T])->Callable[P,T]:"""Decorator to be used on ``install()`` or ``upgrade_one_cli()`` operations to signal that a particular operation does not implement (yet) the version specifier parameter."""defprint_warning(*args:P.args,**kwargs:P.kwargs)->T:ifkwargs.get("version"):logging.warning(f"{func.__qualname__} does not implement version parameter. ""Let the package manager choose the version.",)returnfunc(*args,**kwargs)returnprint_warning