Have the python component include the egg-info.

Instead of having to repeatly get the egg-info
and do the repeated checks in base.py and yum.py
we should just have the component itself (if
applicable) provide its own egg-info instead of
having to repeatly fetch it.

Change-Id: Ic0a85f26224210af191c5bd86ffad5af30d7dabf
This commit is contained in:
Joshua Harlow 2013-06-19 20:50:20 -07:00
parent e4c595a2df
commit 71f4c7e71a
4 changed files with 30 additions and 28 deletions

View File

@ -20,6 +20,8 @@ from anvil import shell as sh
from anvil import trace as tr
from anvil import utils
from anvil.packaging.helpers import pip_helper
from anvil.components.configurators import base as conf
LOG = logging.getLogger(__name__)
@ -147,10 +149,18 @@ class PythonInstallComponent(PkgInstallComponent):
self.requires_files.append(sh.joinpths(tools_dir, 'test-requires'))
self.requires_files.append(sh.joinpths(app_dir,
'test-requirements.txt'))
self._egg_info = None
def _get_download_config(self):
return 'get_from'
@property
def egg_info(self):
if self._egg_info is None:
egg = pip_helper.get_directory_details(self.get_option('app_dir'))
self._egg_info = egg
return self._egg_info
class PkgUninstallComponent(base.Component):
def __init__(self, *args, **kargs):

View File

@ -18,12 +18,8 @@
from anvil.components import base_install as binstall
class Installer(binstall.PythonInstallComponent):
def _get_python_directories(self):
return {}
def _get_download_config(self):
return None
class Installer(binstall.PkgInstallComponent):
pass
class Uninstaller(binstall.PkgUninstallComponent):

View File

@ -101,7 +101,13 @@ class DependencyHandler(object):
@property
def python_names(self):
if self._python_names is None:
self._python_names = self._get_python_names(self.package_dirs)
names = []
for i in self.instances:
try:
names.append(i.egg_info['name'])
except AttributeError:
pass
self._python_names = names
return self._python_names
@staticmethod
@ -113,14 +119,6 @@ class DependencyHandler(object):
package_dirs.append(app_dir)
return package_dirs
@staticmethod
def _get_python_names(package_dirs):
python_names = []
for pkg_dir in package_dirs:
pkg_details = pip_helper.get_directory_details(pkg_dir)
python_names.append(pkg_details['name'])
return python_names
def package_start(self):
requires_files = []
extra_pips = []

View File

@ -277,9 +277,10 @@ class YumDependencyHandler(base.DependencyHandler):
def _write_spec_file(self, instance, app_dir, rpm_name, template_name,
params):
requires_what = []
if sh.isfile(sh.joinpths(app_dir, "setup.py")):
egg_info = pip_helper.get_directory_details(app_dir)
requires_what.extend(egg_info['dependencies'])
try:
requires_what.extend(instance.egg_info['dependencies'])
except AttributeError:
pass
# Ensure we include any extra pips that are desired.
extra_pips = instance.get_option('pips') or []
for i_pip in extra_pips:
@ -385,10 +386,8 @@ class YumDependencyHandler(base.DependencyHandler):
def _get_template_and_rpm_name(self, instance):
rpm_name = None
template_name = None
app_dir = instance.get_option('app_dir')
if sh.isfile(sh.joinpths(app_dir, "setup.py")):
egg_info = pip_helper.get_directory_details(app_dir)
egg_name = egg_info['name']
try:
egg_name = instance.egg_info['name']
if self._is_client(instance.name, egg_name):
rpm_name = egg_name
template_name = "python-commonclient.spec"
@ -396,7 +395,7 @@ class YumDependencyHandler(base.DependencyHandler):
rpm_name = "openstack-%s" % (egg_name)
else:
rpm_name = self.TRANSLATION_NAMES.get(instance.name)
else:
except AttributeError:
rpm_name = instance.name
template_name = "%s.spec" % rpm_name
return (rpm_name, template_name)
@ -405,10 +404,9 @@ class YumDependencyHandler(base.DependencyHandler):
params = {}
(rpm_name, template_name) = self._get_template_and_rpm_name(instance)
app_dir = instance.get_option('app_dir')
if sh.isfile(sh.joinpths(app_dir, "setup.py")):
egg_info = pip_helper.get_directory_details(app_dir)
egg_name = egg_info['name']
params["version"] = egg_info["version"]
try:
egg_name = instance.egg_info['name']
params["version"] = instance.egg_info["version"]
if self._is_client(instance.name, egg_name):
client_name = utils.strip_prefix_suffix(egg_name,
"python-", "client")
@ -418,7 +416,7 @@ class YumDependencyHandler(base.DependencyHandler):
params["clientname"] = client_name
params["apiname"] = self.API_NAMES.get(client_name,
client_name.title())
else:
except AttributeError:
spec_filename = sh.joinpths(settings.TEMPLATE_DIR,
self.SPEC_TEMPLATE_DIR, template_name)
if not sh.isfile(spec_filename):