Skip to content

Commit

Permalink
Merge pull request #5 from Anaconda-Platform/fix-duplicate-python
Browse files Browse the repository at this point in the history
Rather than always putting 'python' in env, add it only if env spec i…
  • Loading branch information
havocp committed Mar 1, 2017
2 parents 9fe32db + d21984b commit 15e3965
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ install:
- conda install -y -q -c conda-forge keyring

script:
- if test "$TEST_TARGET" = tests; then LANG=en_US.UTF-8 python setup.py test; fi
- if test "$TEST_TARGET" = tests; then LANG=en_US.UTF-8 python setup.py test -a '-vv'; fi
- if test "$TRAVIS_PYTHON_VERSION" = "3.5" && test "$TEST_TARGET" = "packaging"; then
git fetch --unshallow ;
LANG=en_US.UTF-8 python setup.py conda_package ;
Expand Down
11 changes: 8 additions & 3 deletions anaconda_project/internal/default_conda_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ def fix_environment_deviations(self, prefix, spec, deviations=None, create=True)
if deviations is None:
deviations = self.find_environment_deviations(prefix, spec)

command_line_packages = set(['python']).union(set(spec.conda_packages))
command_line_packages = set(spec.conda_packages)
# conda won't let us create a completely empty environment
if len(command_line_packages) == 0:
command_line_packages = set(['python'])

if os.path.isdir(os.path.join(prefix, 'conda-meta')):
missing = deviations.missing_packages
Expand All @@ -190,7 +193,8 @@ def fix_environment_deviations(self, prefix, spec, deviations=None, create=True)
try:
conda_api.install(prefix=prefix, pkgs=specs, channels=spec.channels)
except conda_api.CondaError as e:
raise CondaManagerError("Failed to install missing packages: " + ", ".join(missing))
raise CondaManagerError("Failed to install missing packages: {}: {}".format(", ".join(missing), str(
e)))
elif create:
# Create environment from scratch
try:
Expand All @@ -208,7 +212,8 @@ def fix_environment_deviations(self, prefix, spec, deviations=None, create=True)
try:
pip_api.install(prefix=prefix, pkgs=specs)
except pip_api.PipError as e:
raise CondaManagerError("Failed to install missing pip packages: " + ", ".join(missing))
raise CondaManagerError("Failed to install missing pip packages: {}: {}".format(", ".join(missing), str(
e)))

# write a file to tell us we can short-circuit next time
self._write_timestamp_file(prefix, spec)
Expand Down
12 changes: 11 additions & 1 deletion anaconda_project/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ def overrides(self):
"""Override object which was passed to prepare()."""
return self._overrides

@property
def errors(self):
"""Get lines of error output."""
raise NotImplementedError() # pragma: no cover


class PrepareSuccess(PrepareResult):
"""Class describing the successful result of preparing the project to run."""
Expand All @@ -133,6 +138,11 @@ def command_exec_info(self):
"""``CommandExecInfo`` instance if available, None if not."""
return self._command_exec_info

@property
def errors(self):
"""Get empty list of errors."""
return []

def update_environ(self, environ):
"""Overwrite ``environ`` with any additions from the prepared environ.
Expand All @@ -156,7 +166,7 @@ def failed(self):

@property
def errors(self):
"""Get lines of error output."""
"""Get non-empty list of errors."""
return self._errors

def print_output(self):
Expand Down
25 changes: 21 additions & 4 deletions anaconda_project/test/test_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@

def test_prepare_empty_directory():
def prepare_empty(dirname):
project = project_no_dedicated_env(dirname)
project = Project(dirname)
environ = minimal_environ()
result = prepare_without_interaction(project, environ=environ)
assert result.errors == []
assert result
assert dict(PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
assert dict() == strip_environ(environ)
Expand All @@ -56,9 +57,10 @@ def prepare_bad_provide_mode(dirname):

def test_unprepare_empty_directory():
def unprepare_empty(dirname):
project = project_no_dedicated_env(dirname)
project = Project(dirname)
environ = minimal_environ()
result = prepare_without_interaction(project, environ=environ)
assert result.errors == []
assert result
status = unprepare(project, result)
assert status
Expand All @@ -83,9 +85,10 @@ def unprepare_problems(dirname):

def test_unprepare_nothing_to_do():
def unprepare_nothing(dirname):
project = project_no_dedicated_env(dirname)
project = Project(dirname)
environ = minimal_environ()
result = prepare_without_interaction(project, environ=environ)
assert result.errors == []
assert result
status = unprepare(project, result, whitelist=[])
assert status
Expand Down Expand Up @@ -113,16 +116,24 @@ def prepare_system_environ(dirname):
print("ORIGINAL PATH: " + repr(original))
print("UPDATED PATH: " + repr(updated))
assert original == updated
assert result.errors == []
assert result
assert result.environ.get(key) == os.environ.get(key)

with_directory_contents(dict(), prepare_system_environ)
with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
packages: []
"""
}, prepare_system_environ)


def test_prepare_some_env_var_already_set():
def prepare_some_env_var(dirname):
project = project_no_dedicated_env(dirname)
environ = minimal_environ(FOO='bar')
result = prepare_without_interaction(project, environ=environ)
assert result.errors == []
assert result
assert dict(FOO='bar', PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
assert dict(FOO='bar') == strip_environ(environ)
Expand Down Expand Up @@ -219,11 +230,13 @@ def check(dirname):
project = project_no_dedicated_env(dirname)
environ = minimal_environ()
result = prepare_without_interaction(project, environ=environ, command_name='foo')
assert result.errors == []
assert result
assert os.path.join(project.directory_path, 'foo.py') in result.command_exec_info.args

environ = minimal_environ()
result = prepare_without_interaction(project, environ=environ, command_name='bar')
assert result.errors == []
assert result
assert os.path.join(project.directory_path, 'bar.py') in result.command_exec_info.args

Expand All @@ -250,6 +263,7 @@ def check(dirname):
env_spec=project.default_env_spec_name))
environ = minimal_environ()
result = prepare_without_interaction(project, environ=environ, command=command)
assert result.errors == []
assert result
assert os.path.join(project.directory_path, 'foo.py') in result.command_exec_info.args

Expand Down Expand Up @@ -313,6 +327,7 @@ def check(dirname):

environ = minimal_environ()
result = prepare_without_interaction(project, environ=environ, env_spec_name='bar')
assert result.errors == []
assert result
expected_path = project.env_specs['bar'].path(project.directory_path)
assert result.environ[env_var] == expected_path
Expand Down Expand Up @@ -362,6 +377,7 @@ def prepare_then_update_environ(dirname):
project = project_no_dedicated_env(dirname)
environ = minimal_environ(FOO='bar')
result = prepare_without_interaction(project, environ=environ)
assert result.errors == []
assert result

other = minimal_environ(BAR='baz')
Expand Down Expand Up @@ -643,6 +659,7 @@ def prepare_with_browser(dirname):
project = project_no_dedicated_env(dirname)
environ = minimal_environ()
result = prepare_with_browser_ui(project, environ=environ, keep_going_until_success=False, io_loop=io_loop)
assert result.errors == []
assert result
assert dict(FOO_PASSWORD='bloop', PROJECT_DIR=project.directory_path) == strip_environ(result.environ)
assert dict() == strip_environ(environ)
Expand Down

0 comments on commit 15e3965

Please sign in to comment.