mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
cache proper names, for speed
This commit is contained in:
+10
-1
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user