Skip to content

Commit 249ec26

Browse files
committed
added install_packages example and also notes on details/fail_fast flags
1 parent aed7e45 commit 249ec26

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

doc/source/examples.rst

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,14 +829,45 @@ You can also install *unofficial* packages. The following example installs a pre
829829
.. code-block:: python
830830
831831
import weka.core.packages as packages
832-
packages.install_package("/some/where/funky-package-1.0.0.zip")
832+
success = packages.install_package("/some/where/funky-package-1.0.0.zip")
833+
print(success)
833834
834835
And here installing it directly from a URL:
835836

836837
.. code-block:: python
837838
838839
import weka.core.packages as packages
839-
packages.install_package("http://some.server.com/funky-package-1.0.0.zip")
840+
info = packages.install_package("http://some.server.com/funky-package-1.0.0.zip", details=True)
841+
print(info)
842+
843+
Using the `details=True` flag, you can receive a dictionary instead of a simple boolean.
844+
This dictionary consists of:
845+
846+
* `from_repo`: whether the package was installed from the repo or not (i.e., unofficial URL or local archive)
847+
* `version`: the version (only for packages from the repo)
848+
* `error`: any error that may have occurred during installation
849+
* `install_message`: optional message from the package maintainer on the installation
850+
* `success`: whether the package was installed successfully
851+
852+
Of course, you can also install multiple packages in one go using the
853+
`install_packages` method:
854+
855+
.. code-block:: python
856+
857+
import weka.core.packages as packages
858+
info = packages.install_packages([
859+
"http://some.server.com/funky-package-1.0.0.zip",
860+
"http://some.server.com/cool-package-2.0.0.zip",
861+
"http://some.server.com/fancy-package-1.1.0.zip",
862+
], fail_fast=False, details=True)
863+
864+
This method offers the `details` flag as well and returns a dictionary with
865+
the package name/URL/file name as the key and the information dictionary as
866+
the value.
867+
868+
With the `fail_fast` flag you can control whether to stop the installation process
869+
as soon as the first package fails to install (`fail_fast=True`) or keep trying to
870+
install them (`fail_fast=False`).
840871

841872
You can include automatic installation of packages in your scripts:
842873

0 commit comments

Comments
 (0)