Beispiel #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_get_git_root_subdir(self) -> None:
        subdir = os.path.join(self.temp_dir.name, 'subdir')
        os.makedirs(subdir)
        os.chdir(subdir)

        # Ideally should be self.temp_dir.name == get_git_root() but the OS may add a prefix like /private
        self.assertTrue(get_git_root().endswith(self.temp_dir.name.replace('\\', '/')))

        os.chdir(self.temp_dir.name)
 def test_get_git_root_subdir(self) -> None:
     os.makedirs(os.path.join(self.temp_dir.name, 'subdir'))
     self.assertTrue(get_git_root() in f'/private{self.temp_dir.name}')
 def test_get_git_root(self) -> None:
     self.assertTrue(get_git_root() in f'/private{self.temp_dir.name}')
 def test_get_git_root(self) -> None:
     # Ideally should be self.temp_dir.name == get_git_root() but the OS may add a prefix like /private
     self.assertTrue(get_git_root().endswith(self.temp_dir.name.replace('\\', '/')))