![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flexidep)
[![PyPI version](https://badge.fury.io/py/flexidep.svg)](https://badge.fury.io/py/flexidep)
![GitHub](https://img.shields.io/github/license/fsantini/python-dependency-manager)
# Flexidep
Package to manage optional and alternate dependencies in python packages.
This package checks for dependencies at runtime and provides an interface to install them. It supports multiple
alternatives, so that the user can choose which package to install.
Choice for pip and conda are provided.
## Usage
This package is intended to be configured using a cfg file (similar to setup.cfg) and to be called at runtime during the
initialization of the containing module or program, before any import is done. It reads all the modules that are
required and tries to install them.
The installation can either be interactive or automatic, depending on the intended usage.
For the interactive installation, a command-line interface or a GUI based on tk are provided.
### Integration in your code
```python
from flexidep import DependencyManager, SetupFailedError, OperationCanceledError
dm = DependencyManager()
dm.load_file('test.cfg')
try:
dm.install_interactive(force_optional=True)
except OperationCanceledError:
print('Installation canceled')
except SetupFailedError:
print('Setup failed')
```
If you have a configuration file inside a python module, you can use the following simplified code:
```python
from flexidep import standard_install_from_resource
from . import resources # assuming that "resources" is the name of the module where you have the configuration file
standard_install_from_resource(resources, 'runtime_dependencies.cfg')
````
For manual control, a `DependencyManager` object is created with the following parameters:
```python
DependencyManager(
config_file=None,
config_string=None,
unique_id=None,
interactive_initialization=True,
use_gui=False,
install_local=False,
package_manager=PackageManagers.pip,
extra_command_line='',
)
```
* `config_file`: path to the configuration file. It can be a string, a Path-like object or a file-like object.
**Note**: all configuration options in a config file supersede the options specified in the constructor.
* `config_string`: string containing the configuration in config file format. If both `config_file` and `config_string` are provided, the file is used.
* `unique_id`: unique identifier for the project. It is used to store the configuration in the user's home directory.
* `interactive_initialization`: if True, the user is asked to choose the global installation parameters.
* `use_gui`: if True, a GUI is used for the interactive installation.
* `install_local`: if True, the packages are installed locally in the current environment (`--user` flag to pip)
* `package_manager`: package manager to use. Can be `PackageManagers.pip` or `PackageManagers.conda`.
* `extra_command_line`: extra command line arguments to pass to the package manager.
The main functions that are used are:
* `load_file(file)` to load the configuration file. `file` can be a file name, a file object, or a path-like object.
* `install_interactive(force_optional)` to install the dependencies in interactive mode. If force_optional is false,
optional dependencies will only be asked once and the choice will be remembered. If it is true, the choices are
cleared and the optional dependencies are asked again.
* `install_auto(install_optional)` to install the dependencies in automatic mode. If install_optional is true, optional
dependencies are installed too, otherwise only the required ones are.
#### Utility functions
The following functions are provided for convenience:
* `is_conda()` returns True if the current environment is a conda environment.
* `is_frozen()` returns True if the current environment is frozen (e.g. using pyinstaller).
### Configuration file
A typical configuration file is the following:
```ini
[Global]
# Whether to let the user specify the global options (e.g. pip or conda)
interactive initialization = True
# Whether to use the tk gui or not
use gui = True
# Whether to pass the --user flag to pip
local install = False
# Which package manager to use (pip and conda are currently supported)
package manager = pip
# A unique identifier for the app that calls the package
# (used to store the optional package choices)
id = com.myname.myproject
# a list (comma or newline-separated) of packages that are optional.
# The default status of a package is required
optional packages =
tensorflow
# Defines a priority order for the packages to be installed
priority = my_pip_package, tensorflow
# Here you can specify which packages should be uninstalled because they conflict with this package
uninstall = conflict_package
# package-manager-specific packages can be defined like this
uninstall.pip = conflict_package_pip
uninstall.conda = conflict_package_conda
# This section contains list of packages to be installed.
# The name of each entry is the name of the *module* that the package provides.
# For example, tensorflow-gpu and tensorflow-cpu both provide the tensorflow module.
# The name of the entry is therefore "tensorflow".
# After the name, the list of packages is given, separated by newlines.
# Environment markers can also be provided, so that the user is only presented with options
# that are compatible with the current environment.
[Packages]
tensorflow =
tensorflow_gpu ; sys_platform != 'darwin'
tensorflow_cpu ; sys_platform != 'darwin'
tensorflow_metal ; sys_platform == 'darwin'
tensorflow_macos ; sys_platform == 'darwin'
# Alternatives to be checked can also be specified, separated by a pipe character.
# For example, this checks that either PyQt5 or PySide2 is installed and prompts to
# install one of them if none is found.
PyQt5|PySide2 =
PyQt5
PySide2
# dependencies and conflicts can be specified for each alternative
# this is useful if this package automatically installs something that
# is unwanted with the rest of the package.
package_with_dependencies =
package_1 +install_before_package1 +install_before_package2 -uninstall_before_package --uninstall_after_package ++install_after_package
[Pip]
# pip-specific packages. These packages will only be installed if pip is used as a manager.
my_pip_package =
pip_package_1
pip_package_2
[Conda]
# conda-specific packages
``
Raw data
{
"_id": null,
"home_page": null,
"name": "flexidep",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "Package management, dependency management, package manager, dependency manager",
"author": "Francesco Santini",
"author_email": "francesco.santini@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/cb/87/21ad85e43bd79fc2c388f5b1c2a55593790c255ade88cc3872313542515f/flexidep-0.0.9.tar.gz",
"platform": null,
"description": "![PyPI - Python Version](https://img.shields.io/pypi/pyversions/flexidep)\r\n[![PyPI version](https://badge.fury.io/py/flexidep.svg)](https://badge.fury.io/py/flexidep)\r\n![GitHub](https://img.shields.io/github/license/fsantini/python-dependency-manager)\r\n\r\n# Flexidep\r\nPackage to manage optional and alternate dependencies in python packages.\r\n\r\nThis package checks for dependencies at runtime and provides an interface to install them. It supports multiple\r\nalternatives, so that the user can choose which package to install.\r\n\r\nChoice for pip and conda are provided.\r\n\r\n## Usage\r\n\r\nThis package is intended to be configured using a cfg file (similar to setup.cfg) and to be called at runtime during the\r\ninitialization of the containing module or program, before any import is done. It reads all the modules that are\r\nrequired and tries to install them.\r\n\r\nThe installation can either be interactive or automatic, depending on the intended usage.\r\n\r\nFor the interactive installation, a command-line interface or a GUI based on tk are provided.\r\n\r\n### Integration in your code\r\n\r\n```python\r\nfrom flexidep import DependencyManager, SetupFailedError, OperationCanceledError\r\n\r\ndm = DependencyManager()\r\ndm.load_file('test.cfg')\r\ntry:\r\n dm.install_interactive(force_optional=True)\r\nexcept OperationCanceledError:\r\n print('Installation canceled')\r\nexcept SetupFailedError:\r\n print('Setup failed')\r\n```\r\n\r\nIf you have a configuration file inside a python module, you can use the following simplified code:\r\n```python\r\nfrom flexidep import standard_install_from_resource\r\nfrom . import resources # assuming that \"resources\" is the name of the module where you have the configuration file\r\nstandard_install_from_resource(resources, 'runtime_dependencies.cfg')\r\n````\r\n\r\nFor manual control, a `DependencyManager` object is created with the following parameters:\r\n```python\r\nDependencyManager(\r\n config_file=None,\r\n config_string=None,\r\n unique_id=None,\r\n interactive_initialization=True,\r\n use_gui=False,\r\n install_local=False,\r\n package_manager=PackageManagers.pip,\r\n extra_command_line='',\r\n)\r\n```\r\n\r\n* `config_file`: path to the configuration file. It can be a string, a Path-like object or a file-like object.\r\n**Note**: all configuration options in a config file supersede the options specified in the constructor.\r\n* `config_string`: string containing the configuration in config file format. If both `config_file` and `config_string` are provided, the file is used.\r\n* `unique_id`: unique identifier for the project. It is used to store the configuration in the user's home directory.\r\n* `interactive_initialization`: if True, the user is asked to choose the global installation parameters.\r\n* `use_gui`: if True, a GUI is used for the interactive installation.\r\n* `install_local`: if True, the packages are installed locally in the current environment (`--user` flag to pip)\r\n* `package_manager`: package manager to use. Can be `PackageManagers.pip` or `PackageManagers.conda`.\r\n* `extra_command_line`: extra command line arguments to pass to the package manager.\r\n\r\n\r\nThe main functions that are used are:\r\n* `load_file(file)` to load the configuration file. `file` can be a file name, a file object, or a path-like object.\r\n* `install_interactive(force_optional)` to install the dependencies in interactive mode. If force_optional is false,\r\n optional dependencies will only be asked once and the choice will be remembered. If it is true, the choices are\r\n cleared and the optional dependencies are asked again.\r\n* `install_auto(install_optional)` to install the dependencies in automatic mode. If install_optional is true, optional\r\n dependencies are installed too, otherwise only the required ones are.\r\n\r\n#### Utility functions\r\nThe following functions are provided for convenience:\r\n* `is_conda()` returns True if the current environment is a conda environment.\r\n* `is_frozen()` returns True if the current environment is frozen (e.g. using pyinstaller).\r\n\r\n### Configuration file\r\nA typical configuration file is the following:\r\n```ini\r\n[Global]\r\n# Whether to let the user specify the global options (e.g. pip or conda)\r\ninteractive initialization = True\r\n# Whether to use the tk gui or not\r\nuse gui = True\r\n# Whether to pass the --user flag to pip\r\nlocal install = False\r\n# Which package manager to use (pip and conda are currently supported)\r\npackage manager = pip\r\n# A unique identifier for the app that calls the package\r\n# (used to store the optional package choices)\r\nid = com.myname.myproject\r\n# a list (comma or newline-separated) of packages that are optional.\r\n# The default status of a package is required\r\noptional packages =\r\n tensorflow\r\n\r\n# Defines a priority order for the packages to be installed\r\npriority = my_pip_package, tensorflow\r\n\r\n# Here you can specify which packages should be uninstalled because they conflict with this package\r\nuninstall = conflict_package\r\n# package-manager-specific packages can be defined like this\r\nuninstall.pip = conflict_package_pip\r\nuninstall.conda = conflict_package_conda\r\n\r\n# This section contains list of packages to be installed.\r\n# The name of each entry is the name of the *module* that the package provides.\r\n# For example, tensorflow-gpu and tensorflow-cpu both provide the tensorflow module.\r\n# The name of the entry is therefore \"tensorflow\".\r\n# After the name, the list of packages is given, separated by newlines.\r\n# Environment markers can also be provided, so that the user is only presented with options\r\n# that are compatible with the current environment.\r\n[Packages]\r\ntensorflow =\r\n tensorflow_gpu ; sys_platform != 'darwin'\r\n tensorflow_cpu ; sys_platform != 'darwin'\r\n tensorflow_metal ; sys_platform == 'darwin'\r\n tensorflow_macos ; sys_platform == 'darwin'\r\n\r\n# Alternatives to be checked can also be specified, separated by a pipe character.\r\n# For example, this checks that either PyQt5 or PySide2 is installed and prompts to\r\n# install one of them if none is found.\r\nPyQt5|PySide2 =\r\n PyQt5\r\n PySide2\r\n\r\n# dependencies and conflicts can be specified for each alternative\r\n# this is useful if this package automatically installs something that\r\n# is unwanted with the rest of the package.\r\npackage_with_dependencies =\r\n package_1 +install_before_package1 +install_before_package2 -uninstall_before_package --uninstall_after_package ++install_after_package\r\n\r\n[Pip]\r\n# pip-specific packages. These packages will only be installed if pip is used as a manager.\r\nmy_pip_package =\r\n pip_package_1\r\n pip_package_2\r\n\r\n[Conda]\r\n# conda-specific packages\r\n``\r\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Managing dependencies for other python packages, especially when multiple alternatives exist for the same module.",
"version": "0.0.9",
"project_urls": null,
"split_keywords": [
"package management",
" dependency management",
" package manager",
" dependency manager"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ce0108a35defdb09d479535eb2e56db0e1d98f76921ef96956156303d730b737",
"md5": "d0b44e57e3861af8fd55bd4ffd1519c8",
"sha256": "a48c4c06e9e650255ab7b1aeef0b3f81d46f008ef64068b4a78636aba36a4682"
},
"downloads": -1,
"filename": "flexidep-0.0.9-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d0b44e57e3861af8fd55bd4ffd1519c8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 19361,
"upload_time": "2024-09-14T12:26:44",
"upload_time_iso_8601": "2024-09-14T12:26:44.551813Z",
"url": "https://files.pythonhosted.org/packages/ce/01/08a35defdb09d479535eb2e56db0e1d98f76921ef96956156303d730b737/flexidep-0.0.9-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cb8721ad85e43bd79fc2c388f5b1c2a55593790c255ade88cc3872313542515f",
"md5": "2224a13291ed1fa403bd11d5412fb5b3",
"sha256": "428fab16c2c77618d791a85f4a6b20ac1152b6ec0b0278cc39b07befad87cb2e"
},
"downloads": -1,
"filename": "flexidep-0.0.9.tar.gz",
"has_sig": false,
"md5_digest": "2224a13291ed1fa403bd11d5412fb5b3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 19445,
"upload_time": "2024-09-14T12:26:45",
"upload_time_iso_8601": "2024-09-14T12:26:45.886741Z",
"url": "https://files.pythonhosted.org/packages/cb/87/21ad85e43bd79fc2c388f5b1c2a55593790c255ade88cc3872313542515f/flexidep-0.0.9.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-14 12:26:45",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "flexidep"
}