Skip to content

Commit

Permalink
Properly deprecate the Dependencies alias.
Browse files Browse the repository at this point in the history
I killed the Dependencies/DeprecatedDependencies dichotomy,
since we now have a proper deprecation mechanism. I left
the Dependencies name because that's the one that may still be
used externally.

Testing Done:
CI passes: https://travis-ci.org/pantsbuild/pants/builds/94305475

Reviewed at https://rbcommons.com/s/twitter/r/3196/
  • Loading branch information
benjyw authored and Benjy committed Dec 2, 2015
1 parent fb30d2d commit 79a6794
Show file tree
Hide file tree
Showing 21 changed files with 52 additions and 55 deletions.
8 changes: 4 additions & 4 deletions src/python/pants/backend/core/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import sys

from pants.backend.core.from_target import FromTarget
from pants.backend.core.targets.dependencies import Dependencies, DeprecatedDependencies
from pants.backend.core.targets.dependencies import Dependencies
from pants.backend.core.targets.doc import Page, Wiki, WikiArtifact
from pants.backend.core.targets.prep_command import PrepCommand
from pants.backend.core.targets.resources import Resources
Expand Down Expand Up @@ -39,6 +39,7 @@
from pants.base.build_environment import get_buildroot, pants_version
from pants.base.source_root import SourceRoot
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.build_graph.target import Target
from pants.goal.task_registrar import TaskRegistrar as task


Expand All @@ -55,12 +56,11 @@ def __call__(self):
def build_file_aliases():
return BuildFileAliases(
targets={
# NB: the 'dependencies' alias is deprecated in favor of the 'target' alias
'dependencies': DeprecatedDependencies,
'dependencies': Dependencies, # Deprecated, will be removed soon.
'page': Page,
'prep_command': PrepCommand,
'resources': Resources,
'target': Dependencies,
'target': Target,
},
objects={
'ConfluencePublish': ConfluencePublish,
Expand Down
1 change: 1 addition & 0 deletions src/python/pants/backend/core/targets/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ python_library(
'resources.py',
],
dependencies = [
'src/python/pants/base:deprecated',
'src/python/pants/base:payload',
'src/python/pants/base:payload_field',
'src/python/pants/build_graph',
Expand Down
18 changes: 5 additions & 13 deletions src/python/pants/backend/core/targets/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,19 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

import logging

from pants.base.deprecated import deprecated
from pants.build_graph.target import Target


logger = logging.getLogger(__name__)


class Dependencies(Target):
"""A set of dependencies that may be depended upon,
as if depending upon the set of dependencies directly.
NB: This class is commonly referred to by the alias 'target' in BUILD files.
"""


class DeprecatedDependencies(Dependencies):
"""A subclass for Dependencies that warns that the 'dependencies' alias is deprecated."""

@deprecated('0.0.64', 'Replace dependencies(...) with target(...) in your BUILD files. '
'Replace uses of Dependencies with Target in your code.')
def __init__(self, *args, **kwargs):
logger.warn("For {0} : The alias 'dependencies(..)' has been deprecated in favor of "
"'target(..)'"
.format(kwargs['address'].spec))
super(DeprecatedDependencies, self).__init__(*args, **kwargs)
raise RuntimeError('For {}: dependencies(...) targets no longer work. Replace with '
'target(...) in your BUILD files.'.format(kwargs['address'].spec))
1 change: 1 addition & 0 deletions src/python/pants/backend/jvm/tasks/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ python_library(
':jvm_dependency_analyzer',
'src/python/pants/backend/jvm/targets:jvm',
'src/python/pants/base:build_environment',
'src/python/pants/build_graph',
'src/python/pants/util:fileutil',
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import os
from collections import defaultdict

from pants.backend.core.targets.dependencies import Dependencies
from pants.backend.core.targets.resources import Resources
from pants.backend.core.tasks.group_task import GroupMember
from pants.backend.jvm.subsystems.java import Java
Expand Down Expand Up @@ -548,7 +547,7 @@ def _compute_strict_dependencies(self, target):
"""
def resolve(t):
for declared in t.dependencies:
if isinstance(declared, Dependencies) or type(declared) == Target:
if type(declared) == Target:
for r in resolve(declared):
yield r
elif isinstance(declared, self.compiler_plugin_types):
Expand Down
10 changes: 4 additions & 6 deletions src/python/pants/backend/jvm/tasks/jvm_dependency_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
import json
import os
import sys
from collections import OrderedDict, defaultdict, namedtuple
from collections import defaultdict, namedtuple

from pants.backend.core.targets.dependencies import Dependencies
from pants.backend.core.targets.resources import Resources
from pants.backend.jvm.targets.jar_library import JarLibrary
from pants.backend.jvm.tasks.classpath_util import ClasspathUtil
Expand Down Expand Up @@ -80,7 +79,7 @@ def execute(self):
with open(output_file, 'w') as fh:
self._render(graph, fh)
else:
sys.stdout.write('\n')
sys.stdout.write(b'\n')
self._render(graph, sys.stdout)

def _render(self, graph, fh):
Expand All @@ -92,7 +91,7 @@ def _render(self, graph, fh):
def _resolve_aliases(self, target):
"""Recursively resolve `target` aliases."""
for declared in target.dependencies:
if isinstance(declared, Dependencies) or type(declared) == Target:
if type(declared) == Target:
for r in self._resolve_aliases(declared):
yield r
else:
Expand All @@ -105,8 +104,7 @@ def _is_declared_dep(self, target, dep):
def _select(self, target):
if self.get_options().internal_only and isinstance(target, JarLibrary):
return False
elif isinstance(target, (Dependencies, Resources)) or type(target) == Target:
# ignore aliases and resources
elif isinstance(target, Resources) or type(target) == Target:
return False
else:
return True
Expand Down
2 changes: 2 additions & 0 deletions src/python/pants/backend/python/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ python_library(
':python_requirements',
'src/python/pants/backend/python/targets:python',
'src/python/pants/backend/python/tasks:python',
'src/python/pants/base:deprecated',
'src/python/pants/build_graph',
'src/python/pants/goal:task_registrar',
]
Expand Down Expand Up @@ -116,6 +117,7 @@ python_library(
'src/python/pants/backend/core/targets:common',
'src/python/pants/backend/python/targets:python',
'src/python/pants/base:build_environment',
'src/python/pants/build_graph',
'src/python/pants/invalidation',
'src/python/pants/util:dirutil'
],
Expand Down
4 changes: 2 additions & 2 deletions src/python/pants/backend/python/python_chroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

from pants.backend.codegen.targets.python_antlr_library import PythonAntlrLibrary
from pants.backend.codegen.targets.python_thrift_library import PythonThriftLibrary
from pants.backend.core.targets.dependencies import Dependencies
from pants.backend.core.targets.prep_command import PrepCommand
from pants.backend.core.targets.resources import Resources
from pants.backend.python.antlr_builder import PythonAntlrBuilder
Expand All @@ -31,6 +30,7 @@
from pants.backend.python.targets.python_tests import PythonTests
from pants.backend.python.thrift_builder import PythonThriftBuilder
from pants.base.build_environment import get_buildroot
from pants.build_graph.target import Target
from pants.invalidation.build_invalidator import BuildInvalidator, CacheKeyGenerator
from pants.util.dirutil import safe_mkdir, safe_mkdtemp, safe_rmtree

Expand Down Expand Up @@ -184,7 +184,7 @@ def add_dep(trg):
if isinstance(trg, target_type):
children[target_key].add(trg)
return
elif isinstance(trg, Dependencies):
elif type(trg) == Target:
return
raise self.InvalidDependencyException(trg)
for target in targets:
Expand Down
13 changes: 11 additions & 2 deletions src/python/pants/backend/python/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants.backend.core.targets.dependencies import Dependencies
from pants.backend.python.pants_requirement import pants_requirement
from pants.backend.python.python_artifact import PythonArtifact
from pants.backend.python.python_requirement import PythonRequirement
Expand All @@ -19,17 +18,27 @@
from pants.backend.python.tasks.python_repl import PythonRepl
from pants.backend.python.tasks.python_run import PythonRun
from pants.backend.python.tasks.setup_py import SetupPy
from pants.base.deprecated import deprecated
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.build_graph.target import Target
from pants.goal.task_registrar import TaskRegistrar as task


class PythonTestSuite(Target):
@deprecated('0.0.64', 'Replace python_test_suite(...) with target(...) in your BUILD files. '
'Replace uses of PythonTestSuite with Target in your code.')
def __init__(self, *args, **kwargs):
raise RuntimeError('For {}: python_test_suite(...) targets no longer work. Replace with '
'target(...) in your BUILD files.'.format(kwargs['address'].spec))


def build_file_aliases():
return BuildFileAliases(
targets={
'python_binary': PythonBinary,
'python_library': PythonLibrary,
'python_requirement_library': PythonRequirementLibrary,
'python_test_suite': Dependencies, # Legacy alias.
'python_test_suite': PythonTestSuite,
'python_tests': PythonTests,
},
objects={
Expand Down
4 changes: 2 additions & 2 deletions tests/python/pants_test/backend/core/tasks/test_dependees.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from textwrap import dedent

from pants.backend.codegen.targets.java_thrift_library import JavaThriftLibrary
from pants.backend.core.targets.dependencies import Dependencies
from pants.backend.core.targets.resources import Resources
from pants.backend.core.tasks.dependees import ReverseDepmap
from pants.backend.jvm.targets.jar_dependency import JarDependency
Expand All @@ -18,6 +17,7 @@
from pants.backend.python.targets.python_library import PythonLibrary
from pants.backend.python.targets.python_tests import PythonTests
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.build_graph.target import Target
from pants_test.tasks.task_test_base import ConsoleTaskTestBase


Expand Down Expand Up @@ -48,7 +48,7 @@ class ReverseDepmapTest(BaseReverseDepmapTest):
def alias_groups(self):
return BuildFileAliases(
targets={
'target': Dependencies,
'target': Target,
'jar_library': JarLibrary,
'java_library': JavaLibrary,
'java_thrift_library': JavaThriftLibrary,
Expand Down
4 changes: 2 additions & 2 deletions tests/python/pants_test/backend/core/tasks/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

from textwrap import dedent

from pants.backend.core.targets.dependencies import Dependencies
from pants.backend.core.targets.doc import Page
from pants.backend.core.tasks.filter import Filter
from pants.backend.jvm.targets.java_library import JavaLibrary
from pants.backend.python.targets.python_library import PythonLibrary
from pants.backend.python.targets.python_requirement_library import PythonRequirementLibrary
from pants.base.exceptions import TaskError
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.build_graph.target import Target
from pants_test.tasks.task_test_base import ConsoleTaskTestBase


Expand All @@ -24,7 +24,7 @@ class BaseFilterTest(ConsoleTaskTestBase):
def alias_groups(self):
return BuildFileAliases(
targets={
'target': Dependencies,
'target': Target,
'java_library': JavaLibrary,
'page': Page,
'python_library': PythonLibrary,
Expand Down
2 changes: 1 addition & 1 deletion tests/python/pants_test/backend/jvm/tasks/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ python_tests(
dependencies = [
'src/python/pants/backend/jvm/targets:jvm',
'src/python/pants/backend/jvm/tasks:jvm_platform_analysis',
'src/python/pants/util:contextutil',
'src/python/pants/build_graph',
'tests/python/pants_test/tasks:task_test_base',
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import os
from textwrap import dedent

from pants.backend.core.targets.dependencies import Dependencies
from pants.backend.jvm.artifact import Artifact
from pants.backend.jvm.repository import Repository
from pants.backend.jvm.scala_artifact import ScalaArtifact
Expand All @@ -18,6 +17,7 @@
from pants.backend.jvm.targets.scala_jar_dependency import ScalaJarDependency
from pants.backend.jvm.tasks.check_published_deps import CheckPublishedDeps
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.build_graph.target import Target
from pants_test.tasks.task_test_base import ConsoleTaskTestBase


Expand All @@ -27,7 +27,7 @@ class CheckPublishedDepsTest(ConsoleTaskTestBase):
def alias_groups(self):
return BuildFileAliases(
targets={
'target': Dependencies,
'target': Target,
'jar_library': JarLibrary,
'java_library': JavaLibrary,
},
Expand Down
5 changes: 2 additions & 3 deletions tests/python/pants_test/backend/jvm/tasks/test_jar_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import os
import unittest

import pytest
from mock import Mock

from pants.backend.core.targets.dependencies import Dependencies
from pants.backend.jvm.artifact import Artifact
from pants.backend.jvm.repository import Repository
from pants.backend.jvm.scala_artifact import ScalaArtifact
Expand All @@ -20,6 +18,7 @@
from pants.backend.jvm.tasks.jar_publish import JarPublish
from pants.base.exceptions import TaskError
from pants.build_graph.build_file_aliases import BuildFileAliases
from pants.build_graph.target import Target
from pants.scm.scm import Scm
from pants.util.contextutil import temporary_dir
from pants.util.dirutil import safe_mkdir, safe_walk
Expand Down Expand Up @@ -48,7 +47,7 @@ def alias_groups(self):
targets={
'jar_library': JarLibrary,
'java_library': JavaLibrary,
'target': Dependencies,
'target': Target,
},
objects={
'artifact': Artifact,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants.backend.core.targets.dependencies import Dependencies
from pants.backend.jvm.targets.java_library import JavaLibrary
from pants.backend.jvm.tasks.jvm_platform_analysis import JvmPlatformExplain, JvmPlatformValidate
from pants.build_graph.target import Target
from pants_test.tasks.task_test_base import TaskTestBase


Expand All @@ -27,7 +27,7 @@ def _java(self, name, platform=None, deps=None, sources=None):
def _plain(self, name, deps=None):
"""Make a non-jvm target, useful for testing non-jvm intermediate dependencies."""
return self.make_target(spec='java:{}'.format(name),
target_type=Dependencies,
target_type=Target,
dependencies=deps or [],)

def simple_task(self, targets, **options):
Expand Down
2 changes: 2 additions & 0 deletions tests/python/pants_test/backend/project_info/tasks/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ python_tests(
'src/python/pants/backend/project_info/tasks:dependencies',
'src/python/pants/backend/python/targets:python',
'src/python/pants/backend/python:python_requirement',
'src/python/pants/build_graph',
'tests/python/pants_test/tasks:task_test_base',
]
)
Expand Down Expand Up @@ -80,6 +81,7 @@ python_tests(
'src/python/pants/backend/project_info/tasks:export',
'src/python/pants/backend/python:plugin',
'src/python/pants/base:exceptions',
'src/python/pants/build_graph',
'tests/python/pants_test/subsystem:subsystem_utils',
'tests/python/pants_test/tasks:task_test_base',
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from __future__ import (absolute_import, division, generators, nested_scopes, print_function,
unicode_literals, with_statement)

from pants.backend.core.targets.dependencies import Dependencies as DepBag
from pants.backend.jvm.targets.jar_dependency import JarDependency
from pants.backend.jvm.targets.jar_library import JarLibrary
from pants.backend.jvm.targets.java_library import JavaLibrary
from pants.backend.project_info.tasks.dependencies import Dependencies
from pants.backend.python.python_requirement import PythonRequirement
from pants.backend.python.targets.python_library import PythonLibrary
from pants.backend.python.targets.python_requirement_library import PythonRequirementLibrary
from pants.build_graph.target import Target
from pants_test.tasks.task_test_base import ConsoleTaskTestBase


Expand Down Expand Up @@ -65,7 +65,7 @@ def setUp(self):

self.make_target(
'project:dep-bag',
target_type=DepBag,
target_type=Target,
dependencies=[
second,
project
Expand Down
Loading

0 comments on commit 79a6794

Please sign in to comment.