From b9277648fc193c99e0a39f1c24e76780dcf3be33 Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Sun, 12 Feb 2023 22:00:19 +0000 Subject: [PATCH 1/3] DOC: Fixup python-api docs slightly --- docs/source/python_api.rst | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/docs/source/python_api.rst b/docs/source/python_api.rst index 98f47bd949..68e25b4b65 100644 --- a/docs/source/python_api.rst +++ b/docs/source/python_api.rst @@ -22,21 +22,21 @@ Using internal mamba APIs The core of ``mamba`` is written in C++, but we expose the internals of mamba with a Python API (using ``pybind11``). -You can import the ``mamba_api`` using ``from mamba import mamba_api``. +You can import ``libmambapy`` containing the Python API using ``from mamba.api import libmambapy``. -The mamba_api exposes the following objects: +These bindings expose the following objects (`boa_` has a full example): - ``Context``: a singleton configuration object. All global configuration goes through this. From Python you can use the context object like so: .. code:: - from mamba import mamba_api - mamba_api.Context().conda_prefix = "/home/wolfv/conda" - ctx = mamba_api.Context() + from mamba import libmambapy + libmambapy.Context().conda_prefix = "/home/wolfv/conda" + ctx = libmambapy.Context() print(ctx.root_prefix) -Here is an example usage of the mamba_api: +Here is an example usage of the libmambapy: .. code:: @@ -52,7 +52,7 @@ Here is an example usage of the mamba_api: ): check_allowlist(channel_urls) - dlist = mamba_api.DownloadTargetList() + dlist = libmambapy.DownloadTargetList() index = [] for idx, url in enumerate(channel_urls): @@ -68,12 +68,12 @@ Here is an example usage of the mamba_api: name_and_subdir = channel.subdir else: name_and_subdir = channel.name + "/" + channel.subdir - sd = mamba_api.SubdirData(name_and_subdir, full_url, full_path_cache) + sd = libmambapy.SubdirData(name_and_subdir, full_url, full_path_cache) index.append((sd, channel)) dlist.add(sd) - is_downloaded = dlist.download(mamba_api.MAMBA_DOWNLOAD_FAILFAST) + is_downloaded = dlist.download(libmambapy.MAMBA_DOWNLOAD_FAILFAST) if not is_downloaded: raise RuntimeError("Error downloading repodata.") @@ -83,21 +83,21 @@ Here is an example usage of the mamba_api: class MambaSolver: def __init__(self, prefix, channels, platform): - api_ctx = mamba_api.Context() + api_ctx = libmambapy.Context() api_ctx.conda_prefix = prefix self.channels = channels self.platform = platform self.index = get_index(channels, platform=platform) self.local_index = [] - self.pool = mamba_api.Pool() + self.pool = libmambapy.Pool() self.repos = [] start_prio = len(channels) priority = start_prio subpriority = 0 # wrong! :) for subdir, channel in self.index: - repo = mamba_api.Repo( + repo = libmambapy.Repo( self.pool, str(channel), subdir.cache_path(), @@ -122,11 +122,11 @@ Here is an example usage of the mamba_api: solvable : bool True if the set of specs has a solution, False otherwise. """ - solver_options = [(mamba_api.SOLVER_FLAG_ALLOW_DOWNGRADE, 1)] - api_solver = mamba_api.Solver(self.pool, solver_options) + solver_options = [(libmambapy.SOLVER_FLAG_ALLOW_DOWNGRADE, 1)] + api_solver = libmambapy.Solver(self.pool, solver_options) _specs = specs - api_solver.add_jobs(_specs, mamba_api.SOLVER_INSTALL) + api_solver.add_jobs(_specs, libmambapy.SOLVER_INSTALL) success = api_solver.try_solve() if not success: @@ -142,12 +142,10 @@ Here is an example usage of the mamba_api: print(error_string) exit(1) - package_cache = mamba_api.MultiPackageCache(pkgs_dirs) + package_cache = libmambapy.MultiPackageCache(pkgs_dirs) - t = mamba_api.Transaction(api_solver, package_cache) + t = libmambapy.Transaction(api_solver, package_cache) return t -Let's walk through this example: - -We first use the ``get_index`` method to download repository data from the channels. +.. _boa: https://www.github.com/mamba-org/boa/blob/main/boa/core/solver.py From 628b2b0a1cf6f5d832bad7ba701300ddff86219a Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Mon, 13 Feb 2023 09:02:43 +0000 Subject: [PATCH 2/3] DOC: Fixup imports Co-authored-by: Wolf Vollprecht --- docs/source/python_api.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/python_api.rst b/docs/source/python_api.rst index 68e25b4b65..b3569f4b09 100644 --- a/docs/source/python_api.rst +++ b/docs/source/python_api.rst @@ -22,7 +22,7 @@ Using internal mamba APIs The core of ``mamba`` is written in C++, but we expose the internals of mamba with a Python API (using ``pybind11``). -You can import ``libmambapy`` containing the Python API using ``from mamba.api import libmambapy``. +You can import ``libmambapy`` containing the Python API using ``import libmambapy`` without having ``mamba`` installed. These bindings expose the following objects (`boa_` has a full example): @@ -30,7 +30,7 @@ These bindings expose the following objects (`boa_` has a full example): .. code:: - from mamba import libmambapy + import libmambapy libmambapy.Context().conda_prefix = "/home/wolfv/conda" ctx = libmambapy.Context() print(ctx.root_prefix) From db1774b3939d1cc9eb024ee6859adfb13530d9ca Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Mon, 13 Feb 2023 09:06:24 +0000 Subject: [PATCH 3/3] DOC: Add a little more text --- docs/source/python_api.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/source/python_api.rst b/docs/source/python_api.rst index b3569f4b09..1aead11fb1 100644 --- a/docs/source/python_api.rst +++ b/docs/source/python_api.rst @@ -17,6 +17,8 @@ Mamba provides high-level Python APIs for creating environments and installing p # install(env_name, packages, channels) install('my-custom-env', ('matplotlib=3', 'ipympl'), ('conda-forge', )) +These call internal ``mamba`` APIs under the hood, which are discussed below. + Using internal mamba APIs ------------------------- @@ -147,5 +149,7 @@ Here is an example usage of the libmambapy: t = libmambapy.Transaction(api_solver, package_cache) return t +``mamba.api`` also has a default implementation of ``MambaSolver`` which can be +customized with ``Context`` objects. .. _boa: https://www.github.com/mamba-org/boa/blob/main/boa/core/solver.py