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

Port backend/jvm #6092

Merged
merged 25 commits into from
Jul 22, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a136697
Port backend/jvm/ivy_utils.py (removes __cmp__)
Jul 10, 2018
4114770
Port backend/jvm tests
Jul 10, 2018
dd5bd45
Port backend/jvm src code
Jul 10, 2018
6eacc04
Remove unnecessary call to list() in for looop
Jul 10, 2018
1f92395
Port fs engine datatype() instances
Jul 12, 2018
3a0ce56
Port backend/jvm/ivy_utils.py (removes __cmp__)
Jul 10, 2018
343c39c
Port backend/jvm tests
Jul 10, 2018
71059dc
Port backend/jvm src code
Jul 10, 2018
e456a75
Remove unnecessary call to list() in for looop
Jul 10, 2018
3afd237
Merge branch 'port-engine-fs' into port-backend-jvm
Jul 12, 2018
6c1b037
Fix additional usages of engine/fs.py objects
Jul 12, 2018
2fc43c8
Merge branch 'port-engine-fs' into port-backend-jvm
Jul 12, 2018
0f8dd8b
Allow Rust to store `unicode` as well as `bytes`
illicitonion Jul 13, 2018
d10fa27
Merge branch 'rust_unicode' into port-engine-fs
Jul 13, 2018
b218681
Use unicode with DirectoryDigest instead of bytes
Jul 13, 2018
c88c721
Merge branch 'port-engine-fs' into port-backend-jvm
Jul 13, 2018
1159a63
Merge branch 'master' into port-backend-jvm
Jul 15, 2018
dbaaebd
Merge branch 'master' into port-backend-jvm
Jul 15, 2018
aea9fc4
Remove bad merge
Jul 15, 2018
0bdbbbb
Replace unnecessary future.moves.collections imports with native imports
Jul 15, 2018
0573294
bump python version
Jul 16, 2018
d0d2089
Revert travis.yml change to Python 2.7.15
Jul 17, 2018
3ad9956
Merge branch 'master' into port-backend-jvm
Jul 18, 2018
a82e4fd
Merge branch 'master' into port-backend-jvm
Jul 18, 2018
762f9b3
Merge remote-tracking branch 'upstream/master' into port-backend-jvm
Jul 18, 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
6 changes: 5 additions & 1 deletion src/python/pants/backend/jvm/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ python_library(
sources=['ivy_utils.py'],
dependencies=[
'3rdparty/python/twitter/commons:twitter.common.collections',
'3rdparty/python:future',
'3rdparty/python:six',
':ivy_utils_resources',
'src/python/pants/backend/jvm/subsystems:jar_dependency_management',
Expand All @@ -71,6 +72,9 @@ resources(
python_library(
name='repository',
sources=['repository.py'],
dependencies = [
'3rdparty/python:future',
]
)

python_library(
Expand All @@ -87,7 +91,7 @@ python_library(
name='ossrh_publication_metadata',
sources=['ossrh_publication_metadata.py'],
dependencies=[
'3rdparty/python:six',
'3rdparty/python:future',
':artifact',
'src/python/pants/base:validation',
],
Expand Down
23 changes: 12 additions & 11 deletions src/python/pants/backend/jvm/ivy_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import threading
import xml.etree.ElementTree as ET
from abc import abstractmethod
from builtins import object, str
from collections import OrderedDict, defaultdict, namedtuple
from functools import total_ordering

import six
from twitter.common.collections import OrderedSet
Expand Down Expand Up @@ -513,6 +515,7 @@ class IvyResolveMappingError(Exception):
"""Raised when there is a failure mapping the ivy resolve results to pants objects."""


@total_ordering
class IvyModuleRef(object):
"""
:API: public
Expand All @@ -533,8 +536,11 @@ def __init__(self, org, name, rev, classifier=None, ext=None):
def __eq__(self, other):
return isinstance(other, IvyModuleRef) and self._id == other._id

def __ne__(self, other):
return not self == other
# TODO(python3port): Return NotImplemented if other does not have attributes
def __lt__(self, other):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced __cmp__ with rich comparisons, which are auto-generated from the @total_ordering annotation.

Same semantics as before

# We can't just re-use __repr__ or __str_ because we want to order rev last
return ((self.org, self.name, self.classifier, self.ext, self.rev) <
(other.org, other.name, other.classifier, other.ext, other.rev))

def __hash__(self):
return hash(self._id)
Expand All @@ -546,11 +552,6 @@ def __repr__(self):
return ('IvyModuleRef(org={!r}, name={!r}, rev={!r}, classifier={!r}, ext={!r})'
.format(*self._id))

def __cmp__(self, other):
# We can't just re-use __repr__ or __str_ because we want to order rev last
return cmp((self.org, self.name, self.classifier, self.ext, self.rev),
(other.org, other.name, other.classifier, other.ext, other.rev))

@property
def caller_key(self):
"""This returns an identifier for an IvyModuleRef that only retains the caller org and name.
Expand Down Expand Up @@ -724,7 +725,7 @@ def _load_classpath_from_cachepath(path):
return []
else:
with safe_open(path, 'r') as cp:
return filter(None, (path.strip() for path in cp.read().split(os.pathsep)))
return [_f for _f in (path.strip() for path in cp.read().split(os.pathsep)) if _f]

@classmethod
def do_resolve(cls, executor, extra_args, ivyxml, jvm_options, workdir_report_paths_by_conf,
Expand Down Expand Up @@ -1097,7 +1098,7 @@ def collect_elements(target):
new_jars[coordinate] = jar.copy(excludes=jar.excludes + additional_excludes)
jars = new_jars

return jars.values(), global_excludes
return list(jars.values()), global_excludes

@classmethod
def _resolve_conflict(cls, existing, proposed):
Expand Down Expand Up @@ -1178,7 +1179,7 @@ def _generate_jar_template(cls, jars):
mutable=jar_attributes.mutable,
force=jar_attributes.force,
transitive=jar_attributes.transitive,
artifacts=artifacts.values(),
artifacts=list(artifacts.values()),
any_have_url=any_have_url,
excludes=[cls._generate_exclude_template(exclude) for exclude in excludes])

Expand Down Expand Up @@ -1222,7 +1223,7 @@ def _generate_fetch_jar_template(cls, jars):
module=jar_attributes.name,
version=jar_attributes.rev,
mutable=jar_attributes.mutable,
artifacts=artifacts.values(),
artifacts=list(artifacts.values()),
any_have_url=any_have_url,
excludes=[])

Expand Down
6 changes: 4 additions & 2 deletions src/python/pants/backend/jvm/ossrh_publication_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import six
from builtins import object

import future

from pants.backend.jvm.artifact import PublicationMetadata
from pants.base.validation import assert_list


def _validate_maybe_string(name, item):
if item and not isinstance(item, six.string_types):
if item and not isinstance(item, future.utils.string_types):
raise ValueError('{} was expected to be of type {} but given {}'.format(name, type(item), item))
return item

Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/jvm/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
unicode_literals, with_statement)

import os
from builtins import object


class Repository(object):
Expand Down
7 changes: 7 additions & 0 deletions src/python/pants/backend/jvm/subsystems/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ python_library(
name = 'dependency_context',
sources = ['dependency_context.py'],
dependencies = [
'3rdparty/python:future',
':java',
':scala_platform',
'src/python/pants/backend/codegen/thrift/java',
Expand All @@ -18,6 +19,7 @@ python_library(
name = 'jvm_tool_mixin',
sources = ['jvm_tool_mixin.py'],
dependencies = [
'3rdparty/python:future',
'src/python/pants/base:exceptions',
'src/python/pants/java/distribution',
'src/python/pants/option',
Expand Down Expand Up @@ -75,6 +77,7 @@ python_library(
name = 'jvm_platform',
sources = ['jvm_platform.py'],
dependencies = [
'3rdparty/python:future',
'src/python/pants/base:exceptions',
'src/python/pants/base:revision',
'src/python/pants/option',
Expand All @@ -88,6 +91,7 @@ python_library(
name = 'jar_dependency_management',
sources = ['jar_dependency_management.py'],
dependencies = [
'3rdparty/python:future',
'src/python/pants/backend/jvm/targets:jvm',
'src/python/pants/base:revision',
'src/python/pants/build_graph',
Expand Down Expand Up @@ -115,6 +119,7 @@ python_library(
name = 'shader',
sources = ['shader.py'],
dependencies = [
'3rdparty/python:future',
'src/python/pants/java/jar',
'src/python/pants/backend/jvm/tasks:classpath_util',
'src/python/pants/backend/jvm/tasks:jvm_tool_task_mixin',
Expand All @@ -131,6 +136,7 @@ python_library(
name = 'zinc',
sources = ['zinc.py'],
dependencies = [
'3rdparty/python:future',
':dependency_context',
':jvm_tool_mixin',
':shader',
Expand All @@ -142,6 +148,7 @@ python_library(
name = 'zinc_language_mixin',
sources = ['zinc_language_mixin.py'],
dependencies = [
'3rdparty/python:future',
'src/python/pants/subsystem',
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
unicode_literals, with_statement)

import hashlib
from builtins import str

from pants.backend.jvm.subsystems.java import Java
from pants.backend.jvm.subsystems.scala_platform import ScalaPlatform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
unicode_literals, with_statement)

import logging
from builtins import map, next, object
from collections import defaultdict
from textwrap import dedent

Expand Down Expand Up @@ -255,7 +256,7 @@ def __iter__(self):
def __len__(self):
return len(self._artifacts_to_versions)

def __nonzero__(self):
def __bool__(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from builtins import object means that this will implement __nonzero__ for us if Py2

Copy link
Contributor Author

@Eric-Arellano Eric-Arellano Jul 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found through porting another module that this automatic implementation of __nonzero__ only holds if the class inherits the backported object. If it inherits another class, then there will be no __nonzero__ implementation.

I think it’s likely safe to assume this won’t be subclassesed by something other than object anytime soon, but I can remove this deletion if we prefer to use the more explicit implementation of both __bool__ and __nonzero__.

return len(self) > 0

def __contains__(self, artifact):
Expand Down
11 changes: 6 additions & 5 deletions src/python/pants/backend/jvm/subsystems/jvm_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
unicode_literals, with_statement)

import logging
from builtins import object, str
from functools import total_ordering

from pants.base.exceptions import TaskError
from pants.base.revision import Revision
Expand Down Expand Up @@ -185,6 +187,7 @@ def parse_java_version(cls, version):
return Revision(*version.components[:2])


@total_ordering
class JvmPlatformSettings(object):
"""Simple information holder to keep track of common arguments to java compilers."""

Expand Down Expand Up @@ -231,15 +234,13 @@ def __iter__(self):
def __eq__(self, other):
return tuple(self) == tuple(other)

def __ne__(self, other):
return not self.__eq__(other)
# TODO(python3port): decide if this should raise NotImplemented on invalid comparisons
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto on replacing __cmp__ with rich comparisons

Same semantics as before

def __lt__(self, other):
return tuple(self) < tuple(other)

def __hash__(self):
return hash(tuple(self))

def __cmp__(self, other):
return cmp(tuple(self), tuple(other))

def __str__(self):
return 'source={source},target={target},args=({args})'.format(
source=self.source_level,
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/jvm/subsystems/jvm_tool_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from builtins import object
from collections import namedtuple
from textwrap import dedent

Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/jvm/subsystems/shader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import os
import re
from builtins import object
from collections import namedtuple
from contextlib import contextmanager

Expand Down
2 changes: 2 additions & 0 deletions src/python/pants/backend/jvm/subsystems/zinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from builtins import object

from pants.backend.jvm.subsystems.dependency_context import DependencyContext
from pants.backend.jvm.subsystems.java import Java
from pants.backend.jvm.subsystems.jvm_tool_mixin import JvmToolMixin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from builtins import object


class ZincLanguageMixin(object):
"""A mixin for subsystems for languages compiled with Zinc."""
Expand Down
3 changes: 1 addition & 2 deletions src/python/pants/backend/jvm/targets/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ python_library(
dependencies = [
'3rdparty/python/twitter/commons:twitter.common.collections',
'3rdparty/python/twitter/commons:twitter.common.dirutil',
'3rdparty/python:six',
'3rdparty/python:future',
'src/python/pants/java/jar',
'src/python/pants/backend/jvm/subsystems:java',
'src/python/pants/backend/jvm/subsystems:junit',
Expand Down Expand Up @@ -59,7 +59,6 @@ python_library(
'javac_plugin.py',
],
dependencies = [
'3rdparty/python:six',
':jvm',
'src/python/pants/backend/jvm/subsystems:java',
'src/python/pants/backend/jvm/subsystems:junit',
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/jvm/targets/import_jars_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import six
import future

from pants.backend.jvm.targets.jar_library import JarLibrary
from pants.build_graph.address_lookup_error import AddressLookupError
Expand Down Expand Up @@ -53,7 +53,7 @@ def gen_specs():
for item in target_representation.get(fields_tuple[field_pos], ()):
# For better error handling, this simply skips over non-strings, but we catch them
# with a WrongTargetType in JarLibrary.to_jar_dependencies.
if not isinstance(item, six.string_types):
if not isinstance(item, future.utils.string_types):
raise JarLibrary.ExpectedAddressError(
'expected imports to contain string addresses, got {found_class} instead.'
.format(found_class=type(item).__name__)
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/jvm/targets/jar_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import six
import future
from twitter.common.collections import OrderedSet

from pants.base.exceptions import TargetDefinitionException
Expand Down Expand Up @@ -99,7 +99,7 @@ def to_jar_dependencies(relative_to, jar_library_specs, build_graph):
"""
jar_deps = OrderedSet()
for spec in jar_library_specs:
if not isinstance(spec, six.string_types):
if not isinstance(spec, future.utils.string_types):
raise JarLibrary.ExpectedAddressError(
"{address}: expected imports to contain string addresses, got {found_class}."
.format(address=relative_to.spec,
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/jvm/targets/java_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from six import string_types
from future.utils import string_types

from pants.backend.jvm.targets.java_library import JavaLibrary
from pants.base.exceptions import TargetDefinitionException
Expand Down
2 changes: 2 additions & 0 deletions src/python/pants/backend/jvm/targets/junit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from builtins import str

from pants.backend.jvm.subsystems.junit import JUnit
from pants.backend.jvm.subsystems.jvm_platform import JvmPlatform
from pants.backend.jvm.targets.jvm_target import JvmTarget
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/backend/jvm/targets/jvm_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import re
from hashlib import sha1

from six import string_types
from future.utils import string_types

from pants.backend.jvm.targets.jvm_target import JvmTarget
from pants.base.exceptions import TargetDefinitionException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import copy
import os
from builtins import object

from pants.base.exceptions import TargetDefinitionException
from pants.base.payload import Payload
Expand Down
Loading