Skip to content
This repository has been archived by the owner on Apr 18, 2018. It is now read-only.

Commit

Permalink
Fix base jar installation
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Patrick Lucas committed Oct 18, 2014
1 parent 2d62d6a commit dee3a36
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
@@ -1,3 +1,3 @@
include topology_builder/dist/pyleus-base.jar
include pyleus/pyleus-base.jar
include LICENSE
include README.rst
6 changes: 2 additions & 4 deletions 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)
10 changes: 10 additions & 0 deletions 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
5 changes: 2 additions & 3 deletions pyleus/cli/build.py
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down
7 changes: 5 additions & 2 deletions pyleus/cli/virtualenv_proxy.py
Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions setup.py
@@ -1,17 +1,19 @@
from distutils.command.bdist import bdist as _bdist
from distutils.core import Command
import os
import shutil
import subprocess
import sys

from setuptools import setup
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):
Expand All @@ -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):
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit dee3a36

Please sign in to comment.