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

Dropping support for python 3<x<3.6 #186

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c225808
Added --always-copy to virtualenv call
justquick Nov 3, 2014
a459b64
fixed tests to include copy flag
justquick Nov 3, 2014
8f28c88
Dropping support for python 3<x<3.6
Aug 29, 2017
634030c
Fix terminal encoding issues. Temporarily bump a dev version.
Sep 1, 2017
ff6b5a8
Merge branch 'virtualenv-always-copy' of github.com:justquick/pyleus …
Sep 1, 2017
ad71838
Fix Python 3.6 sys.stdout expects unicode inputs.
Sep 1, 2017
003f7a8
Enable str/bin distinction in msgpack-python. Fix unit-tests.
Sep 2, 2017
3954da0
Fix unwanted unicode support when packing the message (the receiving …
Sep 2, 2017
7541f0a
Bump version to 0.3.1 for the Python 3.6 fixes.
Sep 2, 2017
2e597ed
Merge pull request #2 from Detoo/fix-py36
westover Sep 4, 2017
605af40
Fix incompatible sys.stdout.buffer in Python 2. Bump version to 0.3.2
Sep 12, 2017
fc2d2d9
Adding in the ability to use ujson for the JSONSerializer
Sep 22, 2017
685c8b4
(WIP) Python process to be instrumented by New Relic agent.
Feb 17, 2018
be5b8a5
Bump version to 0.3.4-dev
Feb 17, 2018
433a126
Set New Relic config path.
Feb 17, 2018
dfe7067
Fix newrelic did not report by forcing the use of native newrelic-adm…
Feb 20, 2018
e89a6eb
Fix newrelic did not report under virtualenv by overriding the python…
Feb 20, 2018
cbfdd4f
Remove unused codes.
Feb 20, 2018
3323e2b
Finalize version 0.3.4
Feb 20, 2018
0a28c4f
Add comments about the dependency on newrelic.ini
Feb 21, 2018
e1c6fa7
Add more comments about working around newrelic-admin python installa…
Feb 21, 2018
ea1b501
Merge pull request #3 from earthmine/add-py-newrelic-dep
Detoo Feb 22, 2018
f9b89a7
Default use_wheel to false because --use-wheel is deprecated since pi…
Apr 24, 2018
4d9c14c
Bump version to 0.3.5
Apr 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyleus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pkg_resources

__version__ = '0.3.0'
__version__ = '0.3.5'

BASE_JAR = "pyleus-base.jar"
BASE_JAR_PATH = pkg_resources.resource_filename('pyleus', BASE_JAR)
4 changes: 3 additions & 1 deletion pyleus/cli/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import tempfile
import yaml
import zipfile
import sys

from pyleus import __version__
from pyleus.cli.topology_spec import TopologySpec
Expand All @@ -27,6 +28,7 @@
YAML_FILENAME = "pyleus_topology.yaml"
DEFAULT_REQUIREMENTS_FILENAME = "requirements.txt"
VIRTUALENV_NAME = "pyleus_venv"
SYS_ENCODING = sys.getdefaultencoding()

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -96,7 +98,7 @@ def _remove_pyleus_base_jar(venv):
virtualenv, and we don't want to attempt its removal in that case.
"""
base_jar_path = venv.execute_module("pyleus._base_jar",
cwd=venv.path).strip()
cwd=venv.path).decode(SYS_ENCODING).strip()
if _path_contained_by(venv.path, base_jar_path):
os.remove(base_jar_path)

Expand Down
5 changes: 3 additions & 2 deletions pyleus/cli/virtualenv_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class VirtualenvProxy(object):
def __init__(self, path,
system_site_packages=False,
pypi_index_url=None,
use_wheel=True,
# Default to false since --use-wheel flag is deprecated since pip 9.0.1
use_wheel=False,
python_interpreter=None,
verbose=False):
"""Creates the virtualenv with the options specified"""
Expand All @@ -55,7 +56,7 @@ def __init__(self, path,

def _create_virtualenv(self):
"""Creates the actual virtualenv"""
cmd = ["virtualenv", self.path]
cmd = ["virtualenv", "--always-copy", self.path]
if self._system_site_packages:
cmd.append("--system-site-packages")

Expand Down
8 changes: 7 additions & 1 deletion pyleus/storm/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ def __init__(self, input_stream=None, output_stream=None):
input_stream = sys.stdin

if output_stream is None:
output_stream = sys.stdout
# Pyleus serializer outputs byte sequence; however, Python 3.6 sys.stdout expects unicode stream inputs.
# In order to write binary data to stdout, we use the underlying binary buffer object.
# Ref: https://docs.python.org/3/library/sys.html#sys.stderr
try:
output_stream = sys.stdout.buffer
except AttributeError:
output_stream = sys.stdout

self._input_stream = input_stream
self._output_stream = output_stream
Expand Down
9 changes: 6 additions & 3 deletions pyleus/storm/serializers/json_serializer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""JSON implementation of Pyleus serializer"""

try:
import simplejson as json
_ = json # pyflakes
import ujson as json
except ImportError:
import json
try:
import simplejson as json
_ = json # pyflakes
except ImportError:
import json

from pyleus.storm import StormWentAwayError
from pyleus.storm.serializers.serializer import Serializer
Expand Down
7 changes: 6 additions & 1 deletion pyleus/storm/serializers/msgpack_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@


def _messages_generator(input_stream):
unpacker = msgpack.Unpacker()
# Python 3.6 strings are in unicode and are different from generic byte sequence (binary).
# As of v0.4.8, msgpack-python supports the distinction between str and bin types, but it is not enabled by default.
# To enable it requires using use_bin_type=True option in Packer and encoding="utf-8" option in Unpacker
# Ref: https://github.com/msgpack/msgpack-python#string-and-binary-type
unpacker = msgpack.Unpacker(encoding='utf-8')
while True:
# f.read(n) on sys.stdin blocks until n bytes are read, causing
# serializer to hang.
Expand Down Expand Up @@ -46,5 +50,6 @@ def send_msg(self, msg_dict):
""""Messages are delimited by msgapck itself, no need for Storm
multilang end line.
"""
# Don't set use_bin_type=True because the receiving end (Java component) does not expect unicode strings
msgpack.pack(msg_dict, self._output_stream)
self._output_stream.flush()
4 changes: 2 additions & 2 deletions tests/cli/build_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test__remove_pyleus_base_jar(self):
mock_venv_path = "/path/to/venv"

def mock_execute_module(module, cwd):
return "/path/to/venv/inside.jar"
return b"/path/to/venv/inside.jar"

mock_venv = mock.Mock(
path=mock_venv_path,
Expand All @@ -166,7 +166,7 @@ def test__remove_pyleus_base_jar_no_remove(self):
mock_venv_path = "/path/to/venv"

def mock_execute_module(module, cwd):
return "/foo/bar/outside.jar"
return b"/foo/bar/outside.jar"

mock_venv = mock.Mock(
path=mock_venv_path,
Expand Down
11 changes: 5 additions & 6 deletions tests/cli/virtualenv_proxy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test__create_virtualenv_no_options(
system_site_packages=False,
verbose=True)
mock_cmd.assert_called_once_with(
["virtualenv", VENV_PATH],
["virtualenv", "--always-copy", VENV_PATH],
stdout=venv._out_stream,
stderr=venv._err_stream,
err_msg=mock.ANY
Expand All @@ -72,22 +72,21 @@ def test__create_virtualenv_system_site_packages(
system_site_packages=True,
verbose=True)
mock_cmd.assert_called_once_with(
["virtualenv", VENV_PATH, "--system-site-packages"],
["virtualenv", "--always-copy", VENV_PATH, "--system-site-packages"],
stdout=venv._out_stream,
stderr=venv._err_stream,
err_msg=mock.ANY
)

@mock.patch.object(builtins, 'open', autospec=True)
@mock.patch.object(virtualenv_proxy, '_exec_shell_cmd', autospec=True)
def test__create_virtualenv_python_interpreter(
def test__create_virtualenv_no_system_site_packages(
self, mock_cmd, mock_open):
path = "python2.7"
venv = VirtualenvProxy(VENV_PATH,
python_interpreter=path,
system_site_packages=False,
verbose=True)
mock_cmd.assert_called_once_with(
["virtualenv", VENV_PATH, "--python", path],
["virtualenv", "--always-copy", VENV_PATH],
stdout=venv._out_stream,
stderr=venv._err_stream,
err_msg=mock.ANY
Expand Down
2 changes: 1 addition & 1 deletion tests/storm/serializers/msgpack_serializer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TestMsgpackSerializer(SerializerTestCase):

def test_read_msg_dict(self):
msg_dict = {
b'hello': b"world",
'hello': "world",
}

encoded_msg = msgpack.packb(msg_dict)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@
public class PythonComponentsFactory {

public static final String VIRTUALENV_INTERPRETER = "pyleus_venv/bin/python";
// A few notes on how this works:
// (1) The developer of the topology is responsible for putting a newrelic.ini at the root of the topology folder,
// alongside with the topology definition file (.yml).
// (2) newrelic-admin only works when the python process it monitors uses the same python installation that
// installed newrelic-admin, as described here:
// https://docs.newrelic.com/docs/agents/python-agent/installation-configuration/python-agent-admin-script
// (3) newrelic-admin installed by Pyleus in the virtualenv actually points to the wrong python installation in a
// temporary folder. We work around that issue by run it with a specified python installation instead of
// running it directly as a self-executable script.
public static final String NEW_RELIC_PREFIX = String.format("NEW_RELIC_CONFIG_FILE=newrelic.ini %s pyleus_venv/bin/newrelic-admin run-program", VIRTUALENV_INTERPRETER);
public static final String MODULE_OPTION = "-m";

private String[] buildCommand(final String module, final Map<String, Object> argumentsMap,
Expand All @@ -23,7 +33,7 @@ private String[] buildCommand(final String module, final Map<String, Object> arg

StringBuilder strBuf = new StringBuilder();
// Done before launching any spout or bolt in order to cope with Storm permissions bug
strBuf.append(String.format("chmod 755 %s; %s", VIRTUALENV_INTERPRETER, VIRTUALENV_INTERPRETER));
strBuf.append(String.format("chmod 755 %s; %s %s", VIRTUALENV_INTERPRETER, NEW_RELIC_PREFIX, VIRTUALENV_INTERPRETER));
strBuf.append(String.format(" %s %s", MODULE_OPTION, module));

if (argumentsMap != null) {
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py26, py27, py31, py32, py33, py34
envlist = py26, py27, py36
# tox has no use_wheel option
install_cmd = pip install --pre --use-wheel {opts} {packages}

Expand Down