mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
simplifying writes
This commit is contained in:
+1
-1
@@ -103,7 +103,7 @@ def ensure_pipfile(validate=True):
|
||||
# Write changes out to disk.
|
||||
if changed:
|
||||
click.echo(crayons.yellow('Fixing package names in Pipfile...'), err=True)
|
||||
project.write(p)
|
||||
project.write_toml(p)
|
||||
|
||||
|
||||
def ensure_virtualenv(three=None, python=None):
|
||||
|
||||
+7
-15
@@ -96,7 +96,6 @@ class Project(object):
|
||||
@property
|
||||
def parsed_pipfile(self):
|
||||
with open(self.pipfile_location, 'r') as f:
|
||||
# return toml.load(f)
|
||||
return toml.load(f, _dict=OrderedDict)
|
||||
|
||||
@property
|
||||
@@ -114,12 +113,12 @@ class Project(object):
|
||||
|
||||
def create_pipfile(self):
|
||||
data = {u'source': [{u'url': u'https://pypi.python.org/simple', u'verify_ssl': True}], u'packages': {}, 'dev-packages': {}}
|
||||
with open('Pipfile', 'w') as f:
|
||||
f.write(toml.dumps(data))
|
||||
self.write_toml(data, 'Pipfile')
|
||||
|
||||
def write(self, data):
|
||||
# format TOML data.
|
||||
with open(self.pipfile_location, 'w') as f:
|
||||
def write_toml(self, data, path=None):
|
||||
if path is None:
|
||||
path = self.pipfile_location
|
||||
with open(path, 'w') as f:
|
||||
f.write(format_toml(toml.dumps(data)))
|
||||
|
||||
@property
|
||||
@@ -147,15 +146,10 @@ class Project(object):
|
||||
del p[key][package_name]
|
||||
|
||||
# Write Pipfile.
|
||||
data = format_toml(toml.dumps(p))
|
||||
with open(pipfile_path, 'w') as f:
|
||||
f.write(data)
|
||||
self.write_toml(p)
|
||||
|
||||
def add_package_to_pipfile(self, package_name, dev=False):
|
||||
|
||||
# Find the Pipfile.
|
||||
pipfile_path = pipfile.Pipfile.find()
|
||||
|
||||
# Read and append Pipfile.
|
||||
p = self.parsed_pipfile
|
||||
|
||||
@@ -172,6 +166,4 @@ class Project(object):
|
||||
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)
|
||||
self.write_toml(p)
|
||||
|
||||
Reference in New Issue
Block a user