This commit is contained in:
2017-01-21 14:28:06 -05:00
parent 479c5c0463
commit 8ee5213bca
2 changed files with 84 additions and 80 deletions
+2 -80
View File
@@ -10,91 +10,13 @@ import pexpect
import toml
import _pipfile as pipfile
from .project import Project
__version__ = '0.1.4'
class Project(object):
"""docstring for Project"""
def __init__(self):
super(Project, self).__init__()
@property
def name(self):
return self.pipfile_location.split(os.sep)[-2]
@property
def pipfile_exists(self):
return bool(self.pipfile_location)
@property
def virtualenv_location(self):
return os.sep.join(self.pipfile_location.split(os.sep)[:-1] + ['.venv'])
@property
def pipfile_location(self):
try:
return pipfile.Pipfile.find()
except RuntimeError:
return None
@property
def lockfile_location(self):
return '{}.lock'.format(self.pipfile_location)
@property
def lockfile_exists(self):
return os.path.isfile(self.lockfile_location)
def create_pipfile(self):
data = {u'source': [{u'url': u'https://pypi.org/', u'verify_ssl': True}], u'packages': {}, 'dev-packages': {}}
with open('Pipfile', 'w') as f:
f.write(toml.dumps(data))
@staticmethod
def remove_package_from_pipfile(package_name, dev=False):
pipfile_path = pipfile.Pipfile.find()
# Read and append Pipfile.
with open(pipfile_path, 'r') as f:
p = toml.loads(f.read())
key = 'dev-packages' if dev else 'packages'
if package_name in p[key]:
del p[key][package_name]
# Write Pipfile.
data = format_toml(toml.dumps(p))
with open(pipfile_path, 'w') as f:
f.write(data)
@staticmethod
def add_package_to_pipfile(package_name, dev=False):
pipfile_path = pipfile.Pipfile.find()
# Read and append Pipfile.
with open(pipfile_path, 'r') as f:
p = toml.loads(f.read())
key = 'dev-packages' if dev else 'packages'
# Set empty group if it doesn't exist yet.
if key not in p:
p[key] = {}
package = convert_deps_from_pip(package_name)
package_name = package.keys()[0]
# Add the package to the group.
p[key][package_name] = package[package_name]
# Write Pipfile.
data = format_toml(toml.dumps(p))
with open(pipfile_path, 'w') as f:
f.write(data)
project = Project()
def ensure_latest_pip():
# Ensure that pip is installed.
+82
View File
@@ -0,0 +1,82 @@
import os
import _pipfile as pipfile
class Project(object):
"""docstring for Project"""
def __init__(self):
super(Project, self).__init__()
@property
def name(self):
return self.pipfile_location.split(os.sep)[-2]
@property
def pipfile_exists(self):
return bool(self.pipfile_location)
@property
def virtualenv_location(self):
return os.sep.join(self.pipfile_location.split(os.sep)[:-1] + ['.venv'])
@property
def pipfile_location(self):
try:
return pipfile.Pipfile.find()
except RuntimeError:
return None
@property
def lockfile_location(self):
return '{}.lock'.format(self.pipfile_location)
@property
def lockfile_exists(self):
return os.path.isfile(self.lockfile_location)
def create_pipfile(self):
data = {u'source': [{u'url': u'https://pypi.org/', u'verify_ssl': True}], u'packages': {}, 'dev-packages': {}}
with open('Pipfile', 'w') as f:
f.write(toml.dumps(data))
@staticmethod
def remove_package_from_pipfile(package_name, dev=False):
pipfile_path = pipfile.Pipfile.find()
# Read and append Pipfile.
with open(pipfile_path, 'r') as f:
p = toml.loads(f.read())
key = 'dev-packages' if dev else 'packages'
if package_name in p[key]:
del p[key][package_name]
# Write Pipfile.
data = format_toml(toml.dumps(p))
with open(pipfile_path, 'w') as f:
f.write(data)
@staticmethod
def add_package_to_pipfile(package_name, dev=False):
pipfile_path = pipfile.Pipfile.find()
# Read and append Pipfile.
with open(pipfile_path, 'r') as f:
p = toml.loads(f.read())
key = 'dev-packages' if dev else 'packages'
# Set empty group if it doesn't exist yet.
if key not in p:
p[key] = {}
package = convert_deps_from_pip(package_name)
package_name = package.keys()[0]
# Add the package to the group.
p[key][package_name] = package[package_name]
# Write Pipfile.
data = format_toml(toml.dumps(p))
with open(pipfile_path, 'w') as f:
f.write(data)