Skip to content

Commit

Permalink
Make installations into the base env work
Browse files Browse the repository at this point in the history
Look at $CONDA_PREFIX first if no name or prefix is given. If that
is not set, only then default to sys.prefix.
  • Loading branch information
teake committed Mar 30, 2019
1 parent 49fcc5e commit 5768cc2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 26 deletions.
29 changes: 18 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,28 @@ A command-line utility to plot Conda dependency graphs.
Installation
============

It is recommended to install ``conda-depgraph`` in its own environment:
``conda-depgraph`` can be installed as follows:

.. code-block:: console
$ conda create -n depgraph -c omegacen conda-depgraph
$ conda install -c omegacen conda-depgraph
Installing it in the ``base`` environment will work, but then you'll have to
be sure that ``java`` is available in ``$PATH``.
It can either be installed into its own conda environment, or into the base
environment.

Installing it in the base environment has the benefit that the
``conda depgraph`` command is available in all other environments. However,
you will have to make sure that ``java`` is available on ``$PATH``.

Installing it in its own environment automatically ensures it can find ``java``,
but then you will have to activate that environment before you can run
``conda depgraph``.


Usage
=====

After installation and activation of the environment, a new Conda command is
available:
After installation a new Conda command is available:

.. code-block:: console
Expand All @@ -35,9 +42,9 @@ available:
[inout [--distance=<DISTANCE>] <PACKAGE>]
``depgraph`` can plot dependency graphs from either cached repository data,
or from an existing Conda environment. If the target environment is not
specified via either ``--name`` or ``--prefix``, the current environment is
used.
or from an existing Conda environment. The latter is the default behaviour. If
the target environment is not specified via either ``--name`` or ``--prefix``,
the current environment is used.

The subcommands (``in``, ``out``, ``inout``) restrict the output to a subgraph
of the full dependency graph of the environment. They can be arbitrarily nested.
Expand All @@ -50,7 +57,7 @@ The direct dependencies of conda:

.. code-block:: console
$ conda depgraph --name=base outgraph --distance=1 conda
$ conda depgraph --name=base out --distance=1 conda
::

Expand Down Expand Up @@ -80,7 +87,7 @@ The immediate neighborhood of sqlite:

.. code-block:: console
$ conda depgraph --name=base inoutgraph --distance==1 sqlite
$ conda depgraph --name=base inout --distance==1 sqlite
::

Expand Down
2 changes: 1 addition & 1 deletion conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: conda-depgraph
version: 1.0.0
version: 1.0.1

about:
home: https://github.com/omegacen/conda-depgraph
Expand Down
2 changes: 1 addition & 1 deletion src/conda_depgraph/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.0.0'
__version__ = '1.0.1'
13 changes: 5 additions & 8 deletions src/conda_depgraph/cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import functools
import sys

import click
from asciinet import graph_to_ascii

from . import algorithms
from . import conda_facade
from . import exceptions


@click.group(chain=True, invoke_without_command=True)
Expand All @@ -30,13 +30,10 @@ def main(*_, **__):
def process_subcommands(subcommands, from_where, prefix, name, output):

if from_where == 'env':
if name is not None:
prefix = conda_facade.locate_prefix_by_name(name)
if prefix is None:
msg = f"Could not find Conda environment '{name}'."
raise click.BadParameter(msg)
if prefix is None:
prefix = sys.prefix
try:
prefix = conda_facade.locate_prefix(name, prefix)
except exceptions.DepgraphValueError as e:
raise click.BadParameter(e.args)
g = conda_facade.env_graph(prefix)
else:
g = conda_facade.channelcache_graph()
Expand Down
22 changes: 17 additions & 5 deletions src/conda_depgraph/conda_facade.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import json
import os
import pathlib
import subprocess
from pathlib import Path
import sys

import conda
import conda.exports
from networkx import DiGraph
import networkx

from . import exceptions


def locate_prefix(name, prefix):
if name is not None:
prefix = locate_prefix_by_name(name)
if prefix is None:
prefix = os.environ.get('CONDA_PREFIX', sys.prefix)
return prefix


def locate_prefix_by_name(name):
Expand All @@ -25,13 +36,14 @@ def locate_prefix_by_name(name):
name=name, envs_dirs=info['envs_dirs']
)
except conda.exceptions.EnvironmentNameNotFound:
prefix = None
msg = f"Could not find Conda environment '{name}'."
raise exceptions.DepgraphValueError(msg)
return prefix


def channelcache_graph():
prefix = _conda_execute('info', '--base')
cache_dir = Path(prefix) / 'pkgs' / 'cache'
cache_dir = pathlib.Path(prefix) / 'pkgs' / 'cache'

def package_data():
for cache_file in cache_dir.glob('*.json'):
Expand All @@ -53,7 +65,7 @@ def _conda_execute(*args):


def _package_datas_to_graph(datas):
g = DiGraph()
g = networkx.DiGraph()
for data in datas:
for p in data.values():
n = p['name']
Expand Down
2 changes: 2 additions & 0 deletions src/conda_depgraph/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class DepgraphValueError(ValueError):
pass

0 comments on commit 5768cc2

Please sign in to comment.