Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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__}'
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
 def get_requirements(self):
     return Requirements([
         InstallableRequirement.from_str(
             f'dill=={get_module_version(dill)}')
     ])  # for example
Exemplo n.º 7
0
 def requirements(self) -> Requirements:
     return Requirements([InstallableRequirement.from_module(tf)
                          ]) + super().requirements.fget(self)
Exemplo n.º 8
0
 def process(self, obj: Requirement, **kwargs) -> Requirements:
     return Requirements([obj, InstallableRequirement('bbbb')])
Exemplo n.º 9
0
 def can_process(self, obj: Requirement) -> bool:
     return obj == InstallableRequirement('aaaa')
Exemplo n.º 10
0
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']
Exemplo n.º 11
0
 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()
Exemplo n.º 12
0
 def requirements(self) -> Requirements:
     return Requirements([InstallableRequirement.from_module(lgb)
                          ]) + self.inner.requirements
Exemplo n.º 13
0
def test_resolve_requirement_arg():
    req = InstallableRequirement('dumb', '0.4.1')
    actual_reqs = resolve_requirements(req)
    assert actual_reqs.installable[0] == req
Exemplo n.º 14
0
 def _model_requirements(self) -> Requirements:
     return Requirements([
         InstallableRequirement.from_module(lib) for lib in self.libraries
     ])