Skip to content

Commit

Permalink
Complete replacement of packages with <pkg_key>.
Browse files Browse the repository at this point in the history
API change: to_json(pkg_key) now take this argument.
  • Loading branch information
Michael McNeil Forbes committed Feb 1, 2022
1 parent 9d22538 commit 054416c
Show file tree
Hide file tree
Showing 14 changed files with 575 additions and 492 deletions.
4 changes: 2 additions & 2 deletions anaconda_project/conda_manager.py
Original file line number Diff line number Diff line change
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[YamlFile.pkg_key] = packages_dict
yaml_dict[pkg_key] = packages_dict

_block_style_all_nodes(yaml_dict)
return yaml_dict
8 changes: 3 additions & 5 deletions anaconda_project/env_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,8 @@ 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."""
pkg_key = YamlFile.pkg_key

# Note that we use _conda_packages (only the packages we
# introduce ourselves) rather than conda_packages
# (includes inherited packages).
Expand All @@ -411,9 +409,9 @@ def to_json(self):
template_json = ryaml.load("""
something:
description: null
packages: []
<pkg_key>: []
channels: []
""".replace('packages', pkg_key),
""".replace('<pkg_key>', pkg_key),
Loader=ryaml.RoundTripLoader)

if self._description is not None:
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

0 comments on commit 054416c

Please sign in to comment.