Skip to content

Commit

Permalink
Port bin to Python 3 (pantsbuild#6126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Arellano authored and Chris Livingston committed Aug 27, 2018
1 parent 5a5d7ba commit 0f83d35
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/python/pants/bin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
python_library(
dependencies=[
'3rdparty/python/twitter/commons:twitter.common.collections',
'3rdparty/python:future',
'3rdparty/python:setproctitle',
'src/python/pants/backend/jvm/tasks:nailgun_task',
'src/python/pants/base:build_environment',
Expand Down
4 changes: 3 additions & 1 deletion src/python/pants/bin/daemon_pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import termios
import time
from builtins import str, zip
from contextlib import contextmanager

from setproctitle import setproctitle as set_process_title
Expand Down Expand Up @@ -285,7 +286,8 @@ def post_fork_child(self):

# Broadcast our process group ID (in PID form - i.e. negated) to the remote client so
# they can send signals (e.g. SIGINT) to all processes in the runners process group.
NailgunProtocol.send_pid(self._socket, bytes(os.getpgrp() * -1))
pid = str(os.getpgrp() * -1).encode('ascii')
NailgunProtocol.send_pid(self._socket, pid)

# Invoke a Pants run with stdio redirected and a proxied environment.
with self.nailgunned_stdio(self._socket, self._env) as finalizer,\
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/bin/goal_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import logging
import sys
from builtins import object

from pants.base.cmd_line_spec_parser import CmdLineSpecParser
from pants.base.workunit import WorkUnit, WorkUnitLabel
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/bin/local_pants_runner.py
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 logging
from builtins import object

from pants.base.build_environment import get_buildroot
from pants.bin.goal_runner import GoalRunner
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/bin/pants_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import locale
import os
import warnings
from builtins import object


class PantsLoader(object):
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/bin/pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import os
import sys
from builtins import object

from pants.bin.remote_pants_runner import RemotePantsRunner
from pants.option.options_bootstrapper import OptionsBootstrapper
Expand Down
8 changes: 6 additions & 2 deletions src/python/pants/bin/remote_pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import signal
import sys
import time
from builtins import object, str
from contextlib import contextmanager

from future.utils import raise_with_traceback

from pants.console.stty_utils import STTYSettings
from pants.java.nailgun_client import NailgunClient
from pants.java.nailgun_protocol import NailgunProtocol
Expand Down Expand Up @@ -122,9 +125,10 @@ def _run_pants_with_retry(self, port, retries=3):
# Ensure a newline.
logger.fatal('')
logger.fatal('lost active connection to pantsd!')
raise self.Terminated, (
raise_with_traceback(
self.Terminated,
'abruptly lost active connection to pantsd runner: {!r}'.format(e)
), e.traceback
)

def _connect_and_execute(self, port):
# Merge the nailgun TTY capability environment variables with the passed environment dict.
Expand Down
7 changes: 5 additions & 2 deletions src/python/pants/java/nailgun_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

import six
from future.utils import binary_type
Expand Down Expand Up @@ -87,7 +87,10 @@ class TruncatedPayloadError(TruncatedRead):
@classmethod
def _decode_unicode_seq(cls, seq):
for item in seq:
yield item.decode('utf-8')
if isinstance(item, bytes):
yield item.decode('utf-8')
else:
yield item

@classmethod
def send_request(cls, sock, working_dir, command, *arguments, **environment):
Expand Down

0 comments on commit 0f83d35

Please sign in to comment.