Skip to content

Commit

Permalink
Merge pull request #65 from Anaconda-Platform/move-cli
Browse files Browse the repository at this point in the history
Move cli to an internal package for clarity
  • Loading branch information
havocp committed May 17, 2017
2 parents d74b2a1 + 0673718 commit 6aefb9c
Show file tree
Hide file tree
Showing 41 changed files with 134 additions and 122 deletions.
12 changes: 12 additions & 0 deletions anaconda_project/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# ----------------------------------------------------------------------------
# Copyright © 2016, Continuum Analytics, Inc. All rights reserved.
#
# The full license is in the file LICENSE.txt, distributed with this software.
# ----------------------------------------------------------------------------
"""The ``main`` function chooses and runs a subcommand."""
from __future__ import absolute_import, print_function

# the point of this file is to make the internal main() into a public
# entry point.
from anaconda_project.internal.cli.main import main # noqa: F401
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
except ImportError: # pragma: no cover (py2 only)
from pipes import quote

from anaconda_project.commands.prepare_with_mode import prepare_with_ui_mode_printing_errors
from anaconda_project.commands.project_load import load_project
from anaconda_project.internal.cli.prepare_with_mode import prepare_with_ui_mode_printing_errors
from anaconda_project.internal.cli.project_load import load_project


def activate(dirname, ui_mode, conda_environment, command_name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"""The ``archive`` command makes an archive of the project."""
from __future__ import absolute_import, print_function

from anaconda_project.commands.project_load import load_project
from anaconda_project.commands import console_utils
from anaconda_project.internal.cli.project_load import load_project
from anaconda_project.internal.cli import console_utils
import anaconda_project.project_ops as project_ops


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import sys

import anaconda_project.commands.console_utils as console_utils
import anaconda_project.internal.cli.console_utils as console_utils
from anaconda_project.internal.slugify import slugify


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"""The ``clean`` command removes generated state."""
from __future__ import absolute_import, print_function

from anaconda_project.commands.project_load import load_project
from anaconda_project.internal.cli.project_load import load_project
from anaconda_project.prepare import prepare_without_interaction
from anaconda_project.provide import PROVIDE_MODE_CHECK
from anaconda_project.commands import console_utils
from anaconda_project.internal.cli import console_utils
import anaconda_project.project_ops as project_ops


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import platform
import sys

from anaconda_project.commands.project_load import load_project
from anaconda_project.internal.cli.project_load import load_project
from anaconda_project import project_ops
from anaconda_project.commands import console_utils
from anaconda_project.internal.cli import console_utils


def _ask_command(command):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import sys

from anaconda_project.commands.project_load import load_project
from anaconda_project.internal.cli.project_load import load_project
from anaconda_project import project_ops
from anaconda_project.commands import console_utils
from anaconda_project.internal.cli import console_utils
from anaconda_project.prepare import prepare_without_interaction
from anaconda_project.provide import PROVIDE_MODE_CHECK

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import sys

from anaconda_project.commands.project_load import load_project
from anaconda_project.internal.cli.project_load import load_project
from anaconda_project import project_ops
from anaconda_project.commands import console_utils
from anaconda_project.internal.cli import console_utils


def _handle_status(status, success_message=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import os

from anaconda_project import project_ops
from anaconda_project.commands.console_utils import (print_project_problems, console_ask_yes_or_no)
from anaconda_project.internal.cli.console_utils import (print_project_problems, console_ask_yes_or_no)


def init_command(project_dir, assume_yes):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@
import sys
from argparse import ArgumentParser, REMAINDER

from anaconda_project.commands.prepare_with_mode import (UI_MODE_TEXT_ASK_QUESTIONS,
UI_MODE_TEXT_DEVELOPMENT_DEFAULTS_OR_ASK, _all_ui_modes)
from anaconda_project.internal.cli.prepare_with_mode import (UI_MODE_TEXT_ASK_QUESTIONS,
UI_MODE_TEXT_DEVELOPMENT_DEFAULTS_OR_ASK, _all_ui_modes)
from anaconda_project.version import version
from anaconda_project.verbose import push_verbose_logger, pop_verbose_logger
from anaconda_project.project import ALL_COMMAND_TYPES
from anaconda_project.plugins.registry import PluginRegistry
from anaconda_project.plugins.requirements.download import _hash_algorithms
import anaconda_project
from anaconda_project.commands.bug_handler import handle_bugs
import anaconda_project.commands.init as init
import anaconda_project.commands.run as run
import anaconda_project.commands.prepare as prepare
import anaconda_project.commands.clean as clean
import anaconda_project.commands.archive as archive
import anaconda_project.commands.unarchive as unarchive
import anaconda_project.commands.upload as upload
import anaconda_project.commands.activate as activate
import anaconda_project.commands.variable_commands as variable_commands
import anaconda_project.commands.download_commands as download_commands
import anaconda_project.commands.service_commands as service_commands
import anaconda_project.commands.environment_commands as environment_commands
import anaconda_project.commands.command_commands as command_commands
from anaconda_project.internal.cli.bug_handler import handle_bugs
import anaconda_project.internal.cli.init as init
import anaconda_project.internal.cli.run as run
import anaconda_project.internal.cli.prepare as prepare
import anaconda_project.internal.cli.clean as clean
import anaconda_project.internal.cli.archive as archive
import anaconda_project.internal.cli.unarchive as unarchive
import anaconda_project.internal.cli.upload as upload
import anaconda_project.internal.cli.activate as activate
import anaconda_project.internal.cli.variable_commands as variable_commands
import anaconda_project.internal.cli.download_commands as download_commands
import anaconda_project.internal.cli.service_commands as service_commands
import anaconda_project.internal.cli.environment_commands as environment_commands
import anaconda_project.internal.cli.command_commands as command_commands


def _parse_args_and_run_subcommand(argv):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"""The ``prepare`` command configures a project to run, asking the user questions if necessary."""
from __future__ import absolute_import, print_function

from anaconda_project.commands.prepare_with_mode import prepare_with_ui_mode_printing_errors
from anaconda_project.commands.project_load import load_project
from anaconda_project.internal.cli.prepare_with_mode import prepare_with_ui_mode_printing_errors
from anaconda_project.internal.cli.project_load import load_project


def prepare_command(project_dir, ui_mode, conda_environment, command_name):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from anaconda_project.provide import (PROVIDE_MODE_PRODUCTION, PROVIDE_MODE_DEVELOPMENT, PROVIDE_MODE_CHECK)

import anaconda_project.commands.console_utils as console_utils
import anaconda_project.internal.cli.console_utils as console_utils

# these UI_MODE_ strings are used as values for command line options, so they are user-visible

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from anaconda_project.project import Project

import anaconda_project.commands.console_utils as console_utils
import anaconda_project.internal.cli.console_utils as console_utils


def load_project(dirname):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

import sys

from anaconda_project.commands.prepare_with_mode import prepare_with_ui_mode_printing_errors
from anaconda_project.commands.project_load import load_project
from anaconda_project.internal.cli.prepare_with_mode import prepare_with_ui_mode_printing_errors
from anaconda_project.internal.cli.project_load import load_project
from anaconda_project.project_commands import ProjectCommand


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"""Commands related to the downloads section."""
from __future__ import absolute_import, print_function

from anaconda_project.commands.project_load import load_project
from anaconda_project.internal.cli.project_load import load_project
from anaconda_project import project_ops
from anaconda_project.commands import console_utils
from anaconda_project.internal.cli import console_utils
from anaconda_project.prepare import prepare_without_interaction
from anaconda_project.provide import PROVIDE_MODE_CHECK

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

import platform

from anaconda_project.commands.main import _parse_args_and_run_subcommand
from anaconda_project.commands.activate import activate, main
from anaconda_project.commands.prepare_with_mode import UI_MODE_TEXT_ASSUME_YES_DEVELOPMENT
from anaconda_project.internal.cli.main import _parse_args_and_run_subcommand
from anaconda_project.internal.cli.activate import activate, main
from anaconda_project.internal.cli.prepare_with_mode import UI_MODE_TEXT_ASSUME_YES_DEVELOPMENT
from anaconda_project.internal.test.tmpfile_utils import with_directory_contents_completing_project_file
from anaconda_project.project_file import DEFAULT_PROJECT_FILENAME
from anaconda_project.local_state_file import DEFAULT_LOCAL_STATE_FILENAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import os
import pytest

from anaconda_project.commands.bug_handler import handle_bugs
from anaconda_project.internal.cli.bug_handler import handle_bugs


def test_no_bug_happens(capsys):
Expand All @@ -31,7 +31,7 @@ def test_bug_handling(capsys, monkeypatch):
def mock_is_interactive():
return True

monkeypatch.setattr('anaconda_project.commands.console_utils.stdin_is_interactive', mock_is_interactive)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.stdin_is_interactive', mock_is_interactive)

def buggy_main():
raise AssertionError("It did not work")
Expand Down Expand Up @@ -77,7 +77,7 @@ def test_bug_handling_not_interactive(capsys, monkeypatch):
def mock_is_interactive():
return False

monkeypatch.setattr('anaconda_project.commands.console_utils.stdin_is_interactive', mock_is_interactive)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.stdin_is_interactive', mock_is_interactive)

def buggy_main():
raise AssertionError("It did not work")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
import zipfile

from anaconda_project.commands.main import _parse_args_and_run_subcommand
from anaconda_project.internal.cli.main import _parse_args_and_run_subcommand
from anaconda_project.internal.test.tmpfile_utils import (with_directory_contents,
with_directory_contents_completing_project_file)
from anaconda_project.project_file import DEFAULT_PROJECT_FILENAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, print_function

from anaconda_project.commands.main import _parse_args_and_run_subcommand
from anaconda_project.internal.cli.main import _parse_args_and_run_subcommand
from anaconda_project.internal.test.tmpfile_utils import with_directory_contents_completing_project_file
from anaconda_project.project_file import DEFAULT_PROJECT_FILENAME

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import pytest

from anaconda_project.commands.command_commands import main
from anaconda_project.commands.main import _parse_args_and_run_subcommand
from anaconda_project.internal.cli.command_commands import main
from anaconda_project.internal.cli.main import _parse_args_and_run_subcommand
from anaconda_project.internal.test.tmpfile_utils import with_directory_contents_completing_project_file
from anaconda_project.project_file import DEFAULT_PROJECT_FILENAME
from anaconda_project.project import Project
Expand All @@ -30,12 +30,12 @@ def check_ask_type(dirname):
def mock_is_interactive():
return True

monkeypatch.setattr('anaconda_project.commands.console_utils.stdin_is_interactive', mock_is_interactive)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.stdin_is_interactive', mock_is_interactive)

def mock_console_input(prompt):
return "b"

monkeypatch.setattr('anaconda_project.commands.console_utils.console_input', mock_console_input)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.console_input', mock_console_input)

args = Args(None, 'test', 'file.py', directory=dirname)
res = main(args)
Expand All @@ -56,7 +56,7 @@ def check(dirname):
def mock_is_interactive():
return False

monkeypatch.setattr('anaconda_project.commands.console_utils.stdin_is_interactive', mock_is_interactive)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.stdin_is_interactive', mock_is_interactive)

args = Args(None, 'test', 'file.py', directory=dirname)
res = main(args)
Expand All @@ -74,12 +74,12 @@ def check_ask_type(dirname):
def mock_is_interactive():
return True

monkeypatch.setattr('anaconda_project.commands.console_utils.stdin_is_interactive', mock_is_interactive)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.stdin_is_interactive', mock_is_interactive)

def mock_input(prompt):
raise KeyboardInterrupt('^C')

monkeypatch.setattr('anaconda_project.commands.console_utils._input', mock_input)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils._input', mock_input)

args = Args(None, 'test', 'file.py', directory=dirname)
with pytest.raises(SystemExit) as excinfo:
Expand All @@ -98,12 +98,12 @@ def check(dirname):
def mock_is_interactive():
return True

monkeypatch.setattr('anaconda_project.commands.console_utils.stdin_is_interactive', mock_is_interactive)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.stdin_is_interactive', mock_is_interactive)

def mock_console_input(prompt):
return "c"

monkeypatch.setattr('anaconda_project.commands.console_utils.console_input', mock_console_input)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.console_input', mock_console_input)

def mock_system():
return "Linux"
Expand All @@ -129,12 +129,12 @@ def check(dirname):
def mock_is_interactive():
return True

monkeypatch.setattr('anaconda_project.commands.console_utils.stdin_is_interactive', mock_is_interactive)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.stdin_is_interactive', mock_is_interactive)

def mock_console_input(prompt):
return "c"

monkeypatch.setattr('anaconda_project.commands.console_utils.console_input', mock_console_input)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.console_input', mock_console_input)

def mock_system():
return "Windows"
Expand All @@ -160,7 +160,7 @@ def check_ask_type(dirname):
def mock_is_interactive():
return True

monkeypatch.setattr('anaconda_project.commands.console_utils.stdin_is_interactive', mock_is_interactive)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.stdin_is_interactive', mock_is_interactive)

calls = []

Expand All @@ -169,7 +169,7 @@ def mock_console_input(prompt):
calls.append(True)
return res

monkeypatch.setattr('anaconda_project.commands.console_utils.console_input', mock_console_input)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.console_input', mock_console_input)

args = Args(None, 'test', 'file.py', directory=dirname)
res = main(args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import sys

import anaconda_project.commands.console_utils as console_utils
import anaconda_project.internal.cli.console_utils as console_utils


def test_stdin_is_interactive(monkeypatch):
Expand All @@ -32,7 +32,7 @@ def mock_input(prompt):
else:
return item

monkeypatch.setattr('anaconda_project.commands.console_utils._input', mock_input)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils._input', mock_input)


def _monkeypatch_getpass(monkeypatch, answer):
Expand All @@ -59,7 +59,7 @@ def mock_isatty_true():
return True

# python 2 can throw a "readonly" error if you try to patch sys.stdin.isatty itself
monkeypatch.setattr('anaconda_project.commands.console_utils.stdin_is_interactive', mock_isatty_true)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.stdin_is_interactive', mock_isatty_true)

for answer in ("y", "Y", "yes", "Yes", "YES", "yoyo"):
_monkeypatch_input(monkeypatch, answer)
Expand Down Expand Up @@ -113,7 +113,7 @@ def mock_isatty_true():
return True

# python 2 can throw a "readonly" error if you try to patch sys.stdin.isatty itself
monkeypatch.setattr('anaconda_project.commands.console_utils.stdin_is_interactive', mock_isatty_true)
monkeypatch.setattr('anaconda_project.internal.cli.console_utils.stdin_is_interactive', mock_isatty_true)

_monkeypatch_getpass(monkeypatch, "s3kr3t")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import os

from anaconda_project.commands.main import _parse_args_and_run_subcommand
from anaconda_project.internal.cli.main import _parse_args_and_run_subcommand
from anaconda_project.internal.test.tmpfile_utils import with_directory_contents_completing_project_file
from anaconda_project.project import Project
from anaconda_project.project_file import DEFAULT_PROJECT_FILENAME
Expand Down

0 comments on commit 6aefb9c

Please sign in to comment.