Skip to content

Commit

Permalink
Remove the Scm interface
Browse files Browse the repository at this point in the history
# Rust tests and lints will be skipped. Delete if not intended.
[ci skip-rust]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
  • Loading branch information
Eric-Arellano committed Sep 30, 2020
1 parent efef4c5 commit 6fe997c
Show file tree
Hide file tree
Showing 17 changed files with 70 additions and 196 deletions.
37 changes: 11 additions & 26 deletions src/python/pants/base/build_environment.py
Expand Up @@ -6,7 +6,7 @@
from typing import Optional

from pants.base.build_root import BuildRoot
from pants.scm.scm import Scm
from pants.vcs.git import Git, GitException
from pants.version import VERSION

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -52,37 +52,22 @@ def get_default_pants_config_file() -> str:
return os.path.join(get_buildroot(), "pants.toml")


_SCM: Optional[Scm] = None
_Git: Optional[Git] = None


def get_scm() -> Optional[Scm]:
"""Returns the pants Scm if any.
def get_git() -> Optional[Git]:
"""Returns Git, if available."""
global _Git
if _Git:
return _Git

:API: public
"""
# TODO(John Sirois): Extract a module/class to carry the bootstrap logic.
global _SCM
if _SCM:
return _SCM
from pants.scm.git import Git

# We know about git, so attempt an auto-configure
# We know about Git, so attempt an auto-configure
worktree = Git.detect_worktree()
if worktree and os.path.isdir(worktree):
git = Git(worktree=worktree)
try:
logger.debug(f"Detected git repository at {worktree} on branch {git.branch_name}")
set_scm(git)
except git.LocalException as e:
_Git = git
except GitException as e:
logger.info(f"Failed to load git repository at {worktree}: {e!r}")
return _SCM


def set_scm(scm: Optional[Scm]) -> None:
"""Sets the pants Scm."""
if scm is None:
return
if not isinstance(scm, Scm):
raise ValueError(f"The scm must be an instance of Scm, given {scm}")
global _SCM
_SCM = scm
return _Git
11 changes: 1 addition & 10 deletions src/python/pants/base/run_info.py
Expand Up @@ -8,7 +8,7 @@
import time
from collections import OrderedDict

from pants.base.build_environment import get_buildroot, get_scm
from pants.base.build_environment import get_buildroot
from pants.util.dirutil import safe_mkdir_for
from pants.version import VERSION

Expand Down Expand Up @@ -92,12 +92,3 @@ def add_basic_info(self, run_id, timestamp):
("buildroot", buildroot),
("version", VERSION),
)

def add_scm_info(self):
"""Adds SCM-related info."""
scm = get_scm()
if not scm:
return
revision = scm.commit_id
branch = scm.branch_name or revision
self.add_infos(("revision", revision), ("branch", branch))
2 changes: 1 addition & 1 deletion src/python/pants/init/engine_initializer.py
Expand Up @@ -31,8 +31,8 @@
from pants.option.global_options import DEFAULT_EXECUTION_OPTIONS, ExecutionOptions
from pants.option.options_bootstrapper import OptionsBootstrapper
from pants.option.subsystem import Subsystem
from pants.scm.subsystems.changed import rules as changed_rules
from pants.util.ordered_set import FrozenOrderedSet
from pants.vcs.changed import rules as changed_rules

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/init/global_subsystems.py
Expand Up @@ -4,7 +4,7 @@
from pants.goal.run_tracker import RunTracker
from pants.process.subprocess import Subprocess
from pants.reporting.reporting import Reporting
from pants.scm.subsystems.changed import Changed
from pants.vcs.changed import Changed


class GlobalSubsystems:
Expand Down
12 changes: 6 additions & 6 deletions src/python/pants/init/specs_calculator.py
Expand Up @@ -4,7 +4,7 @@
import logging
from typing import Optional, cast

from pants.base.build_environment import get_buildroot, get_scm
from pants.base.build_environment import get_buildroot, get_git
from pants.base.specs import AddressLiteralSpec, AddressSpecs, FilesystemSpecs, Specs
from pants.base.specs_parser import SpecsParser
from pants.engine.addresses import AddressInput
Expand All @@ -13,7 +13,7 @@
from pants.engine.rules import QueryRule
from pants.option.options import Options
from pants.option.options_bootstrapper import OptionsBootstrapper
from pants.scm.subsystems.changed import ChangedAddresses, ChangedOptions, ChangedRequest
from pants.vcs.changed import ChangedAddresses, ChangedOptions, ChangedRequest

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -53,13 +53,13 @@ def calculate_specs(
if not changed_options.provided:
return specs

scm = get_scm()
if not scm:
git = get_git()
if not git:
raise InvalidSpecConstraint(
"The `--changed-*` options are not available without a recognized SCM (usually " "Git)."
"The `--changed-*` options are only available if Git is used for the repository."
)
changed_request = ChangedRequest(
sources=tuple(changed_options.changed_files(scm=scm)),
sources=tuple(changed_options.changed_files(git)),
dependees=changed_options.dependees,
)
(changed_addresses,) = session.product_request(
Expand Down
6 changes: 0 additions & 6 deletions src/python/pants/scm/BUILD

This file was deleted.

3 changes: 0 additions & 3 deletions src/python/pants/scm/README.md

This file was deleted.

96 changes: 0 additions & 96 deletions src/python/pants/scm/scm.py

This file was deleted.

4 changes: 0 additions & 4 deletions src/python/pants/scm/subsystems/BUILD

This file was deleted.

Empty file.
22 changes: 22 additions & 0 deletions src/python/pants/vcs/BUILD
@@ -0,0 +1,22 @@
# Copyright 2014 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

python_library()

python_tests(
name="tests",
sources=["*_test.py", "!*integration_test.py"],
)


python_integration_tests(
name = 'changed_integration',
sources = ['changed_integration_test.py'],
dependencies = [
'//:gitignore',
'testprojects/src/python:python_targets_directory',
'testprojects/src/python:sources_directory',
],
uses_pants_run=True,
timeout = 600,
)
File renamed without changes.
Expand Up @@ -15,7 +15,7 @@
from pants.engine.rules import Get, collect_rules, rule
from pants.option.option_value_container import OptionValueContainer
from pants.option.subsystem import Subsystem
from pants.scm.scm import Scm
from pants.vcs.git import Git


class DependeesOption(Enum):
Expand Down Expand Up @@ -86,15 +86,15 @@ def from_options(cls, options: OptionValueContainer) -> "ChangedOptions":
def provided(self) -> bool:
return bool(self.since) or bool(self.diffspec)

def changed_files(self, *, scm: Scm) -> List[str]:
def changed_files(self, git: Git) -> List[str]:
"""Determines the files changed according to SCM/workspace and options."""
if self.diffspec:
return cast(List[str], scm.changes_in(self.diffspec, relative_to=get_buildroot()))
return cast(List[str], git.changes_in(self.diffspec, relative_to=get_buildroot()))

changes_since = self.since or scm.current_rev_identifier
changes_since = self.since or git.current_rev_identifier
return cast(
List[str],
scm.changed_files(
git.changed_files(
from_commit=changes_since, include_untracked=True, relative_to=get_buildroot()
),
)
Expand Down
Expand Up @@ -11,11 +11,11 @@
import pytest

from pants.base.build_environment import get_buildroot
from pants.scm.git import Git
from pants.testutil.pants_integration_test import PantsIntegrationTest, ensure_daemon
from pants.testutil.test_base import AbstractTestGenerator
from pants.util.contextutil import environment_as, temporary_dir
from pants.util.dirutil import safe_delete, safe_mkdir, safe_open, touch
from pants.vcs.git import Git


@contextmanager
Expand Down

0 comments on commit 6fe997c

Please sign in to comment.