Skip to content

Commit

Permalink
Merge pull request #30 from callowayproject/19-decouple-search-replac…
Browse files Browse the repository at this point in the history
…e-from-version-bump

Added replace subcommand.
  • Loading branch information
coordt authored Jul 10, 2023
2 parents 59b2e41 + 3fe96f0 commit 0a722a5
Show file tree
Hide file tree
Showing 35 changed files with 2,859 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ repos:
hooks:
- id: mypy
args: [--no-strict-optional, --ignore-missing-imports]
additional_dependencies: ["pydantic", "toml", "types-all"]
additional_dependencies: ["pydantic<2.0", "toml", "types-all"]
- repo: https://github.com/terrencepreilly/darglint
rev: v1.8.1
hooks:
Expand Down
156 changes: 155 additions & 1 deletion bumpversion/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
from bumpversion.aliases import AliasedGroup
from bumpversion.bump import do_bump
from bumpversion.config import find_config_file, get_configuration
from bumpversion.files import modify_files, resolve_file_config
from bumpversion.logging import setup_logging
from bumpversion.show import do_show, log_list
from bumpversion.utils import get_overrides
from bumpversion.utils import get_context, get_overrides

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -290,3 +291,156 @@ def show(args: List[str], config_file: Optional[str], format_: str, increment: O
do_show("all", config=config, format_=format_, increment=increment)
else:
do_show(*args, config=config, format_=format_, increment=increment)


@cli.command()
@click.argument("files", nargs=-1, type=str)
@click.option(
"--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.",
)
@click.option(
"-v",
"--verbose",
count=True,
required=False,
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. If not specified, it will be None.",
)
@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."
),
)
@click.option(
"--dry-run",
"-n",
is_flag=True,
envvar="BUMPVERSION_DRY_RUN",
help="Don't write any files, just pretend.",
)
def replace(
files: list,
config_file: Optional[str],
verbose: int,
allow_dirty: Optional[bool],
current_version: Optional[str],
new_version: Optional[str],
parse: Optional[str],
serialize: Optional[List[str]],
search: Optional[str],
replace: Optional[str],
no_configured_files: bool,
dry_run: bool,
) -> None:
"""
Replace the version in files.
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__)

overrides = get_overrides(
allow_dirty=allow_dirty,
current_version=current_version,
new_version=new_version,
parse=parse,
serialize=serialize or None,
search=search,
replace=replace,
commit=False,
tag=False,
sign_tags=False,
tag_name=None,
tag_message=None,
message=None,
commit_args=None,
)

found_config_file = find_config_file(config_file)
config = get_configuration(found_config_file, **overrides)

config.allow_dirty = allow_dirty if allow_dirty is not None else config.allow_dirty
if not config.allow_dirty and config.scm_info.tool:
config.scm_info.tool.assert_nondirty()

if no_configured_files:
config.files = []

if files:
config.add_files(files)

version = config.version_config.parse(config.current_version)

if new_version:
next_version = config.version_config.parse(new_version)
else:
next_version = None

ctx = get_context(config, version, next_version)

configured_files = resolve_file_config(config.files, config.version_config)

modify_files(configured_files, version, next_version, ctx, dry_run)
9 changes: 0 additions & 9 deletions docsrc/api.rst

This file was deleted.

8 changes: 7 additions & 1 deletion docsrc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

extensions = [
"myst_parser",
"sphinx.ext.autodoc",
"autodoc2",
# "sphinx.ext.autodoc",
"sphinx.ext.viewcode",
"sphinx.ext.autosummary",
"sphinx.ext.intersphinx",
Expand All @@ -36,6 +37,11 @@
autosectionlabel_prefix_document = True
autosectionlabel_maxdepth = 2

autodoc2_packages = ["../bumpversion"]
autodoc2_render_plugin = "myst"
autodoc2_output_dir = "reference"
autodoc2_index_template = None

autodoc_default_flags = [
# Make sure that any autodoc declarations show the right members
"members",
Expand Down
4 changes: 4 additions & 0 deletions docsrc/explanation/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Explanation

```{toctree}
```
6 changes: 6 additions & 0 deletions docsrc/howtos/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# How-To Guides



```{toctree}
```
12 changes: 5 additions & 7 deletions docsrc/index.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Bump My Version's documentation
# Bump My Version

```{toctree}
---
Expand All @@ -7,12 +7,10 @@ caption: Contents
---
Introduction <readme>
usage
configuration
version-parts
formatting-context
search-and-replace
cli
api
tutorials/index
howtos/index
reference/index
explanation/index
contributing
changelog
```
Expand Down
8 changes: 8 additions & 0 deletions docsrc/reference/bumpversion/bumpversion.__main__.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# {py:mod}`bumpversion.__main__`

```{py:module} bumpversion.__main__
```

```{autodoc2-docstring} bumpversion.__main__
:allowtitles:
```
56 changes: 56 additions & 0 deletions docsrc/reference/bumpversion/bumpversion.aliases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# {py:mod}`bumpversion.aliases`

```{py:module} bumpversion.aliases
```

```{autodoc2-docstring} bumpversion.aliases
:allowtitles:
```

## Module Contents

### Classes

````{list-table}
:class: autosummary longtable
:align: left
* - {py:obj}`AliasedGroup <bumpversion.aliases.AliasedGroup>`
- ```{autodoc2-docstring} bumpversion.aliases.AliasedGroup
:summary:
```
````

### API

`````{py:class} AliasedGroup(name: typing.Optional[str] = None, commands: typing.Optional[typing.Union[typing.Dict[str, click.core.Command], typing.Sequence[click.core.Command]]] = None, **attrs: typing.Any)
:canonical: bumpversion.aliases.AliasedGroup
Bases: {py:obj}`rich_click.rich_group.RichGroup`
```{autodoc2-docstring} bumpversion.aliases.AliasedGroup
```
```{rubric} Initialization
```
```{autodoc2-docstring} bumpversion.aliases.AliasedGroup.__init__
```
````{py:method} get_command(ctx: click.Context, cmd_name: str) -> typing.Optional[rich_click.Command]
:canonical: bumpversion.aliases.AliasedGroup.get_command
```{autodoc2-docstring} bumpversion.aliases.AliasedGroup.get_command
```
````
````{py:method} resolve_command(ctx: click.Context, args: typing.List[str]) -> tuple
:canonical: bumpversion.aliases.AliasedGroup.resolve_command
```{autodoc2-docstring} bumpversion.aliases.AliasedGroup.resolve_command
```
````
`````
64 changes: 64 additions & 0 deletions docsrc/reference/bumpversion/bumpversion.autocast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# {py:mod}`bumpversion.autocast`

```{py:module} bumpversion.autocast
```

```{autodoc2-docstring} bumpversion.autocast
:allowtitles:
```

## Module Contents

### Functions

````{list-table}
:class: autosummary longtable
:align: left
* - {py:obj}`boolify <bumpversion.autocast.boolify>`
- ```{autodoc2-docstring} bumpversion.autocast.boolify
:summary:
```
* - {py:obj}`noneify <bumpversion.autocast.noneify>`
- ```{autodoc2-docstring} bumpversion.autocast.noneify
:summary:
```
* - {py:obj}`listify <bumpversion.autocast.listify>`
- ```{autodoc2-docstring} bumpversion.autocast.listify
:summary:
```
* - {py:obj}`autocast_value <bumpversion.autocast.autocast_value>`
- ```{autodoc2-docstring} bumpversion.autocast.autocast_value
:summary:
```
````

### API

````{py:function} boolify(s: str) -> bool
:canonical: bumpversion.autocast.boolify
```{autodoc2-docstring} bumpversion.autocast.boolify
```
````

````{py:function} noneify(s: str) -> None
:canonical: bumpversion.autocast.noneify
```{autodoc2-docstring} bumpversion.autocast.noneify
```
````

````{py:function} listify(s: str) -> list
:canonical: bumpversion.autocast.listify
```{autodoc2-docstring} bumpversion.autocast.listify
```
````

````{py:function} autocast_value(var: typing.Any) -> typing.Any
:canonical: bumpversion.autocast.autocast_value
```{autodoc2-docstring} bumpversion.autocast.autocast_value
```
````
Loading

0 comments on commit 0a722a5

Please sign in to comment.