Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #407 from dephell/better-bump
Browse files Browse the repository at this point in the history
`dephell project bump` improvements
  • Loading branch information
orsinium committed Mar 18, 2020
2 parents 72c8cad + cf43ee4 commit 3670328
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
27 changes: 26 additions & 1 deletion dephell/commands/project_bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@


FILE_NAMES = (
# dunder
'__init__.py',
'__version__.py',
'__about__.py',

# sunder
'_version.py',
'_about.py',

# human
'version.py',
'about.py',
)

DOCS_PATHS = (
('docs', 'conf.py'),
('wiki', 'conf.py'),
)


Expand All @@ -43,7 +55,8 @@ def __call__(self) -> bool:
old_version = None
root = None
loader = None
package = PackageRoot(path=Path(self.config['project']))
project_path = Path(self.config['project'])
package = PackageRoot(path=project_path)

if 'from' in self.config:
# get project metainfo
Expand Down Expand Up @@ -99,6 +112,7 @@ def __call__(self) -> bool:

@staticmethod
def _bump_project(project: PackageRoot, old: str, new: str) -> Iterator[Path]:
# bump in the source
for package in project.packages:
for path in package:
if path.name not in FILE_NAMES:
Expand All @@ -107,6 +121,17 @@ def _bump_project(project: PackageRoot, old: str, new: str) -> Iterator[Path]:
if file_bumped:
yield path

# bump in the docs
for parts in DOCS_PATHS:
path = project.path.joinpath(*parts)
if not path.exists():
continue
content = path.read_text()
new_content = content.replace(old, new)
if new_content != content:
path.write_text(new_content)
yield path

def _update_metadata(self, root, loader, new_version) -> bool:
if root is None:
return False
Expand Down
2 changes: 2 additions & 0 deletions dephell/converters/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ def dumps(self, reqs, project: RootDependency, content=None) -> str:
section['extras'] = tomlkit.table()
# add new extras
for extra, deps in extras.items():
if list(section['extras'].get(extra, [])) == deps:
continue
section['extras'][extra] = deps
elif 'extras' in section:
# deop all old extras if there are no new extras
Expand Down
17 changes: 16 additions & 1 deletion docs/cmd-project-bump.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ It's recommend to explicitly add `versioning` in config to let your users know w
versioning = "semver"
```

If you don't have [dephell config](config), you should explicitly specify `from` parameter:

```bash
dephell project bump --from-format=poetry --from-path=pyproject.toml minor
```

Or just add it into your config:

```toml
[tool.dephell.main]
from = {format = "poetry", path = "pyproject.toml"}
```

Command steps:

1. Try to detect version from `from` file.
Expand All @@ -23,7 +36,9 @@ Command steps:
1. Write new version in source code. DepHell looks for `__version__` variable in project source and writes new version in it.
1. Write new version in `from` file.

Also, the command adds git tag if `--tag` option (or `tag = <your_template>` in the config) is specified as template.
## Git tag

The command adds git tag if `--tag` option (or `tag = <your_template>` in the config) is specified as template.
Template can be string with `{version}` placeholder (e.g. `v.{version}`) or just prefix string (e.g. `v.`)

```bash
Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
copyright = '{}, Gram (@orsinium)'.format(date.today().year)
author = 'Gram (@orsinium)'

version = '0.7'
release = '0.7.0'
version = '0.8.1'
release = version

language = None
exclude_patterns = []
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ to = {format = "setuppy", path = "setup.py"}

# explicitly specify your versioning scheme to let your users know what they can expect
versioning = "semver"
# git tag template for releases
tag = "v."

# Make lockfile
# $ dephell deps convert --env=lock
Expand Down Expand Up @@ -201,6 +203,6 @@ docs = ["alabaster", "pygments-github-lexers", "recommonmark", "sphinx"]
tests = ["aioresponses", "pytest", "requests-mock"]
full = [
"aiofiles", "appdirs", "autopep8", "bowler", "colorama", "docker",
"dockerpty", "fissix", "graphviz", "html5lib", "python-gnupg", "pygments",
"dockerpty", "fissix", "graphviz", "html5lib", "pygments", "python-gnupg",
"ruamel-yaml", "tabulate", "yapf",
]

0 comments on commit 3670328

Please sign in to comment.