Skip to content

Commit

Permalink
2.2.0.dev1 deprecations. (#11281)
Browse files Browse the repository at this point in the history
- Remove deprecated class-based test infrastructure.
- Remove deprecated global option.
- Deprecate unused global options.
- Fix scheduler-related type annotation.

[ci skip-rust]

[ci skip-build-wheels]
  • Loading branch information
benjyw authored Dec 10, 2020
1 parent dfff814 commit bde37bd
Show file tree
Hide file tree
Showing 24 changed files with 256 additions and 740 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,6 @@ def test_coverage_html_xml_json() -> None:
assert html_cov_dir.exists() is True
assert (html_cov_dir / "index.html").exists() is True

assert "Wrote json coverage report to `dist/coverage/python`" in result.stderr_data
assert "Wrote json coverage report to `dist/coverage/python`" in result.stderr
json_coverage = coverage_path / "coverage.json"
assert json_coverage.exists() is True
10 changes: 6 additions & 4 deletions src/python/pants/backend/python/macros/python_requirements.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import os
from pathlib import Path
from typing import Iterable, Mapping, Optional

Expand Down Expand Up @@ -81,10 +81,12 @@ def __call__(
)
requirements.append(req)

self._parse_context.create_object(
"_python_requirements_file", name=requirements_relpath, sources=[requirements_relpath]
req_file_tgt = self._parse_context.create_object(
"_python_requirements_file",
name=requirements_relpath.replace(os.path.sep, "_"),
sources=[requirements_relpath],
)
requirements_dep = f":{requirements_relpath}"
requirements_dep = f":{req_file_tgt.name}"

for parsed_req in requirements:
req_module_mapping = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ def test_relpath_override(rule_runner: RuleRunner) -> None:
requirements_txt_relpath="subdir/requirements.txt",
expected_file_dep=PythonRequirementsFile(
{"sources": ["subdir/requirements.txt"]},
address=Address("", target_name="subdir/requirements.txt"),
address=Address("", target_name="subdir_requirements.txt"),
),
expected_targets=[
PythonRequirementLibrary(
{
"dependencies": [":subdir/requirements.txt"],
"dependencies": [":subdir_requirements.txt"],
"requirements": [Requirement.parse("ansicolors>=1.18.0")],
},
address=Address("", target_name="ansicolors"),
Expand Down
11 changes: 0 additions & 11 deletions src/python/pants/base/build_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ def get_pants_cachedir() -> str:
return os.path.expanduser(os.path.join(cache_home, "pants"))


def get_pants_configdir() -> str:
"""Return the pants global config directory."""
# TODO: Keep in alignment with rust `fs::default_config_path`. This method
# is not used there directly because it would create a cycle for native bootstrap via
# BinaryUtil being used to download tools needed to bootstrap.
config_home = os.environ.get("XDG_CONFIG_HOME")
if not config_home:
config_home = "~/.config"
return os.path.expanduser(os.path.join(config_home, "pants"))


def get_default_pants_config_file() -> str:
"""Return the default location of the Pants config file."""
return os.path.join(get_buildroot(), "pants.toml")
Expand Down
22 changes: 1 addition & 21 deletions src/python/pants/base/build_environment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import os
import unittest

from pants.base.build_environment import get_pants_cachedir, get_pants_configdir
from pants.base.build_environment import get_pants_cachedir
from pants.engine.internals.native import Native
from pants.util.contextutil import environment_as, temporary_file

Expand All @@ -13,34 +13,14 @@ def test_get_pants_cachedir() -> None:
assert Native().default_cache_path() == get_pants_cachedir()


def test_get_pants_configdir() -> None:
assert Native().default_config_path() == get_pants_configdir()


class TestBuildEnvironment(unittest.TestCase):
"""Test class for pants.base.build_environment."""

def test_get_configdir(self) -> None:
with environment_as(XDG_CONFIG_HOME=""):
self.assertEqual(os.path.expanduser("~/.config/pants"), get_pants_configdir())

def test_get_cachedir(self) -> None:
with environment_as(XDG_CACHE_HOME=""):
self.assertEqual(os.path.expanduser("~/.cache/pants"), get_pants_cachedir())

def test_set_configdir(self) -> None:
with temporary_file() as temp:
with environment_as(XDG_CONFIG_HOME=temp.name):
self.assertEqual(os.path.join(temp.name, "pants"), get_pants_configdir())

def test_set_cachedir(self) -> None:
with temporary_file() as temp:
with environment_as(XDG_CACHE_HOME=temp.name):
self.assertEqual(os.path.join(temp.name, "pants"), get_pants_cachedir())

def test_expand_home_configdir(self) -> None:
with environment_as(XDG_CONFIG_HOME="~/somewhere/in/home"):
self.assertEqual(
os.path.expanduser(os.path.join("~/somewhere/in/home", "pants")),
get_pants_configdir(),
)
4 changes: 2 additions & 2 deletions src/python/pants/base/parse_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def create_object(self, alias, *args, **kwargs):
:param alias: Either the type alias or the type itself.
:type alias: string|type
:param *args: These pass through to the underlying callable object.
:param **kwargs: These pass through to the underlying callable object.
:param args: These pass through to the underlying callable object.
:param kwargs: These pass through to the underlying callable object.
:returns: The created object.
"""
object_type = self._type_aliases.get(alias)
Expand Down
21 changes: 3 additions & 18 deletions src/python/pants/build_graph/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pathlib import PurePath
from typing import Optional, Sequence

from pants.base.deprecated import warn_or_error
from pants.engine.engine_aware import EngineAwareParameter
from pants.util.dirutil import fast_relpath, longest_dir_prefix
from pants.util.strutil import strip_prefix
Expand Down Expand Up @@ -234,25 +233,11 @@ def __init__(
self._target_name: Optional[str]
if target_name and target_name != os.path.basename(self.spec_path):
banned_chars = BANNED_CHARS_IN_TARGET_NAME & set(target_name)
deprecated_banned_chars = banned_chars & set(r"/\:")
if deprecated_banned_chars:
warn_or_error(
removal_version="2.2.0.dev1",
deprecated_entity_description=(
r"Using any of the `\`, `/`, or `:` characters in a target name."
),
hint=(
f"The target name {target_name} (defined in directory {self.spec_path}) "
f"contains deprecated characters (`{deprecated_banned_chars}`), which will "
"cause some usecases to fail. Please replace these characters with another "
"separator character like `_` or `-`."
),
)
elif banned_chars:
if banned_chars:
raise InvalidTargetName(
f"The target name {target_name} (defined in directory {self.spec_path}) "
f"contains banned characters (`{banned_chars}`). Please replace these "
"characters with another separator character like `_` or `-`."
f"contains banned characters (`{'`,`'.join(banned_chars)}`). Please replace "
"these characters with another separator character like `_` or `-`."
)
self._target_name = target_name
else:
Expand Down
8 changes: 1 addition & 7 deletions src/python/pants/build_graph/address_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import warnings
from typing import Optional

import pytest
Expand Down Expand Up @@ -111,12 +110,7 @@ def assert_bad_target_component(spec: str) -> None:
assert_bad_target_component("//:!t")
assert_bad_target_component("//:?t")
assert_bad_target_component("//:=t")

# Deprecated banned chars. This should convert into an error in `2.2.0.dev1`.
with warnings.catch_warnings(record=True) as w:
AddressInput.parse(r"a:b\c").dir_to_address()
assert len(w) == 1
assert "deprecated" in str(w[0].message)
assert_bad_target_component(r"a:b\c")


def test_subproject_spec() -> None:
Expand Down
Loading

0 comments on commit bde37bd

Please sign in to comment.