Skip to content

Commit

Permalink
Fix tests failures
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming committed Apr 10, 2018
1 parent 29e9b23 commit 3c0770f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
9 changes: 4 additions & 5 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2036,11 +2036,10 @@ def do_uninstall(
c = delegator.run(cmd)
click.echo(crayons.blue(c.out))
if pipfile_remove:
norm_name = pep423_name(package_name)
in_dev_packages = (
norm_name in project._pipfile.get('dev-packages', {})
)
in_packages = (norm_name in project._pipfile.get('packages', {}))
in_packages = project.get_package_name_in_pipfile(
package_name, dev=False)
in_dev_packages = project.get_package_name_in_pipfile(
package_name, dev=True)
if not in_dev_packages and not in_packages:
click.echo(
'No package {0} to remove from Pipfile.'.format(
Expand Down
34 changes: 18 additions & 16 deletions pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,17 +591,23 @@ def destroy_lockfile(self):
except OSError:
pass

def get_package_name_in_pipfile(self, package_name, dev=False):
"""Get the equivalent package name in pipfile"""
key = 'dev-packages' if dev else 'packages'
section = self.parsed_pipfile.get(key, {})
for name in section.keys():
if pep423_name(name) == pep423_name(package_name):
return name
return None

def remove_package_from_pipfile(self, package_name, dev=False):
# Read and append Pipfile.
p = self.parsed_pipfile
package_name = pep423_name(package_name)
name = self.get_package_name_in_pipfile(package_name, dev)
key = 'dev-packages' if dev else 'packages'
if key in p:
for name in dict(p[key]):
if pep423_name(name) == package_name:
del p[key][name]
# Write Pipfile.
return self.write_toml(p)
p = self.parsed_pipfile
if name:
del p[key][name]
self.write_toml(p)

def add_package_to_pipfile(self, package_name, dev=False):
# Read and append Pipfile.
Expand All @@ -619,14 +625,10 @@ def add_package_to_pipfile(self, package_name, dev=False):
p[key] = {}
package = convert_deps_from_pip(package_name)
package_name = [k for k in package.keys()][0]
for name in dict(p[key]):
# Normalize names to compare
if (
pep423_name(name) == pep423_name(package_name) and
name != package_name
):
# Replace the package name
del p[key][name]
name = self.get_package_name_in_pipfile(package_name, dev)
if name and name != package_name:
# Replace the packge name
del p[key][name]
# Add the package to the group.
p[key][package_name] = package[package_name]
# Write Pipfile.
Expand Down

0 comments on commit 3c0770f

Please sign in to comment.