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

Commit

Permalink
working
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 cc7a146 commit 08d835b
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 86 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
install:
ln -s "$(shell pwd)" ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/pipenv-sublime
open:
open ~/Library/Application\ Support/Sublime\ Text\ 3/
2 changes: 1 addition & 1 deletion dependencies.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"*": {
">=3000": [
"requests"
"requests",
"parse"
]
}
Expand Down
Empty file added package-control.cleanup
Empty file.
78 changes: 0 additions & 78 deletions pipenv.py

This file was deleted.

4 changes: 2 additions & 2 deletions pipenv.sublime-commands
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
{ "caption": "Pipenv: Install Package", "command": "pipenv_install" },
{ "caption": "Pipenv: Uninstall Package", "command": "pipenv_uninstall" }
// { "caption": "Pipenv: Install Package", "command": "pipenv_install" },
// { "caption": "Pipenv: Uninstall Package", "command": "pipenv_uninstall" }
]
129 changes: 129 additions & 0 deletions subl_pipenv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import os

import sublime
import sublime_plugin

from .vendor import requests
from .vendor import parse
from .vendor import pipenvlib


TEMPLATE = "<a href='{0}'>{0}</a><br/>"
ALL_PACKAGES = list()

def plugin_loaded():
pass

class InstallHandler(sublime_plugin.ListInputHandler):
"""docstring for ClassName"""

def __init__(self):
super(InstallHandler, self).__init__()

def _yield_packages(self):
# Set the status message.
sublime.status_message("Fetching all available packages from PyPi (just a sec!)…")

# Make the HTTP Request.
r = requests.get('https://pypi.python.org/simple/')
sublime.status_message("")

# Yield results.
for result in parse.findall(TEMPLATE, r.text):
yield result[0]

@property
def _all_packages(self):
return ALL_PACKAGES

@_all_packages.setter
def function(self, value):
global ALL_PACKAGES
ALL_PACKAGES = value

@property
def all_packages(self):
if self._all_packages:
return self._all_packages

for package in self._yield_packages():
self._all_packages.append(package)

# List special packages first, because I can.
kr_packages = (
'requests', 'requests-html', 'maya', 'records', 'httpbin', 'crayons',
'delegator.py', 'tablib', 'background', 'clint', 'xerox'
)
# Special shout-outs.
kr_favorites = ('django', 'flask', 'docopt', 'parse', 'apistar')
kr_favorites = list(kr_packages + kr_favorites)

# Reverse order.
kr_favorites.reverse()

for kr_package in kr_favorites:
package = self._all_packages.pop(self._all_packages.index(kr_package))
self._all_packages.insert(0, package)

return self._all_packages

def list_items(self):
return self.all_packages

def next_input(self, *args):
return None

def placeholder(self):
# return "package-name"
pass

def description(self, *args):
# return "Package to install."
pass


class pipenv_install(sublime_plugin.WindowCommand):
"""docstring for PipenvMenu"""

def __init__(self, text):
super(pipenv_install, self).__init__(text)

def is_enabled(self):
return True

def description(self):
return "Pipenv is awesome"

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))

sublime.run_command('show_panel', {'panel': 'console'})
print()
c = p._run('install {}'.format(package))
# sublime.status_message("Waiting for {!r} to install…".format(package))
# c.block()

assert c.return_code == 0
sublime.status_message("Success installing {!r}!".format(package))

sublime.active_window().active_view().window().open_file('Pipfile')
# sublime.open('Pipfile')
# Show a new window.


# Print the output of the installation.


if sublime.version() < '3000':
plugin_loaded()
10 changes: 5 additions & 5 deletions vendor/pipenvlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ def gen():

return [l for l in gen()]

def _run(self, cmd):
def run(self, cmd, block=True):
"""Run a Pipenv command for the Pipenv project."""
return delegator.run('pipenv {0}'.format(cmd), cwd=self.home)
return delegator.run('pipenv {0}'.format(cmd), cwd=self.home, block=block)

def install(self, package_name, constraint=None, dev=False):
"""Installs a given package to the Pipenv project."""
Expand All @@ -185,12 +185,12 @@ def install(self, package_name, constraint=None, dev=False):
def uninstall(self, package_name):
"""Uninstalls a given package from the Pipenv project."""

return self._run('uninstall {0}'.format(package_name)).return_code == 0
return self.run('uninstall {0}'.format(package_name)).return_code == 0

def check(self):
"""Runs Pipenv check on the Pipenv project."""
return self._run('check').return_code == 0
return self.run('check').return_code == 0

@property
def virtualenv_location(self):
return self._run('--venv').out.strip()
return self.run('--venv').out.strip()

0 comments on commit 08d835b

Please sign in to comment.