def test_resolve_requirements_arg(): requirements = Requirements([ InstallableRequirement('dumb', '0.4.1'), InstallableRequirement('art', '4.0') ]) actual_reqs = resolve_requirements(requirements) assert actual_reqs == requirements
def test_resolve_requirement_list_arg(): req = [ InstallableRequirement('dumb', '0.4.1'), InstallableRequirement('art', '4.0') ] actual_reqs = resolve_requirements(req) assert len(actual_reqs.installable) == 2 assert actual_reqs.installable == req
def test_create_model_with_custom_requirements(sklearn_model_obj, pandas_data): requirements = Requirements([ InstallableRequirement('dumb', '0.4.1'), InstallableRequirement('art', '4.0') ]) model = Model.create(sklearn_model_obj, pandas_data, custom_requirements=Requirements([Requirement()])) assert model is not None assert all(req in [r.module for r in requirements.installable] for req in model.requirements.installable)
def test_installable_requirement__from_module(): import pandas as pd assert InstallableRequirement.from_module( pd).to_str() == f'pandas=={pd.__version__}' import numpy as np assert InstallableRequirement.from_module( np).to_str() == f'numpy=={np.__version__}' import sklearn as sk assert InstallableRequirement.from_module( sk).to_str() == f'scikit-learn=={sk.__version__}' assert InstallableRequirement.from_module( sk, 'xyz').to_str() == f'xyz=={sk.__version__}'
def get_module_as_requirement(mod: ModuleType, validate_pypi=False) -> InstallableRequirement: """ Builds Ebonite representation of given module object :param mod: module object to use :param validate_pypi: if `True` (default is `False`) perform representation validation in PyPi repository :return: representation as :class:`.InstallableRequirement` """ mod_version = get_module_version(mod) if validate_pypi: mod_name = get_package_name(mod) check_pypi_module(mod_name, mod_version, raise_on_error=True) return InstallableRequirement(mod.__name__, mod_version)
def get_requirements(self): return Requirements([ InstallableRequirement.from_str( f'dill=={get_module_version(dill)}') ]) # for example
def requirements(self) -> Requirements: return Requirements([InstallableRequirement.from_module(tf) ]) + super().requirements.fget(self)
def process(self, obj: Requirement, **kwargs) -> Requirements: return Requirements([obj, InstallableRequirement('bbbb')])
def can_process(self, obj: Requirement) -> bool: return obj == InstallableRequirement('aaaa')
def test_requirement_analyzer(): req = InstallableRequirement('aaaa') result = RequirementAnalyzer.analyze(req) assert isinstance(result, Requirements) assert len(result.requirements) == 3 assert sorted(r.module for r in result.requirements) == ['aaaa', 'bbbb', 'cccc']
def _model_requirements(self) -> Requirements: if get_object_base_module(self.model) is sklearn: return Requirements([InstallableRequirement.from_module(sklearn)]) # some sklearn compatible model (either from library or user code) - fallback return super()._model_requirements()
def requirements(self) -> Requirements: return Requirements([InstallableRequirement.from_module(lgb) ]) + self.inner.requirements
def test_resolve_requirement_arg(): req = InstallableRequirement('dumb', '0.4.1') actual_reqs = resolve_requirements(req) assert actual_reqs.installable[0] == req
def _model_requirements(self) -> Requirements: return Requirements([ InstallableRequirement.from_module(lib) for lib in self.libraries ])