From dee3a36d28aa1971704b220ab3f2eb1b36520a55 Mon Sep 17 00:00:00 2001 From: Patrick Lucas Date: Fri, 17 Oct 2014 15:57:18 -0700 Subject: [PATCH] Fix base jar installation Previously, pyleus-base.jar was installed to sys.prefix + '/share/pyleus/ pyleus-base.jar', and this worked fine when Pyleus was installed in a virtualenv or via an fpm-created deb. In the former case, the jar was installed to $VIRTUAL_ENV/share/pyleus/pyleus-base.jar, and in the latter, it made its way to /usr/share/pyleus/pyleus-base.jar. However, if a user just ran 'pip install pyleus' on their system, the jar would actually be installed to /usr/local/share/pyleus/pyleus-base.jar, even though sys.prefix was just '/usr' when pyleus was executed. Pyleus would thus look in /usr/share/pyleus and fail when it couldn't find the base jar. This change uses the seemingly preferred method of including the jar within the package itself, and using the pkg_resources module to construct its filesystem path. The build step of removing the base jar from a topology jar (since it is unneeded and takes up space) required modification as well. Closes #24 --- MANIFEST.in | 2 +- pyleus/__init__.py | 6 ++---- pyleus/_base_jar.py | 10 ++++++++++ pyleus/cli/build.py | 5 ++--- pyleus/cli/virtualenv_proxy.py | 7 +++++-- setup.py | 10 ++++++++-- 6 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 pyleus/_base_jar.py diff --git a/MANIFEST.in b/MANIFEST.in index ee442f0..9ba4106 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,3 +1,3 @@ -include topology_builder/dist/pyleus-base.jar +include pyleus/pyleus-base.jar include LICENSE include README.rst diff --git a/pyleus/__init__.py b/pyleus/__init__.py index c8ac1a7..57d3568 100644 --- a/pyleus/__init__.py +++ b/pyleus/__init__.py @@ -1,10 +1,8 @@ from __future__ import absolute_import -import os -import sys +import pkg_resources __version__ = '0.2' BASE_JAR = "pyleus-base.jar" -BASE_JAR_INSTALL_DIR = "share/pyleus" -BASE_JAR_PATH = os.path.join(sys.prefix, BASE_JAR_INSTALL_DIR, BASE_JAR) +BASE_JAR_PATH = pkg_resources.resource_filename('pyleus', BASE_JAR) diff --git a/pyleus/_base_jar.py b/pyleus/_base_jar.py new file mode 100644 index 0000000..480644d --- /dev/null +++ b/pyleus/_base_jar.py @@ -0,0 +1,10 @@ +"""This module is used only by pyleus.cli.build._remove_pyleus_base_jar to +determine the value of BASE_JAR_PATH inside _another_ virtualenv, so it can be +removed to save space. +""" +from __future__ import absolute_import + +import pyleus + +if __name__ == '__main__': + print pyleus.BASE_JAR_PATH diff --git a/pyleus/cli/build.py b/pyleus/cli/build.py index 8f56a78..8920982 100644 --- a/pyleus/cli/build.py +++ b/pyleus/cli/build.py @@ -15,8 +15,6 @@ import zipfile from pyleus import __version__ -from pyleus import BASE_JAR -from pyleus import BASE_JAR_INSTALL_DIR from pyleus.cli.topology_spec import TopologySpec from pyleus.cli.virtualenv_proxy import VirtualenvProxy from pyleus.storm.component import DESCRIBE_OPT @@ -79,7 +77,8 @@ def _remove_pyleus_base_jar(venv): """Remove the Pyleus base jar from the virtualenv since it's redundant and takes up space. See PYLEUS-74. """ - base_jar_path = os.path.join(venv.path, BASE_JAR_INSTALL_DIR, BASE_JAR) + base_jar_path = venv.execute_module("pyleus._base_jar", + cwd=venv.path).strip() os.remove(base_jar_path) diff --git a/pyleus/cli/virtualenv_proxy.py b/pyleus/cli/virtualenv_proxy.py index d245d52..3b93c8f 100644 --- a/pyleus/cli/virtualenv_proxy.py +++ b/pyleus/cli/virtualenv_proxy.py @@ -92,10 +92,13 @@ def install_from_requirements(self, req): err_msg="Failed to install dependencies for this topology." " Run with --verbose for detailed info.") - def execute_module(self, module, args, cwd=None): + def execute_module(self, module, args=None, cwd=None): """Call "virtualenv/interpreter -m" to execute a python module.""" cmd = [os.path.join(self.path, "bin", "python"), "-m", module] - cmd += args + + if args: + cmd += args + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, diff --git a/setup.py b/setup.py index 1027be9..cc4807c 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ from distutils.command.bdist import bdist as _bdist from distutils.core import Command import os +import shutil import subprocess import sys @@ -8,10 +9,11 @@ from setuptools.command.sdist import sdist as _sdist from pyleus import __version__ -from pyleus import BASE_JAR, BASE_JAR_INSTALL_DIR +from pyleus import BASE_JAR JAVA_SRC_DIR = "topology_builder/" BASE_JAR_SRC = os.path.join(JAVA_SRC_DIR, "dist", BASE_JAR) +BASE_JAR_DST = os.path.join("pyleus", BASE_JAR) class build_java(Command): @@ -28,8 +30,12 @@ def finalize_options(self): def _make_jar(self): subprocess.check_call(["make", "-C", JAVA_SRC_DIR]) + def _copy_jar(self): + shutil.copy(BASE_JAR_SRC, BASE_JAR_DST) + def run(self): self._make_jar() + self._copy_jar() class bdist(_bdist): @@ -87,7 +93,7 @@ def run(self): "PyYAML", "msgpack-python", ] + extra_install_requires, - data_files=[(BASE_JAR_INSTALL_DIR, [BASE_JAR_SRC])], + package_data={'pyleus': [BASE_JAR]}, cmdclass={ 'build_java': build_java, 'bdist': bdist,