Skip to content

Commit

Permalink
Port contrib/node to py3 (#6158)
Browse files Browse the repository at this point in the history
Mostly imports, an occasional cast to list.
Largest change perhaps was the dict comp in test_node_task.py

### Problem

port to py3

### Solution

only significant change:
   -- type_check_results = [(type, type_check_function(self.make_target(target_name, type)))
                          for (type, target_name) in types_with_target_names]
   ++ type_check_results = {type: type_check_function(self.make_target(target_name, type))
                          for type, target_name in types_with_target_names}

   -- return dict(type_check_results)
   ++ return type_check_results
  • Loading branch information
GoingTharn authored and Stu Hood committed Jul 20, 2018
1 parent 4670779 commit 1be6113
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 11 deletions.
Expand Up @@ -3,6 +3,7 @@

python_library(
dependencies=[
'3rdparty/python:future',
'src/python/pants/base:deprecated',
'src/python/pants/binaries',
'src/python/pants/subsystem',
Expand Down
Expand Up @@ -77,7 +77,7 @@ def get_package_manager(self, package_manager=None):
if not package_manager_obj:
raise TaskError(
'Unknown package manager: {}.\nValid values are {}.'.format(
package_manager, NodeDistribution.VALID_PACKAGE_MANAGER_LIST.keys()
package_manager, list(NodeDistribution.VALID_PACKAGE_MANAGER_LIST.keys())
))
return package_manager_obj

Expand Down
Expand Up @@ -5,6 +5,7 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import logging
from builtins import object

from pants.contrib.node.subsystems.command import command_gen

Expand Down
6 changes: 5 additions & 1 deletion contrib/node/src/python/pants/contrib/node/tasks/BUILD
Expand Up @@ -15,7 +15,10 @@ target(

python_library(
name='node_paths',
sources=['node_paths.py']
sources=['node_paths.py'],
dependencies = [
'3rdparty/python:future',
],
)

python_library(
Expand Down Expand Up @@ -58,6 +61,7 @@ python_library(
name='node_task',
sources=['node_task.py'],
dependencies=[
'3rdparty/python:future',
'contrib/node/src/python/pants/contrib/node/subsystems',
'contrib/node/src/python/pants/contrib/node/targets:node_bundle',
'contrib/node/src/python/pants/contrib/node/targets:node_module',
Expand Down
Expand Up @@ -43,12 +43,10 @@ def fix(self):
raise NotImplementedError()

def get_lintable_node_targets(self, targets):
return filter(
lambda target: isinstance(target, NodeModule)
return [target for target in targets if isinstance(target, NodeModule)
and (target.has_sources(self._JS_SOURCE_EXTENSION)
or target.has_sources(self._JSX_SOURCE_EXTENSION))
and (not target.is_synthetic),
targets)
and (not target.is_synthetic)]

def get_javascript_sources(self, target):
sources = set()
Expand Down
Expand Up @@ -4,6 +4,8 @@

from __future__ import absolute_import, division, print_function, unicode_literals

from builtins import object


# TODO(John Sirois): UnionProducts? That seems broken though for ranged version constraints,
# which npm has and are widely used in the community. For now stay dumb simple (and slow) and
Expand Down Expand Up @@ -38,4 +40,4 @@ def all_node_paths(self):
:rtype list string
"""
return self._paths_by_target.values()
return list(self._paths_by_target.values())
2 changes: 2 additions & 0 deletions contrib/node/src/python/pants/contrib/node/tasks/node_task.py
Expand Up @@ -4,6 +4,8 @@

from __future__ import absolute_import, division, print_function, unicode_literals

from builtins import str

from pants.base.workunit import WorkUnit, WorkUnitLabel
from pants.task.task import Task
from pants.util.memo import memoized_property
Expand Down
2 changes: 2 additions & 0 deletions contrib/node/tests/python/pants_test/contrib/node/tasks/BUILD
Expand Up @@ -73,6 +73,7 @@ python_tests(
name='node_test_integration',
sources=['test_node_test_integration.py'],
dependencies=[
'3rdparty/python:future',
'tests/python/pants_test:int-test',
],
timeout=240,
Expand All @@ -83,6 +84,7 @@ python_tests(
name='node_task',
sources=['test_node_task.py'],
dependencies=[
'3rdparty/python:future',
'contrib/node/src/python/pants/contrib/node/targets:node_module',
'contrib/node/src/python/pants/contrib/node/targets:node_remote_module',
'contrib/node/src/python/pants/contrib/node/targets:node_test',
Expand Down
Expand Up @@ -57,7 +57,7 @@ def test_node_deployable_bundle(self):

product_data = product.get(target)
self.assertIsNotNone(product_data)
product_basedir = product_data.keys()[0]
product_basedir = list(product_data.keys())[0]
self.assertEquals(product_data[product_basedir], ['{}.tar.gz'.format(self.target_name)])

def test_no_dependencies_for_node_bundle(self):
Expand Down
Expand Up @@ -7,6 +7,7 @@
import json
import os
import string
from builtins import zip
from textwrap import dedent

from pants.build_graph.target import Target
Expand Down Expand Up @@ -76,10 +77,10 @@ def _type_check(self, types, type_check_function):
target_names = [':' + letter for letter in list(string.ascii_lowercase)]
types_with_target_names = zip(types, target_names)

type_check_results = [(type, type_check_function(self.make_target(target_name, type)))
for (type, target_name) in types_with_target_names]
type_check_results = {type: type_check_function(self.make_target(target_name, type))
for type, target_name in types_with_target_names}

return dict(type_check_results)
return type_check_results

def test_execute_node(self):
task = self.create_task(self.context())
Expand Down
Expand Up @@ -4,6 +4,8 @@

from __future__ import absolute_import, division, print_function, unicode_literals

from builtins import range

from pants_test.pants_run_integration_test import PantsRunIntegrationTest


Expand Down

0 comments on commit 1be6113

Please sign in to comment.