mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
refactor
This commit is contained in:
+2
-80
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
Reference in New Issue
Block a user