Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 337: Added pkg_key to ensure 'packages' == 'dependencies' #359

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Here's how to work on the code:
specific versions, or the warnings and errors may have changed
which will make tests fail. The simplest way to get the right
environment is `conda env create environment.yml` but you can
also look in that file and/or .travis.yml/appveyor.xml to see
also look in that file and/or `.travis.yml/appveyor.xml` to see
which packages are neded and then create the dev environment
by hand as you see fit.
* NOTE: Do make sure to respect the version pins found in the
Expand Down
8 changes: 4 additions & 4 deletions anaconda_project/conda_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from copy import deepcopy
import difflib

from anaconda_project.yaml_file import (_CommentedMap, _CommentedSeq, _block_style_all_nodes)
from anaconda_project.yaml_file import (_CommentedMap, _CommentedSeq, _block_style_all_nodes, YamlFile)
from anaconda_project.internal.metaclass import with_metaclass
from anaconda_project.internal import conda_api
from anaconda_project.internal import pip_api
Expand Down Expand Up @@ -394,7 +394,7 @@ def diff_from(self, old):
packages_diff.extend(map(lambda x: x, diff))

if packages_diff:
packages_diff = [' packages:'] + packages_diff
packages_diff = [f' {YamlFile.pkg_key}:'] + packages_diff

if old is None:
old_platforms = []
Expand Down Expand Up @@ -442,7 +442,7 @@ def supports_current_platform(self):
"""Whether we have locked deps for the current platform."""
return self.enabled and conda_api.current_platform() in self.platforms

def to_json(self):
def to_json(self, pkg_key=YamlFile.pkg_key):
"""JSON/YAML version of the lock set."""
yaml_dict = _CommentedMap()

Expand All @@ -462,7 +462,7 @@ def to_json(self):
for package in self._package_specs_by_platform[platform]:
packages.append(package)
packages_dict[platform] = packages
yaml_dict['packages'] = packages_dict
yaml_dict[pkg_key] = packages_dict

_block_style_all_nodes(yaml_dict)
return yaml_dict
13 changes: 9 additions & 4 deletions anaconda_project/env_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from anaconda_project.internal.py2_compat import is_string
from anaconda_project import conda_manager

from anaconda_project.yaml_file import _load_string, _save_file, _YAMLError, ryaml
from anaconda_project.yaml_file import _load_string, _save_file, _YAMLError, ryaml, YamlFile


class EnvSpec(object):
Expand Down Expand Up @@ -390,7 +390,7 @@ def filter_context(items):

return True

def to_json(self):
def to_json(self, pkg_key=YamlFile.pkg_key):
"""Get JSON for an anaconda-project.yml env spec section."""
# Note that we use _conda_packages (only the packages we
# introduce ourselves) rather than conda_packages
Expand All @@ -406,14 +406,19 @@ def to_json(self):
# have ordering... OrderedDict doesn't work because the
# yaml saver saves them as some "!!omap" nonsense. Other
# than ordering, the formatting isn't even preserved here.
template_json = ryaml.load("something:\n description: null\n" + " packages: []\n" + " channels: []\n",
template_json = ryaml.load("""
something:
description: null
<pkg_key>: []
channels: []
""".replace('<pkg_key>', pkg_key),
Loader=ryaml.RoundTripLoader)

if self._description is not None:
template_json['something']['description'] = self._description
else:
del template_json['something']['description']
template_json['something']['packages'] = packages
template_json['something'][pkg_key] = packages
template_json['something']['channels'] = channels

# usually "platforms" will be global so don't clutter
Expand Down
20 changes: 10 additions & 10 deletions anaconda_project/internal/cli/test/test_command_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def mock_console_input(prompt):
with_directory_contents_completing_project_file({DEFAULT_PROJECT_FILENAME: ''}, check_ask_type)


def test_add_command_specifying_notebook(monkeypatch, capsys):
def test_add_command_specifying_notebook(monkeypatch, capsys, pkg_key):
def check_specifying_notebook(dirname):
args = Args('notebook', 'test', 'file.ipynb', directory=dirname)
res = main(args)
Expand All @@ -206,11 +206,11 @@ def check_specifying_notebook(dirname):
assert command['env_spec'] == 'default'
assert len(command.keys()) == 2

with_directory_contents_completing_project_file({DEFAULT_PROJECT_FILENAME: 'packages:\n - notebook\n'},
with_directory_contents_completing_project_file({DEFAULT_PROJECT_FILENAME: f'{pkg_key}:\n - notebook\n'},
check_specifying_notebook)


def test_add_command_guessing_notebook(monkeypatch, capsys):
def test_add_command_guessing_notebook(monkeypatch, capsys, pkg_key):
def check_guessing_notebook(dirname):
args = Args(None, 'test', 'file.ipynb', directory=dirname)
res = main(args)
Expand All @@ -225,7 +225,7 @@ def check_guessing_notebook(dirname):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: 'packages:\n - notebook\n',
DEFAULT_PROJECT_FILENAME: f'{pkg_key}:\n - notebook\n',
'file.ipynb': "{}"
}, check_guessing_notebook)

Expand Down Expand Up @@ -332,7 +332,7 @@ def test_remove_command_with_project_file_problems(capsys, monkeypatch):
append_dir=True)


def test_remove_command(monkeypatch, capsys):
def test_remove_command(monkeypatch, capsys, pkg_key):
def check(dirname):
code = _parse_args_and_run_subcommand(['anaconda-project', 'remove-command', 'test', '--directory', dirname])
assert code == 0
Expand All @@ -347,7 +347,7 @@ def check(dirname):
assert err == ''

with_directory_contents_completing_project_file(
{DEFAULT_PROJECT_FILENAME: 'packages: ["notebook"]\ncommands:\n test:\n notebook: file.ipynb\n'}, check)
{DEFAULT_PROJECT_FILENAME: f'{pkg_key}: ["notebook"]\ncommands:\n test:\n notebook: file.ipynb\n'}, check)


def test_remove_command_missing(monkeypatch, capsys):
Expand Down Expand Up @@ -378,7 +378,7 @@ def check_empty_project(dirname):
with_directory_contents_completing_project_file({DEFAULT_PROJECT_FILENAME: ""}, check_empty_project)


def test_list_commands(capsys):
def test_list_commands(capsys, pkg_key):
def check_empty_project(dirname):
code = _parse_args_and_run_subcommand(['anaconda-project', 'list-commands', '--directory', dirname])
assert code == 0
Expand All @@ -404,13 +404,13 @@ def check_empty_project(dirname):
" bokeh_app: test.py\n"
" run_notebook:\n"
" notebook: test.ipynb\n"
"packages:\n"
f"{pkg_key}:\n"
" - bokeh\n"
" - notebook\n")
}, check_empty_project)


def test_list_default_command(capsys):
def test_list_default_command(capsys, pkg_key):
def check_empty_project(dirname):
code = _parse_args_and_run_subcommand(['anaconda-project', 'list-default-command', '--directory', dirname])
assert code == 0
Expand All @@ -426,7 +426,7 @@ def check_empty_project(dirname):
" bokeh_app: test.py\n"
" 0second:\n"
" notebook: test.ipynb\n"
"packages:\n"
f"{pkg_key}:\n"
" - bokeh\n"
" - notebook\n")
}, check_empty_project)
Expand Down
Loading