Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael McNeil Forbes committed Feb 1, 2022
1 parent 054416c commit 8c0e18d
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 113 deletions.
78 changes: 49 additions & 29 deletions anaconda_project/internal/cli/test/test_environment_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def mock_remove(path, ignore_errors=False, onerror=None):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
DEFAULT_PROJECT_FILENAME:
"""
env_specs:
foo:
channels: []
Expand All @@ -203,7 +204,8 @@ def mock_remove(path, ignore_errors=False, onerror=None):
<pkg_key>:
- bar
""".replace('<pkg_key>', pkg_key),
'envs/foo/bin/test': 'code here'
'envs/foo/bin/test':
'code here'
}, check)


Expand All @@ -221,7 +223,8 @@ def check(dirname):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
DEFAULT_PROJECT_FILENAME:
"""
env_specs:
foo:
channels: []
Expand All @@ -232,7 +235,8 @@ def check(dirname):
<pkg_key>:
- baz
""".replace('<pkg_key>', pkg_key),
'envs/foo/bin/test': 'code here'
'envs/foo/bin/test':
'code here'
}, check)


Expand All @@ -249,14 +253,16 @@ def check(dirname):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
DEFAULT_PROJECT_FILENAME:
"""
env_specs:
foo:
channels: []
<pkg_key>:
- bar
""".replace('<pkg_key>', pkg_key),
'envs/foo/bin/test': 'code here'
'envs/foo/bin/test':
'code here'
}, check)


Expand All @@ -274,7 +280,8 @@ def check(dirname):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
DEFAULT_PROJECT_FILENAME:
"""
commands:
foo:
unix: envs/foo/bin/test
Expand All @@ -288,7 +295,8 @@ def check(dirname):
<pkg_key>:
- boo
""".replace('<pkg_key>', pkg_key),
'envs/foo/bin/test': 'code here'
'envs/foo/bin/test':
'code here'
}, check)


Expand Down Expand Up @@ -316,7 +324,8 @@ def check(dirname):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
DEFAULT_PROJECT_FILENAME:
"""
env_specs:
foo:
channels: []
Expand All @@ -327,7 +336,8 @@ def check(dirname):
<pkg_key>:
- baz
""".replace('<pkg_key>', pkg_key),
'envs/foo/bin/test': 'code here'
'envs/foo/bin/test':
'code here'
}, check)


Expand All @@ -345,7 +355,8 @@ def check(dirname):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
DEFAULT_PROJECT_FILENAME:
"""
env_specs:
foo:
channels: []
Expand All @@ -356,7 +367,8 @@ def check(dirname):
<pkg_key>:
- baz
""".replace('<pkg_key>', pkg_key),
'envs/foo/bin/test': 'code here'
'envs/foo/bin/test':
'code here'
}, check)


Expand All @@ -373,7 +385,8 @@ def check(dirname):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
DEFAULT_PROJECT_FILENAME:
"""
env_specs:
foo:
channels: []
Expand All @@ -384,7 +397,8 @@ def check(dirname):
<pkg_key>:
- baz
""".replace('<pkg_key>', pkg_key),
'envs/foo/bin/test': 'code here'
'envs/foo/bin/test':
'code here'
}, check)


Expand Down Expand Up @@ -477,14 +491,12 @@ def check(dirname):
assert dict(env_spec_name='foo', packages=['a', 'b'], channels=None, pip=True) == params['kwargs']

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
{DEFAULT_PROJECT_FILENAME: """
env_specs:
foo:
<pkg_key>:
- bar
"""
}, check)
"""}, check)


def test_remove_packages_from_all_environments(capsys, monkeypatch):
Expand Down Expand Up @@ -567,14 +579,12 @@ def check(dirname):
assert dict(env_spec_name='foo', platforms=['a', 'b']) == params['kwargs']

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
{DEFAULT_PROJECT_FILENAME: """
env_specs:
foo:
<pkg_key>:
- bar
""".replace('<pkg_key>', pkg_key)
}, check)
""".replace('<pkg_key>', pkg_key)}, check)


def test_remove_platforms_from_all_environments(capsys, monkeypatch):
Expand Down Expand Up @@ -632,7 +642,8 @@ def check_list_not_empty(dirname):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
DEFAULT_PROJECT_FILENAME:
"""
env_specs:
foo:
<pkg_key>:
Expand Down Expand Up @@ -724,15 +735,24 @@ def check_list_not_empty(dirname):


def test_list_packages_from_env(capsys, pkg_key):
_test_list_packages(capsys, 'bar', '\ndjango\nhttplib\nmandatory_package\n\n',
'\nmandatory_pip_package\n\n', pkg_key=pkg_key)
_test_list_packages(capsys, 'foo', '\nflask\nmandatory_package\nrequests\n\n',
'\nmandatory_pip_package\n\n', pkg_key=pkg_key)
_test_list_packages(capsys,
'bar',
'\ndjango\nhttplib\nmandatory_package\n\n',
'\nmandatory_pip_package\n\n',
pkg_key=pkg_key)
_test_list_packages(capsys,
'foo',
'\nflask\nmandatory_package\nrequests\n\n',
'\nmandatory_pip_package\n\n',
pkg_key=pkg_key)


def test_list_packages_from_env_default(capsys, pkg_key):
_test_list_packages(capsys, None, '\nflask\nmandatory_package\nrequests\n\n',
'\nmandatory_pip_package\n\n', pkg_key=pkg_key)
_test_list_packages(capsys,
None,
'\nflask\nmandatory_package\nrequests\n\n',
'\nmandatory_pip_package\n\n',
pkg_key=pkg_key)


def test_list_packages_with_project_file_problems(capsys, monkeypatch):
Expand Down
22 changes: 14 additions & 8 deletions anaconda_project/internal/cli/test/test_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def main_redis_url(dirname):
assert "All ports from 6380 to 6449 were in use" in err


#@pytest._change_default_pkg_key
def test_prepare_command_choose_environment(capsys, monkeypatch, pkg_key):
def mock_conda_create(prefix, pkgs, channels, stdout_callback, stderr_callback):
from anaconda_project.internal.makedirs import makedirs_ok_if_exists
Expand All @@ -143,7 +142,8 @@ def check_prepare_choose_environment(dirname):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
DEFAULT_PROJECT_FILENAME:
"""
env_specs:
foo:
<pkg_key>:
Expand Down Expand Up @@ -188,7 +188,8 @@ def check_prepare_choose_environment(dirname):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
DEFAULT_PROJECT_FILENAME:
"""
env_specs:
foo:
<pkg_key>:
Expand Down Expand Up @@ -237,7 +238,8 @@ def check_prepare_choose_environment(dirname):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
DEFAULT_PROJECT_FILENAME:
"""
env_specs:
foo:
<pkg_key>:
Expand Down Expand Up @@ -282,7 +284,8 @@ def check_prepare_choose_environment(dirname):
foo_package_json = os.path.join(default_envdir, "conda-meta", "nonexistent_foo-0.1-pyNN.json")
assert os.path.isfile(foo_package_json)

with_directory_contents_completing_project_file({DEFAULT_PROJECT_FILENAME: """
with_directory_contents_completing_project_file(
{DEFAULT_PROJECT_FILENAME: """
<pkg_key>:
- nonexistent_foo
""".replace("<pkg_key>", pkg_key)}, check_prepare_choose_environment)
Expand Down Expand Up @@ -310,7 +313,8 @@ def check_prepare_choose_environment_does_not_exist(dirname):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
DEFAULT_PROJECT_FILENAME:
"""
env_specs:
foo:
<pkg_key>:
Expand Down Expand Up @@ -344,7 +348,8 @@ def check(dirname):

with_directory_contents_completing_project_file(
{
DEFAULT_PROJECT_FILENAME: """
DEFAULT_PROJECT_FILENAME:
"""
env_specs:
foo:
<pkg_key>:
Expand Down Expand Up @@ -656,7 +661,8 @@ def mock_console_input(prompt, encrypted):
""" == out
assert '' == err

with_directory_contents_completing_project_file({DEFAULT_PROJECT_FILENAME: """
with_directory_contents_completing_project_file(
{DEFAULT_PROJECT_FILENAME: """
<pkg_key>: []
weird_field: 42
""".replace("<pkg_key>", pkg_key)}, check)
11 changes: 6 additions & 5 deletions anaconda_project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ def _update_lock_sets(self, problems, lock_file):
def _update_env_specs(self, problems, project_file, lock_file):
# Should we check/set lock_file.pkg_key?
pkg_key = project_file.pkg_key

def _parse_string_list(parent_dict, key, what):
return self._parse_string_list(problems, project_file, parent_dict, key, what)

Expand Down Expand Up @@ -791,9 +791,9 @@ def set_env_spec_platforms(project):
lock_set_names.add(parsed.name)
unlocked_names = env_spec.conda_package_names_set - lock_set_names
if len(unlocked_names) > 0:
text = (f"Lock file is missing %s {lock_file.pkg_key} for env spec %s on %s (%s)" %
(len(unlocked_names), env_spec.name, platform,
",".join(sorted(list(unlocked_names)))))
text = (
f"Lock file is missing %s {lock_file.pkg_key} for env spec %s on %s (%s)" %
(len(unlocked_names), env_spec.name, platform, ",".join(sorted(list(unlocked_names)))))
problems.append(
ProjectProblem(text=text, filename=lock_file.filename, only_a_suggestion=True))

Expand Down Expand Up @@ -1206,8 +1206,9 @@ def load_default_specs():

@property
def pkg_key(self):
"""Return the project `pkg_key` - 'packages' or 'dependencies'."""
return self.project_file.pkg_key

def _updated_cache(self):
self._config_cache.update(self._project_file, self._lock_file)
return self._config_cache
Expand Down
2 changes: 1 addition & 1 deletion anaconda_project/project_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ProjectFile(YamlFile):
save in a way that conflicts with your loads and saves.
"""

template = '''
# This is an Anaconda project file.
#
Expand Down
Loading

0 comments on commit 8c0e18d

Please sign in to comment.