PK! cli/bump.py'''Version bumper for Foliant projects.''' import re from pathlib import Path from semver import bump_major, bump_minor, bump_patch, bump_prerelease, bump_build from cliar import set_help, set_arg_map from foliant.cli.base import BaseCli class Cli(BaseCli): @set_arg_map({'project_path': 'path', 'config_file_name': 'config'}) @set_help( { 'version_part': 'Part of the version to bump: ' + 'major, minor, patch, prerelease, or build ' + '(default: patch).', 'project_path': 'Path to the directory with the config file (default: ".").', 'config_file_name': 'Name of the config file (default: "foliant.yml").' } ) def bump(self, version_part='patch', project_path=Path('.'), config_file_name='foliant.yml'): '''Bump Foliant project version.''' try: bump_function = { 'major': bump_major, 'minor': bump_minor, 'patch': bump_patch, 'prerelease': bump_prerelease, 'build': bump_build }[version_part] except KeyError as exception: quit(f'Unknown version part {exception}.') version_line_pattern = re.compile(r'^(version:\s*)(?P.+)$', flags=re.MULTILINE) try: with open(project_path/config_file_name, encoding='utf8') as config_file: config = config_file.read() except FileNotFoundError: quit(f'No config file named {config_file_name} found in "{project_path}".') version_line = version_line_pattern.search(config) if not version_line: quit('No version defined in the config file.') old_version = version_line.group('version') new_version = bump_function(old_version) with open(project_path/config_file_name, 'w', encoding='utf8') as config_file: config_file.write(version_line_pattern.sub(rf'\g<1>{new_version}', config)) self.logger.info('Version bumping completed.') print(f'Bumped version from {old_version} to {new_version}.') PK!g!!+foliantcontrib.bump-1.0.0.dist-info/LICENSEMIT License Copyright (c) 2018 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HRST)foliantcontrib.bump-1.0.0.dist-info/WHEEL A н#J;/"d&F]xzw>@Zpy3F ]n2H%_60{8&baPa>PK!H*,foliantcontrib.bump-1.0.0.dist-info/METADATA[o0 +I42)4i :7ۍ63]g??kka]^ ԼrxG99Ψ/<˻h PK!H}*foliantcontrib.bump-1.0.0.dist-info/RECORDr04]tA1TSn^JLo`͜`3/ǥ"}%څ;RX Ƀ9]5MM! RF͹75;s:K٣QRL<$ƒqUٺ_,uS n[Avu3d P72+AYn :,C3Qe4 ?fYҌ́0')zi%`D{R4Z{?~PK! cli/bump.pyPK!g!!+foliantcontrib.bump-1.0.0.dist-info/LICENSEPK!HRST)? foliantcontrib.bump-1.0.0.dist-info/WHEELPK!H*, foliantcontrib.bump-1.0.0.dist-info/METADATAPK!H}*8foliantcontrib.bump-1.0.0.dist-info/RECORDPK