Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
install --dev
Browse files Browse the repository at this point in the history
Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
  • Loading branch information
kennethreitz committed Mar 9, 2018
1 parent 0ef763c commit c419e03
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions pipenv.sublime-commands
Original file line number Diff line number Diff line change
@@ -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" },
Expand Down
59 changes: 59 additions & 0 deletions subl_pipenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c419e03

Please sign in to comment.