Skip to content

Commit

Permalink
Port java to Python 3 (#6159)
Browse files Browse the repository at this point in the history
Part of #6062
  • Loading branch information
Eric-Arellano authored and Stu Hood committed Jul 17, 2018
1 parent 2b8f295 commit e61a164
Show file tree
Hide file tree
Showing 23 changed files with 38 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/python/pants/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ python_library(
name = 'executor',
sources = ['executor.py'],
dependencies = [
'3rdparty/python:future',
'3rdparty/python/twitter/commons:twitter.common.collections',
'3rdparty/python:six',
'src/python/pants/base:build_environment',
Expand All @@ -19,6 +20,7 @@ python_library(
name = 'nailgun_client',
sources = ['nailgun_client.py'],
dependencies = [
'3rdparty/python:future',
':nailgun_io',
':nailgun_protocol',
'src/python/pants/util:socket'
Expand All @@ -29,6 +31,7 @@ python_library(
name = 'nailgun_io',
sources = ['nailgun_io.py'],
dependencies = [
'3rdparty/python:future',
'3rdparty/python:contextlib2',
':nailgun_protocol'
]
Expand All @@ -38,6 +41,7 @@ python_library(
name = 'nailgun_protocol',
sources = ['nailgun_protocol.py'],
dependencies = [
'3rdparty/python:future',
'3rdparty/python:six',
]
)
Expand All @@ -60,6 +64,7 @@ python_library(
name = 'util',
sources = ['util.py'],
dependencies = [
'3rdparty/python:future',
':executor',
':nailgun_executor',
'src/python/pants/base:workunit',
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/java/distribution/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
python_library(
sources=[ 'distribution.py' ],
dependencies=[
'3rdparty/python:future',
'3rdparty/python:six',
':resources',
'src/python/pants/base:revision',
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/java/distribution/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pkgutil
import plistlib
from abc import abstractproperty
from builtins import object, str
from collections import namedtuple
from contextlib import contextmanager

Expand Down
1 change: 1 addition & 0 deletions src/python/pants/java/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import sys
from abc import abstractmethod, abstractproperty
from builtins import object
from contextlib import contextmanager

from six import string_types
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/java/jar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

python_library(
dependencies = [
'3rdparty/python:future',
'3rdparty/python:six',
'src/python/pants/base:build_environment',
'src/python/pants/base:hash_utils',
Expand Down
2 changes: 2 additions & 0 deletions src/python/pants/java/jar/exclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from __future__ import absolute_import, division, print_function, unicode_literals

from builtins import object


class Exclude(object):
"""Represents a dependency exclude pattern to filter transitive dependencies against.
Expand Down
6 changes: 4 additions & 2 deletions src/python/pants/java/jar/jar_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import os
import urlparse
from builtins import object

from future.moves.urllib import parse

from pants.base.build_environment import get_buildroot
from pants.base.hash_utils import stable_json_hash
Expand Down Expand Up @@ -115,7 +117,7 @@ def name(self):
@memoized_method
def get_url(self, relative=False):
if self.url:
parsed_url = urlparse.urlparse(self.url)
parsed_url = parse.urlparse(self.url)
if parsed_url.scheme == 'file':
if relative and os.path.isabs(parsed_url.path):
relative_path = os.path.relpath(parsed_url.path,
Expand Down
2 changes: 2 additions & 0 deletions src/python/pants/java/jar/jar_dependency_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from __future__ import absolute_import, division, print_function, unicode_literals

from builtins import object

from pants.util.memo import memoized_property


Expand Down
1 change: 1 addition & 0 deletions src/python/pants/java/jar/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import absolute_import, division, print_function, unicode_literals

from builtins import object
from contextlib import closing

from six import StringIO
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/java/junit/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

python_library(
dependencies=[
'3rdparty/python:future',
'3rdparty/python/twitter/commons:twitter.common.collections',
'src/python/pants/util:dirutil',
'src/python/pants/util:objects',
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/java/junit/junit_xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import fnmatch
import os
from builtins import object
from collections import defaultdict

from twitter.common.collections import OrderedSet
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/java/nailgun_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import signal
import socket
import sys
from builtins import object, str

from pants.java.nailgun_io import NailgunStreamWriter
from pants.java.nailgun_protocol import ChunkType, NailgunProtocol
Expand Down
5 changes: 3 additions & 2 deletions src/python/pants/java/nailgun_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
import select
import threading
from builtins import zip
from contextlib import contextmanager

from contextlib2 import ExitStack
Expand Down Expand Up @@ -163,10 +164,10 @@ def open_multi(cls, sock, chunk_types, isattys, chunk_eof_type=None, buf_size=No

# N.B. This is purely to permit safe handling of a dynamic number of contextmanagers.
with ExitStack() as stack:
read_fds, write_fds = zip(
read_fds, write_fds = list(zip(
# Allocate one pipe pair per chunk type provided.
*(stack.enter_context(_pipe(isatty)) for isatty in isattys)
)
))
writer = NailgunStreamWriter(
read_fds,
sock,
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/java/nailgun_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os
import struct
from builtins import bytes, object, zip

import six

Expand Down
5 changes: 3 additions & 2 deletions src/python/pants/java/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import logging
import os
import sys
import urllib
from zipfile import ZIP_STORED

from future.moves.urllib import parse

from pants.base.workunit import WorkUnit, WorkUnitLabel
from pants.java.executor import Executor, SubprocessExecutor
from pants.java.jar.manifest import Manifest
Expand Down Expand Up @@ -275,7 +276,7 @@ def safe_classpath(classpath, synthetic_jar_dir, custom_name=None):
synthetic_jar_dir = safe_mkdtemp()

# Quote the paths so that if they contain reserved characters can be safely passed to JVM classloader.
bundled_classpath = map(urllib.quote, relativize_classpath(classpath, synthetic_jar_dir))
bundled_classpath = [parse.quote(cp) for cp in relativize_classpath(classpath, synthetic_jar_dir)]

manifest = Manifest()
manifest.addentry(Manifest.CLASS_PATH, ' '.join(bundled_classpath))
Expand Down
2 changes: 2 additions & 0 deletions tests/python/pants_test/java/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ python_tests(
name = 'executor',
sources = ['test_executor.py'],
dependencies = [
'3rdparty/python:future',
'src/python/pants/java/distribution:distribution',
'src/python/pants/java:executor',
'src/python/pants/util:contextutil',
Expand All @@ -18,6 +19,7 @@ python_tests(
sources = ['test_nailgun_client.py'],
coverage = ['pants.java.nailgun_client'],
dependencies = [
'3rdparty/python:future',
'3rdparty/python:mock',
'src/python/pants/java:nailgun_client',
]
Expand Down
2 changes: 2 additions & 0 deletions tests/python/pants_test/java/distribution/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
python_tests(
sources = ['test_distribution.py'],
dependencies = [
'3rdparty/python:future',
'3rdparty/python/twitter/commons:twitter.common.collections',
'src/python/pants/base:revision',
'src/python/pants/java/distribution',
Expand All @@ -19,6 +20,7 @@ python_tests(
name = 'distribution_integration',
sources = ['test_distribution_integration.py'],
dependencies = [
'3rdparty/python:future',
'src/python/pants/java/distribution',
'src/python/pants/util:osutil',
'tests/python/pants_test:int-test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import textwrap
import unittest
from builtins import object
from contextlib import contextmanager

from twitter.common.collections import maybe_list
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import os
from builtins import str
from contextlib import contextmanager
from unittest import skipIf

Expand Down
1 change: 1 addition & 0 deletions tests/python/pants_test/java/junit/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

python_tests(
dependencies=[
'3rdparty/python:future',
'src/python/pants/java/junit',
'src/python/pants/util:contextutil',
'src/python/pants/util:dirutil',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os
import unittest
from builtins import object

from pants.java.junit.junit_xml_parser import Test as JUnitTest
# NB: The Test -> JUnitTest import re-name above is needed to work around conflicts with pytest test
Expand Down
1 change: 1 addition & 0 deletions tests/python/pants_test/java/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import textwrap
import unittest
from builtins import object
from contextlib import contextmanager

from pants.java.distribution.distribution import Distribution
Expand Down
1 change: 1 addition & 0 deletions tests/python/pants_test/java/test_nailgun_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import signal
import socket
import unittest
from builtins import object

import mock

Expand Down

0 comments on commit e61a164

Please sign in to comment.