def _generate_changelog(version: Optional[str], use_news_files: bool) -> None: """Creates a towncrier log of the release. Will only create a log entry if we are using news files. Args: version: the semver version of the release use_news_files: are we generating the release from news files """ if use_news_files: logger.info(":: Generating a new changelog") project_config_path = configuration.get_value( ConfigurationVariable.PROJECT_CONFIG) with cd(os.path.dirname(project_config_path)): subprocess.check_call( ["towncrier", "--yes", '--name=""', f'--version="{version}"'])
def test_find_file_down_the_tree(self): filename = "test.test" with TemporaryDirectory() as temp_dir: child_dir = temp_dir for i in range(0, 10): child_dir = child_dir.joinpath(f"test{str(i)}") os.makedirs(child_dir) temp_file = Path(child_dir).joinpath(filename) temp_file.touch() with cd(str(temp_dir)): self.assertEqual( temp_file, Path( find_file_in_tree(filename, starting_point=os.getcwd(), top=False)))
def _release_to_pypi() -> None: logger.info("Releasing to PyPI") logger.info("Generating a release package") root = configuration.get_value(ConfigurationVariable.PROJECT_ROOT) with cd(root): subprocess.check_call([ sys.executable, "setup.py", "clean", "--all", "sdist", "-d", OUTPUT_DIRECTORY, "--formats=gztar", "bdist_wheel", "-d", OUTPUT_DIRECTORY, ]) _upload_to_test_pypi() _upload_to_pypi()
def _calculate_version(commit_type: CommitType, use_news_files: bool) -> Tuple[bool, Optional[str]]: """Calculates the version for the release. eg. "0.1.2" Args: commit_type: use_news_files: Should the version be dependant on changes recorded in news files Returns: Tuple containing a flag stating whether it is a new version or not A semver-style version for the latest release """ BUMP_TYPES = { CommitType.DEVELOPMENT: "build", CommitType.BETA: "prerelease" } is_release = commit_type == CommitType.RELEASE enable_file_triggers = True if use_news_files else None bump = BUMP_TYPES.get(commit_type) project_config_path = configuration.get_value( ConfigurationVariable.PROJECT_CONFIG) new_version: Optional[str] = None is_new_version: bool = False with cd(os.path.dirname(project_config_path)): old, _, updates = auto_version_tool.main( release=is_release, enable_file_triggers=enable_file_triggers, commit_count_as=bump, config_path=project_config_path, ) # Autoversion second returned value is not actually the new version # There seem to be a bug in autoversion. # This is why the following needs to be done to determine the version new_version = updates["__version__"] is_new_version = old != new_version logger.info(":: Determining the new version") logger.info(f"Version: {new_version}") return is_new_version, new_version
def test_cd(self): with TemporaryDirectory() as temp_dir: self.assertNotEqual(Path(os.getcwd()), temp_dir) with cd(temp_dir): self.assertEqual(Path(os.getcwd()), temp_dir) self.assertNotEqual(Path(os.getcwd()), temp_dir)