diff --git a/pipenv.sublime-commands b/pipenv.sublime-commands index d698beb..afac0a3 100644 --- a/pipenv.sublime-commands +++ b/pipenv.sublime-commands @@ -1,5 +1,6 @@ [ { "caption": "Pipenv: Install Package", "command": "pipenv_install" }, + { "caption": "Pipenv: Install Dev Package", "command": "pipenv_install_dev" }, { "caption": "Pipenv: Uninstall Package", "command": "pipenv_uninstall" }, { "caption": "Pipenv: Open Pipfile", "command": "pipenv_open_pipfile" }, { "caption": "Pipenv: Open Pipfile.lock", "command": "pipenv_open_pipfile_lock" }, diff --git a/subl_pipenv.py b/subl_pipenv.py index 38c8f7e..510b363 100644 --- a/subl_pipenv.py +++ b/subl_pipenv.py @@ -90,6 +90,7 @@ def list_items(self): def initial_text(self, *args): return "" + class pipenv_install(PipenvIsEnabledMixin, sublime_plugin.WindowCommand): def __init__(self, text): @@ -148,6 +149,64 @@ def run(self, install_handler): print(c.err) +class pipenv_install_dev(PipenvIsEnabledMixin, sublime_plugin.WindowCommand): + + def __init__(self, text): + super(pipenv_install_dev, self).__init__(text) + + # def is_enabled(self): + # return super(pipenv_install, self).is_enabled() + + def input(self, *args): + return InstallHandler() + + def run(self, install_handler): + # The package to install. + package = install_handler + + # The home directory for the current file name. + home = os.path.dirname(sublime.active_window().active_view().file_name()) + p = pipenvlib.PipenvProject(home) + + # Update package status. + sublime.status_message("Installing {!r} with Pipenv…".format(package)) + + # Show the console. + sublime.active_window().active_view().window().run_command('show_panel', {'panel': 'console'}) + + # Run the install command. + c = p.run('install --dev {}'.format(package), block=False) + + # Update the status bar. + sublime.status_message("Waiting for {!r} to install…".format(package)) + + # Block on subprocess… + c.block() + + # Print results to console. + print(c.out) + + # Assure that the intallation was successful. + try: + # Ensure installation was successful. + assert c.return_code == 0 + + # Update the status bar. + sublime.status_message("Success installing {!r}!".format(package)) + + # Open the Pipfile. + sublime.active_window().active_view().window().open_file('Pipfile') + + # Hide the console. + sublime.active_window().active_view().window().run_command('hide_panel', {'panel': 'console'}) + except AssertionError: + # Update the status bar. + sublime.status_message("Error installing {!r}!".format(package)) + + # Report the error. + print(c.err) + + class UninstallHandler(sublime_plugin.ListInputHandler): def __init__(self):