Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Make Java, Python wheel artifacts have same dependencies #5915

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions py/embedded-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ plugins {
id 'java-library'
}

evaluationDependsOn ':docker-server-jetty'

configurations {
classpath
}
Expand All @@ -24,3 +26,40 @@ dependencies {
because 'downstream dagger compile'
}
}

def testPyClient = Docker.registerDockerTask(project, 'testPyClient') {
copyIn {
from('tests') {
into 'project/tests'
}
from(tasks.getByName('buildWheel')) {
into 'wheels'
}
from(configurations.pythonWheel) {
into 'wheels'
}
from ('requirements-dev.txt') {
into 'project/'
}
}
dockerfile {
// Start from the image that built our wheel, so it is already ready to go
from(Docker.localImageName('server-jetty'))
copyFile('project', '/project')
copyFile('wheels', '/wheels')

workingDir('/project')
runCommand '''set -eux; \\
mkdir -p /out/report; \\
pip install --upgrade pip; \\
pip3 install -r requirements-dev.txt; \\
pip3 install /wheels/*'''
}
parentContainers = [ project(':docker-server-jetty').tasks.findByName('buildDocker-server-jetty') ]
entrypoint = ['python', '-m', 'xmlrunner', 'discover', 'tests', '-v', '-o', '/out/report']
copyOut {
into layout.buildDirectory.dir('test-results')
}
}

tasks.getByName('check').dependsOn(testPyClient)
10 changes: 10 additions & 0 deletions py/embedded-server/java-runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ dependencies {
runtimeOnly project(':hotspot-impl')
}

if (!hasProperty('excludeClockImpl')) {
runtimeOnly project(':clock-impl')
}

if (!hasProperty('excludeSql')) {
runtimeOnly project(':engine-sql')
}
Expand All @@ -34,6 +38,12 @@ dependencies {
runtimeOnly project(':extensions-s3')
runtimeOnly project(':extensions-iceberg-s3')
}

if (!hasProperty('excludeJson')) {
dependencies {
runtimeOnly project(':extensions-json-jackson')
}
}
}

// making a dir here isn't optimal, but without it we need to make py-embedded-server be a java and a python
Expand Down
10 changes: 10 additions & 0 deletions py/embedded-server/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pandas
pyarrow
grpcio
setuptools
protobuf
wheel
sphinx
bitstring
unittest-xml-reporting
timeout-decorator
27 changes: 27 additions & 0 deletions py/embedded-server/tests/test_load_app_modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
#

import unittest
import importlib
import pkgutil
import sys


class LoadAllModules(unittest.TestCase):
def test_import_all_packages(self):
# First start the server that is defined in this package
from deephaven_server import Server
Server().start()

# Then iterate through all deephaven packages to make sure they all can be imported
# using the wheel that we distribute
pkg = importlib.import_module('deephaven')

mods = pkgutil.walk_packages(pkg.__path__, prefix='deephaven.')
for mod in mods:
if mod.name not in sys.modules:
try:
importlib.import_module(mod.name)
except:
...
31 changes: 19 additions & 12 deletions py/server/deephaven_internal/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
import io


def _get_encoding_or_utf8(stream) -> str:
"""
Helper to read the encoding from a stream. The stream implementation may or may not have an
encoding property, and if it has one it might be None - if absent or None, use utf8, otherwise
return the actual encoding value.

Known cases:
- "no encoding attr' - jpy doesn't include this attr for its built-in stdout/stderr impls
- "encoding attr is None" - xmlrunner has an attribute, but it has a None value
- other cases seem to provide a real value.
:param stream: the stream to ask for its encoding
:return: the encoding to use
"""
return getattr(stream, 'encoding', 'UTF-8') or 'UTF-8'


class TeeStream(io.TextIOBase):
"""TextIOBase subclass that splits output between a delegate instance and a set of lambdas.

Expand All @@ -14,10 +30,7 @@ class TeeStream(io.TextIOBase):

@classmethod
def split(cls, py_stream, java_stream):
if hasattr(py_stream, "encoding"):
encoding = py_stream.encoding
else:
encoding = 'UTF-8'
encoding = _get_encoding_or_utf8(py_stream)
return TeeStream(
orig_stream=py_stream,
should_write_to_orig_stream=True,
Expand All @@ -28,10 +41,7 @@ def split(cls, py_stream, java_stream):

@classmethod
def redirect(cls, py_stream, java_stream):
if hasattr(py_stream, "encoding"):
encoding = py_stream.encoding
else:
encoding = 'UTF-8'
encoding = _get_encoding_or_utf8(py_stream)
return TeeStream(
orig_stream=py_stream,
should_write_to_orig_stream=False,
Expand Down Expand Up @@ -72,10 +82,7 @@ def fileno(self):

@property
def encoding(self):
if hasattr(self._stream, 'encoding') and self._stream.encoding is not None:
return self._stream.encoding
else:
return 'UTF-8'
return _get_encoding_or_utf8(self._stream)

def write(self, string):
self.write_func(string)
Expand Down
2 changes: 2 additions & 0 deletions server/jetty-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ if (!hasProperty('excludeJson')) {
}
}

// When you add a new dependency here, be sure to include it in server-netty-app and py-embedded-server

def authHandlers = []
def authConfigs = ['AuthHandlers']
if (hasProperty('anonymous')) {
Expand Down
6 changes: 6 additions & 0 deletions server/netty-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ if (!hasProperty('excludeS3')) {
}
}

if (!hasProperty('excludeJson')) {
dependencies {
runtimeOnly project(':extensions-json-jackson')
}
}

def authHandlers = []
def authConfigs = ['AuthHandlers']
if (hasProperty('anonymous')) {
Expand Down
Loading