Exemple #1
0
    def get_reproducibility_info() -> Dict[str, str]:
        """Gets a dictionary of reproducibility information.

        Reproducibility information always includes:
        - command_line: The command line command used to execute the code.
        - time: The current time.

        If git is installed, reproducibility information also includes:
        - git_root: The root of the git repo where the command is run.
        - git_url: The url of the current hash of the git repo where the command is run.
                   Ex. https://github.com/swansonk14/rationale-alignment/tree/<hash>
        - git_has_uncommitted_changes: Whether the current git repo has uncommitted changes.

        :return: A dictionary of reproducibility information.
        """
        reproducibility = {
            'command_line': f'python {" ".join(sys.argv)}',
            'time': time.strftime('%c')
        }

        if has_git():
            reproducibility['git_root'] = get_git_root()
            reproducibility['git_url'] = get_git_url(commit_hash=True)
            reproducibility[
                'git_has_uncommitted_changes'] = has_uncommitted_changes()

        return reproducibility
 def test_has_git_false(self) -> None:
     with TemporaryDirectory() as temp_dir_no_git:
         os.chdir(temp_dir_no_git)
         self.assertFalse(has_git())
     os.chdir(self.temp_dir.name)
 def test_has_git_true(self) -> None:
     self.assertTrue(has_git())