Skip to content

Commit

Permalink
Added explicit environment variable declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
coordt committed Apr 12, 2023
1 parent 2b3b358 commit 80fe7ef
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
31 changes: 29 additions & 2 deletions bumpversion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
)
Expand All @@ -41,54 +42,63 @@
"--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(
"--serialize",
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."
Expand All @@ -98,46 +108,54 @@
"--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(
"-m",
"--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(
Expand Down Expand Up @@ -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__)
Expand Down
6 changes: 4 additions & 2 deletions bumpversion/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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"),
)
Expand Down Expand Up @@ -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
}


Expand Down

0 comments on commit 80fe7ef

Please sign in to comment.