def __call__(self) -> bool: old_version = None root = None loader = None project_path = Path(self.config['project']) package = PackageRoot(path=project_path) if 'from' in self.config: # get project metainfo loader = CONVERTERS[self.config['from']['format']] loader = loader.copy(project_path=Path(self.config['project'])) root = loader.load(path=self.config['from']['path']) if root.version != '0.0.0': package = root.package old_version = root.version else: self.logger.warning('cannot get version from `from` file') else: self.logger.warning('`from` file is not specified') if old_version is None and package.metainfo: old_version = package.metainfo.version if old_version is None: if self.args.name == 'init': old_version = '' else: self.logger.error('cannot find old project version') return False # make new version new_version = bump_version( version=old_version, rule=self.args.name, scheme=self.config['versioning'], ) self.logger.info('generated new version', extra=dict( old=old_version, new=new_version, )) # update version in project files paths = [] for path in self._bump_project(project=package, old=old_version, new=new_version): paths.append(path) self.logger.info('file bumped', extra=dict(path=str(path))) # update version in project metadata updated = self._update_metadata(root=root, loader=loader, new_version=new_version) if updated: paths.append(Path(self.config['from']['path'])) # set git tag tagged = True if self.config.get('tag') is not None: tagged = self._add_git_tag(paths=paths, new_version=new_version, template=self.config['tag']) return tagged
def test_bump_version(rule, old, new): assert bump_version(rule=rule, version=old, scheme='pep') == new