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_uncommited_changes_true(self) -> None: subprocess.run(['touch', 'main.py']) self.assertTrue(has_uncommitted_changes())
def test_has_uncommitted_changes_false(self) -> None: self.assertFalse(has_uncommitted_changes())