cache proper names, for speed

This commit is contained in:
2017-01-27 22:59:21 -05:00
parent 7bc12384d2
commit 6a184a74cf
2 changed files with 29 additions and 1 deletions
+10 -1
View File
@@ -515,6 +515,10 @@ def which_pip(allow_global=False):
def proper_case(package_name):
# Skip checking proper-case if it's already a good name.
if package_name in project.proper_names:
return package_name
# Capture tag contents here.
collected = []
@@ -535,7 +539,12 @@ def proper_case(package_name):
parser.feed(r.text)
r = parse.parse('Links for {name}', collected[1])
return r['name'].strip()
good_name = r['name'].strip()
# Register the good name for future reference.
project.register_proper_name(good_name)
return good_name
def format_help(help):
+19
View File
@@ -58,6 +58,25 @@ class Project(object):
return d_dir
@property
def proper_names_location(self):
pn_file = os.sep.join(self.pipfile_location.split(os.sep)[:-1] + ['.venv', 'pipenev-proper-names.txt'])
# Create the database, if it doesn't exist.
open(pn_file, 'a').close()
return pn_file
@property
def proper_names(self):
with open(self.proper_names_location, 'r') as f:
return f.read().splitlines()
def register_proper_name(self, name):
"""Registers a proper name to the database."""
with open(self.proper_names_location, 'a') as f:
f.write('{0}\n'.format(name))
@property
def pipfile_location(self):
try: