From 80fe7ef0cf1005333143cce38835dbc9ad811884 Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Wed, 12 Apr 2023 09:13:51 -0500 Subject: [PATCH] Added explicit environment variable declarations --- bumpversion/cli.py | 31 +++++++++++++++++++++++++++++-- bumpversion/config.py | 6 ++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/bumpversion/cli.py b/bumpversion/cli.py index 8dbf799f..875b9de7 100644 --- a/bumpversion/cli.py +++ b/bumpversion/cli.py @@ -33,6 +33,7 @@ "--config-file", metavar="FILE", required=False, + envvar="BUMPVERSION_CONFIG_FILE", type=click.Path(exists=True), help="Config file to read most of the variables from.", ) @@ -41,30 +42,35 @@ "--verbose", count=True, required=False, - help="Print verbose logging to stderr", + envvar="BUMPVERSION_VERBOSE", + help="Print verbose logging to stderr. Can specify several times for more verbosity.", ) @click.option( "--allow-dirty/--no-allow-dirty", default=None, required=False, + envvar="BUMPVERSION_ALLOW_DIRTY", help="Don't abort if working directory is dirty, or explicitly abort if dirty.", ) @click.option( "--current-version", metavar="VERSION", required=False, + envvar="BUMPVERSION_CURRENT_VERSION", help="Version that needs to be updated", ) @click.option( "--new-version", metavar="VERSION", required=False, + envvar="BUMPVERSION_NEW_VERSION", help="New version that should be in the files", ) @click.option( "--parse", metavar="REGEX", required=False, + envvar="BUMPVERSION_PARSE", help="Regex parsing the version string", ) @click.option( @@ -72,23 +78,27 @@ metavar="FORMAT", multiple=True, required=False, + envvar="BUMPVERSION_SERIALIZE", help="How to format what is parsed back to a version", ) @click.option( "--search", metavar="SEARCH", required=False, + envvar="BUMPVERSION_SEARCH", help="Template for complete string to search", ) @click.option( "--replace", metavar="REPLACE", required=False, + envvar="BUMPVERSION_REPLACE", help="Template for complete string to replace", ) @click.option( "--no-configured-files", is_flag=True, + envvar="BUMPVERSION_NO_CONFIGURED_FILES", help=( "Only replace the version in files specified on the command line, " "ignoring the files from the configuration file." @@ -98,33 +108,39 @@ "--dry-run", "-n", is_flag=True, + envvar="BUMPVERSION_DRY_RUN", help="Don't write any files, just pretend.", ) @click.option( "--commit/--no-commit", default=None, + envvar="BUMPVERSION_COMMIT", help="Commit to version control", ) @click.option( "--tag/--no-tag", default=None, + envvar="BUMPVERSION_TAG", help="Create a tag in version control", ) @click.option( "--sign-tags/--no-sign-tags", default=None, + envvar="BUMPVERSION_SIGN_TAGS", help="Sign tags if created", ) @click.option( "--tag-name", metavar="TAG_NAME", required=False, + envvar="BUMPVERSION_TAG_NAME", help="Tag name (only works with --tag)", ) @click.option( "--tag-message", metavar="TAG_MESSAGE", required=False, + envvar="BUMPVERSION_TAG_MESSAGE", help="Tag message", ) @click.option( @@ -132,12 +148,14 @@ "--message", metavar="COMMIT_MSG", required=False, + envvar="BUMPVERSION_MESSAGE", help="Commit message", ) @click.option( "--commit-args", metavar="COMMIT_ARGS", required=False, + envvar="BUMPVERSION_COMMIT_ARGS", help="Extra arguments to commit command", ) @click.option( @@ -169,7 +187,16 @@ def cli( commit_args: Optional[str], show_list: bool, ) -> None: - """Change the version.""" + """ + Change the version. + + VERSION_PART is the part of the version to increase, e.g. `minor` . + Valid values include those given in the `--serialize` / `--parse` option. + + FILES are additional file(s) to modify. + If you want to rewrite only files specified on the command line, use with the + `--no-configured-files` option. + """ setup_logging(verbose) logger.info("Starting BumpVersion %s", __version__) diff --git a/bumpversion/config.py b/bumpversion/config.py index 2914b0b2..3d671a49 100644 --- a/bumpversion/config.py +++ b/bumpversion/config.py @@ -68,7 +68,7 @@ class Config: def add_files(self, filename: Union[str, List[str]]) -> None: """Add a filename to the list of files.""" filenames = [filename] if isinstance(filename, str) else filename - self.files.extend([FileConfig(filename=name) for name in filenames]) + self.files.extend([FileConfig(filename=name) for name in filenames]) # type: ignore[call-arg] @property def version_config(self) -> "VersionConfig": @@ -99,6 +99,7 @@ def version_config(self) -> "VersionConfig": CONFIG_FILE_SEARCH_ORDER = ( Path(".bumpversion.cfg"), + Path(".bumpversion.toml"), Path("setup.cfg"), Path("pyproject.toml"), ) @@ -148,7 +149,8 @@ def get_all_part_configs(config_dict: dict) -> Dict[str, VersionPartConfig]: parts = config_dict["parts"] all_labels = set(itertools.chain.from_iterable([labels_for_format(fmt) for fmt in serialize])) return { - label: VersionPartConfig(**parts[label]) if label in parts else VersionPartConfig() for label in all_labels + label: VersionPartConfig(**parts[label]) if label in parts else VersionPartConfig() # type: ignore[call-arg] + for label in all_labels }