Dependencies#
Types of dependencies#
There are three types of dependencies in sktime: core, soft, or developer.
Note
Core dependencies are required to install and run
sktimeand are automatically installed withsktime, e.g.pandas;Soft dependencies are only required to import certain modules, but not necessary to use most functionalities. A soft dependency is not installed automatically with the package. Instead, users need to install it manually if they want to use a module that requires a soft dependency, e.g.
pmdarima;Developer dependencies are required for
sktimedevelopers, but not for typical users ofsktime, e.g.pytest.
We try to keep the number of core dependencies to a minimum and rely on other packages as soft dependencies when feasible.
Adding a soft dependency#
Soft dependencies in sktime should usually be restricted to estimators.
When adding a new soft dependency or changing the version of an existing one, the following files need to be updated:
pyproject.toml, adding the dependency or version bounds in the
all_extrasdependency set. Following the PEP 621 convention, all dependencies including build time dependencies and optional dependencies are specified in this file.
Informative warnings or error messages for missing soft dependencies should be raised, in a situation where a user would need them.
This is handled through our _check_soft_dependencies utility
here.
There are specific conventions to add such warnings in estimators, as below. To add an estimator with a soft dependency, ensure the following:
imports of the soft dependency only happen inside the estimator, e.g., in
_fitor__init__methods of the estimator. In__init__, imports should happen only after calls tosuper(cls).__init__.the
python_dependenciestag of the estimator is populated with astr, or alistofstr, of import dependencies. Exceptions will automatically raised when constructing the estimator in an environment without the required packages.In a case where the package import differs from the package name, i.e.,
import package_stringis different frompip install different-package-string(usually the case for packages containing a dash in the name), the_check_soft_dependenciesutility should be called in__init__before thesuper.__init__call, withseverity="error". Thepackage_import_aliasargument should be used to pass the information on package and import strings.If the soft dependencies require specific python versions, the
python_versiontag should also be populated, with a PEP 440 compliant version specificationstrsuch as"<3.10"or">3.6,~=3.8".If including docstring examples that use soft dependencies, ensure to skip doctest. To do this add a
# doctest: +SKIPto the end of each line in the doctest to skip. Check out the arima estimator as as an example. If concerned that skipping the test will reduce test coverage, consider exposing the doctest example as a pytest test function instead, see below how to handle soft dependencies in pytest functions.”.Decorate all pytest tests that import soft dependencies with a
@pytest.mark.skipif(...)conditional on a check to_check_soft_dependenciesfor your new soft depenency. Be sure that all soft dependencies which are imported for testing are imported within the test funciton itself, rather than for the whole module! This decorator will then skip your test unless the system has the required packages installed. Doing this is helpful for any users runningcheck_estimatoron all estimators, or a full local pytest run without the required soft dependency. Again, see the tests for pydarima (in forecasting) for a concrete example.
Adding a core or developer dependency#
Core or developer dependencies can be added only by core developers after discussion in the core developer meeting.
When adding a new core dependency or changing the version of an existing one, the following files need to be updated:
pyproject.toml, adding the dependency or version bounds in the
dependenciesdependency set.
When adding a new developer dependency or changing the version of an existing one, the following files need to be updated:
pyproject.toml, adding the dependency or version bounds in the
devdependency set.