def pantsd_test_context(
        self,
        *,
        log_level: str = "info",
        extra_config: Optional[Dict[str, Any]] = None
    ) -> Iterator[Tuple[str, Dict[str, Any], PantsDaemonMonitor]]:
        with temporary_dir(root_dir=os.getcwd()) as workdir_base:
            pid_dir = os.path.join(workdir_base, ".pids")
            workdir = os.path.join(workdir_base, ".workdir.pants.d")
            print(f"\npantsd log is {workdir}/pantsd/pantsd.log")
            pantsd_config = {
                "GLOBAL": {
                    "pantsd": True,
                    "level": log_level,
                    "pants_subprocessdir": pid_dir,
                }
            }

            if extra_config:
                recursively_update(pantsd_config, extra_config)
            print(f">>> config: \n{pantsd_config}\n")

            checker = PantsDaemonMonitor(pid_dir)
            kill_daemon(pid_dir)
            try:
                yield (workdir, pantsd_config, checker)
                kill_daemon(pid_dir)
                checker.assert_stopped()
            finally:
                banner("BEGIN pantsd.log")
                for line in read_pantsd_log(workdir):
                    print(line)
                banner("END pantsd.log")
Exemplo n.º 2
0
 def pantsd_test_context(self, log_level='info', extra_config=None, expected_runs=1):
   with no_lingering_process_by_command('pantsd-runner'):
     with self.temporary_workdir() as workdir_base:
       pid_dir = os.path.join(workdir_base, '.pids')
       workdir = os.path.join(workdir_base, '.workdir.pants.d')
       print('\npantsd log is {}/pantsd/pantsd.log'.format(workdir))
       pantsd_config = {
         'GLOBAL': {
           'enable_pantsd': True,
           # The absolute paths in CI can exceed the UNIX socket path limitation
           # (>104-108 characters), so we override that here with a shorter path.
           'watchman_socket_path': '/tmp/watchman.{}.sock'.format(os.getpid()),
           'level': log_level,
           'pants_subprocessdir': pid_dir,
         }
       }
       if extra_config:
         recursively_update(pantsd_config, extra_config)
       print('>>> config: \n{}\n'.format(pantsd_config))
       checker = PantsDaemonMonitor(pid_dir)
       self.assert_success_runner(workdir, pantsd_config, ['kill-pantsd'])
       try:
         yield workdir, pantsd_config, checker
       finally:
         banner('BEGIN pantsd.log')
         for line in read_pantsd_log(workdir):
           print(line)
         banner('END pantsd.log')
         self.assert_success_runner(
           workdir,
           pantsd_config,
           ['kill-pantsd'],
           expected_runs=expected_runs,
         )
         checker.assert_stopped()
Exemplo n.º 3
0
 def test_recursively_update(self) -> None:
     d1 = {
         'a': 1,
         'b': {
             'c': 2,
             'o': 'z',
         },
         'z': {
             'y': 0,
         }
     }
     d2 = {'e': 3, 'b': {'f': 4, 'o': 9}, 'g': {'h': 5}, 'z': 7}
     recursively_update(d1, d2)
     self.assertEqual(d1, {
         'a': 1,
         'b': {
             'c': 2,
             'f': 4,
             'o': 9
         },
         'e': 3,
         'g': {
             'h': 5
         },
         'z': 7
     })
Exemplo n.º 4
0
 def test_recursively_update(self) -> None:
     d1 = {
         "a": 1,
         "b": {
             "c": 2,
             "o": "z",
         },
         "z": {
             "y": 0,
         }
     }
     d2 = {"e": 3, "b": {"f": 4, "o": 9}, "g": {"h": 5}, "z": 7}
     recursively_update(d1, d2)
     self.assertEqual(d1, {
         "a": 1,
         "b": {
             "c": 2,
             "f": 4,
             "o": 9
         },
         "e": 3,
         "g": {
             "h": 5
         },
         "z": 7
     })
Exemplo n.º 5
0
 def test_recursively_update(self):
     d = {'a': 1, 'b': {'c': 2, 'o': 'z'}, 'z': {'y': 0}}
     recursively_update(d, {
         'e': 3,
         'b': {
             'f': 4,
             'o': 9
         },
         'g': {
             'h': 5
         },
         'z': 7
     })
     self.assertEqual(d, {
         'a': 1,
         'b': {
             'c': 2,
             'f': 4,
             'o': 9
         },
         'e': 3,
         'g': {
             'h': 5
         },
         'z': 7
     })
Exemplo n.º 6
0
  def assert_success_runner(self, workdir, config, cmd, extra_config={}, extra_env={}, expected_runs=1):
    combined_config = config.copy()
    recursively_update(combined_config, extra_config)
    print(bold(cyan('\nrunning: ./pants {} (config={}) (extra_env={})'
                    .format(' '.join(cmd), combined_config, extra_env))))
    run_count = self._run_count(workdir)
    start_time = time.time()
    run = self.run_pants_with_workdir(
      cmd,
      workdir,
      combined_config,
      extra_env=extra_env,
      # TODO: With this uncommented, `test_pantsd_run` fails.
      # tee_output=True
    )
    elapsed = time.time() - start_time
    print(bold(cyan('\ncompleted in {} seconds'.format(elapsed))))

    runs_created = self._run_count(workdir) - run_count
    self.assertEquals(
        runs_created,
        expected_runs,
        'Expected {} RunTracker run to be created per pantsd run: was {}'.format(
          expected_runs,
          runs_created,
        )
    )
    self.assert_success(run)
    return run
Exemplo n.º 7
0
 def pantsd_test_context(self, log_level='info', extra_config=None, expected_runs=1):
   with no_lingering_process_by_command('pantsd-runner'):
     with self.temporary_workdir() as workdir_base:
       pid_dir = os.path.join(workdir_base, '.pids')
       workdir = os.path.join(workdir_base, '.workdir.pants.d')
       print('\npantsd log is {}/pantsd/pantsd.log'.format(workdir))
       pantsd_config = {
         'GLOBAL': {
           'enable_pantsd': True,
           # The absolute paths in CI can exceed the UNIX socket path limitation
           # (>104-108 characters), so we override that here with a shorter path.
           'watchman_socket_path': '/tmp/watchman.{}.sock'.format(os.getpid()),
           'level': log_level,
           'pants_subprocessdir': pid_dir,
         }
       }
       if extra_config:
         recursively_update(pantsd_config, extra_config)
       print('>>> config: \n{}\n'.format(pantsd_config))
       checker = PantsDaemonMonitor(pid_dir)
       self.assert_success_runner(workdir, pantsd_config, ['kill-pantsd'])
       try:
         yield workdir, pantsd_config, checker
       finally:
         banner('BEGIN pantsd.log')
         for line in read_pantsd_log(workdir):
           print(line)
         banner('END pantsd.log')
         self.assert_success_runner(
           workdir,
           pantsd_config,
           ['kill-pantsd'],
           expected_runs=expected_runs,
         )
         checker.assert_stopped()
Exemplo n.º 8
0
  def assert_success_runner(self, workdir, config, cmd, extra_config={}, extra_env={}, expected_runs=1):
    combined_config = config.copy()
    recursively_update(combined_config, extra_config)
    print(bold(cyan('\nrunning: ./pants {} (config={}) (extra_env={})'
                    .format(' '.join(cmd), combined_config, extra_env))))
    run_count = self._run_count(workdir)
    start_time = time.time()
    run = self.run_pants_with_workdir(
      cmd,
      workdir,
      combined_config,
      extra_env=extra_env,
      # TODO: With this uncommented, `test_pantsd_run` fails.
      # tee_output=True
    )
    elapsed = time.time() - start_time
    print(bold(cyan('\ncompleted in {} seconds'.format(elapsed))))

    runs_created = self._run_count(workdir) - run_count
    self.assertEquals(
        runs_created,
        expected_runs,
        'Expected {} RunTracker run to be created per pantsd run: was {}'.format(
          expected_runs,
          runs_created,
        )
    )
    self.assert_success(run)
    return run
Exemplo n.º 9
0
 def with_global_plugin_args(self, args, config={}):
   if args is not None:
     recursively_update(config,  {'scala': {
       'scalac_plugin_args': {
         'simple_scalac_plugin': args
       }
     }})
   return config
 def pantsd_test_context(self,
                         log_level='info',
                         extra_config=None,
                         expected_runs=1):
     with no_lingering_process_by_command(
             'pantsd-runner') as runner_process_context:
         with self.temporary_workdir() as workdir_base:
             pid_dir = os.path.join(workdir_base, '.pids')
             workdir = os.path.join(workdir_base, '.workdir.pants.d')
             print('\npantsd log is {}/pantsd/pantsd.log'.format(workdir))
             pantsd_config = {
                 'GLOBAL': {
                     'enable_pantsd':
                     True,
                     # The absolute paths in CI can exceed the UNIX socket path limitation
                     # (>104-108 characters), so we override that here with a shorter path.
                     'watchman_socket_path':
                     '/tmp/watchman.{}.sock'.format(os.getpid()),
                     'level':
                     log_level,
                     'pants_subprocessdir':
                     pid_dir,
                 }
             }
             if extra_config:
                 recursively_update(pantsd_config, extra_config)
             print('>>> config: \n{}\n'.format(pantsd_config))
             checker = PantsDaemonMonitor(runner_process_context, pid_dir)
             # TODO(#6574): this should be 1, but when we kill pantsd with a signal it doesn't make sure
             # to close the run tracker -- we can easily address this by moving that cleanup into the
             # Exiter.
             self.assert_runner(workdir,
                                pantsd_config, ['kill-pantsd'],
                                expected_runs=1)
             try:
                 yield workdir, pantsd_config, checker
             finally:
                 banner('BEGIN pantsd.log')
                 for line in read_pantsd_log(workdir):
                     print(line)
                 banner('END pantsd.log')
                 self.assert_runner(
                     workdir,
                     pantsd_config,
                     ['kill-pantsd'],
                     # TODO(#6574): this should be 1, see above.
                     expected_runs=1,
                 )
                 checker.assert_stopped()
Exemplo n.º 11
0
    def assert_runner(
        self,
        workdir: str,
        config,
        cmd,
        extra_config={},
        extra_env={},
        success=True,
        expected_runs: int = 1,
    ):
        combined_config = config.copy()
        recursively_update(combined_config, extra_config)
        print(
            bold(
                cyan(
                    "\nrunning: ./pants {} (config={}) (extra_env={})".format(
                        " ".join(cmd), combined_config, extra_env
                    )
                )
            )
        )
        run_count = self._run_count(workdir)
        start_time = time.time()
        run = self.run_pants_with_workdir(
            cmd,
            workdir,
            combined_config,
            extra_env=extra_env,
            # TODO: With this uncommented, `test_pantsd_run` fails.
            # tee_output=True
        )
        elapsed = time.time() - start_time
        print(bold(cyan(f"\ncompleted in {elapsed} seconds")))

        if success:
            self.assert_success(run)
        else:
            self.assert_failure(run)

        runs_created = self._run_count(workdir) - run_count
        self.assertEqual(
            runs_created,
            expected_runs,
            "Expected {} RunTracker run(s) to be created per pantsd run: was {}".format(
                expected_runs, runs_created,
            ),
        )

        return run
Exemplo n.º 12
0
 def with_compiler_option_sets_enabled_scalac_plugins(self, config={}):
   recursively_update(config, {
     'compile.rsc': {
       'compiler_option_sets_enabled_args': {
         'option-set-requiring-scalac-plugin': [
           '-S-P:simple_scalac_plugin:abc',
           '-S-P:simple_scalac_plugin:def',
         ],
       },
       'compiler_option_sets_enabled_scalac_plugins': {
         'option-set-requiring-scalac-plugin': ['simple_scalac_plugin'],
       },
     }
   })
   return config
Exemplo n.º 13
0
 def with_compiler_option_sets_enabled_scalac_plugins(self, config={}):
     recursively_update(
         config,
         {
             "compile.rsc": {
                 "compiler_option_sets_enabled_args": {
                     "option-set-requiring-scalac-plugin": [
                         "-S-P:simple_scalac_plugin:abc",
                         "-S-P:simple_scalac_plugin:def",
                     ],
                 },
                 "compiler_option_sets_enabled_scalac_plugins": {
                     "option-set-requiring-scalac-plugin": ["simple_scalac_plugin"],
                 },
             }
         },
     )
     return config
Exemplo n.º 14
0
    def pantsd_test_context(
        self,
        *,
        log_level: str = "info",
        extra_config: Optional[Dict[str, Any]] = None
    ) -> Iterator[Tuple[str, Dict[str, Any], PantsDaemonMonitor]]:
        with no_lingering_process_by_command(
                "pantsd") as runner_process_context:
            with self.temporary_workdir() as workdir_base:
                pid_dir = os.path.join(workdir_base, ".pids")
                workdir = os.path.join(workdir_base, ".workdir.pants.d")
                print(f"\npantsd log is {workdir}/pantsd/pantsd.log")
                pantsd_config = {
                    "GLOBAL": {
                        "enable_pantsd": True,
                        "shutdown_pantsd_after_run": False,
                        # The absolute paths in CI can exceed the UNIX socket path limitation
                        # (>104-108 characters), so we override that here with a shorter path.
                        "watchman_socket_path":
                        f"/tmp/watchman.{os.getpid()}.sock",
                        "level": log_level,
                        "pants_subprocessdir": pid_dir,
                    }
                }

                if extra_config:
                    recursively_update(pantsd_config, extra_config)
                print(f">>> config: \n{pantsd_config}\n")

                checker = PantsDaemonMonitor(runner_process_context, pid_dir)
                self.assert_runner(workdir, pantsd_config, ["kill-pantsd"])
                try:
                    yield workdir, pantsd_config, checker
                    self.assert_runner(
                        workdir,
                        pantsd_config,
                        ["kill-pantsd"],
                    )
                    checker.assert_stopped()
                finally:
                    banner("BEGIN pantsd.log")
                    for line in read_pantsd_log(workdir):
                        print(line)
                    banner("END pantsd.log")
    def pantsd_test_context(
        self,
        *,
        log_level: str = "info",
        extra_config: dict[str, Any] | None = None
    ) -> Iterator[tuple[str, dict[str, Any], PantsDaemonMonitor]]:
        with temporary_dir(root_dir=os.getcwd()) as workdir_base:
            pid_dir = os.path.join(workdir_base, ".pids")
            workdir = os.path.join(workdir_base, ".workdir.pants.d")
            print(f"\npantsd log is {workdir}/pantsd/pantsd.log")
            pantsd_config = {
                "GLOBAL": {
                    "pantsd":
                    True,
                    "level":
                    log_level,
                    "pants_subprocessdir":
                    pid_dir,
                    "backend_packages": [
                        # Provide goals used by various tests.
                        "pants.backend.python",
                        "pants.backend.python.lint.flake8",
                    ],
                }
            }

            if extra_config:
                recursively_update(pantsd_config, extra_config)
            print(f">>> config: \n{pantsd_config}\n")

            checker = PantsDaemonMonitor(pid_dir)
            kill_daemon(pid_dir)
            try:
                yield workdir, pantsd_config, checker
                kill_daemon(pid_dir)
                checker.assert_stopped()
            finally:
                banner("BEGIN pants.log")
                for line in read_pants_log(workdir):
                    print(line)
                banner("END pants.log")
Exemplo n.º 16
0
 def with_global_plugin_enabled(self, config={}):
   recursively_update(config, {'scala': {'scalac_plugins': ['simple_scalac_plugin']}})
   return config
Exemplo n.º 17
0
 def test_recursively_update(self):
   d = {'a': 1, 'b': {'c': 2, 'o': 'z'}, 'z': {'y': 0}}
   recursively_update(d, {'e': 3, 'b': {'f': 4, 'o': 9}, 'g': {'h': 5}, 'z': 7})
   self.assertEqual(
     d, {'a': 1, 'b': {'c': 2, 'f': 4, 'o': 9}, 'e': 3, 'g': {'h': 5}, 'z': 7}
   )
Exemplo n.º 18
0
 def with_global_plugin_enabled(self, config={}):
     recursively_update(config, {"scala": {"scalac_plugins": ["simple_scalac_plugin"]}})
     return config
Exemplo n.º 19
0
def test_recursively_update() -> None:
    d1 = {"a": 1, "b": {"c": 2, "o": "z"}, "z": {"y": 0}}
    d2 = {"e": 3, "b": {"f": 4, "o": 9}, "g": {"h": 5}, "z": 7}
    recursively_update(d1, d2)
    assert d1 == {"a": 1, "b": {"c": 2, "f": 4, "o": 9}, "e": 3, "g": {"h": 5}, "z": 7}