Skip to content
This repository has been archived by the owner on Jan 30, 2019. It is now read-only.

fix for export outside of default env path #272

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions conda_env/cli/main_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from conda.cli import common

from ..env import from_environment
from conda.config import default_prefix

description = """
Export a given environment
Expand Down Expand Up @@ -47,6 +48,12 @@ def configure_parser(sub_parsers):
help='name of environment (in %s)' % os.pathsep.join(config.envs_dirs),
default=None,
)
p.add_argument(
'-p', "--prefix",
action="store",
help="Full path to environment prefix (default: %s)." % default_prefix,
metavar='PATH',
)

p.add_argument(
'-f', '--file',
Expand All @@ -67,23 +74,33 @@ def configure_parser(sub_parsers):

# TODO Make this aware of channels that were used to install packages
def execute(args, parser):

if args.prefix:
prefix = os.path.abspath(args.prefix)
else:
prefix = common.get_prefix(args)

if not args.name:
# Note, this is a hack fofr get_prefix that assumes argparse results
# TODO Refactor common.get_prefix
name = os.environ.get('CONDA_DEFAULT_ENV', False)
if not name:

if args.prefix:
name = os.path.basename(prefix)
elif not name:
msg = "Unable to determine environment\n\n"
msg += textwrap.dedent("""
Please re-run this command with one of the following options:

* Provide an environment name via --name or -n
* Alternately, provide an environment path via --prefix or -p
* Re-run this command inside an activated conda environment.""").lstrip()
# TODO Add json support
common.error_and_exit(msg, json=False)
args.name = name
else:
name = args.name
prefix = common.get_prefix(args)

env = from_environment(name, prefix, no_builds=args.no_builds)

if args.override_channels:
Expand Down