|
| 1 | +## dephell_versioning |
| 2 | + |
| 3 | +[](https://travis-ci.org/dephell/dephell_versioning) |
| 4 | +[](https://ci.appveyor.com/project/orsinium/dephell-versioning) |
| 5 | +[](https://github.com/dephell/dephell_versioning/blob/master/LICENSE) |
| 6 | + |
| 7 | +Library for bumping project version. |
| 8 | + |
| 9 | +Available schemes: |
| 10 | + |
| 11 | ++ `calver` |
| 12 | ++ `comver` |
| 13 | ++ `pep` |
| 14 | ++ `roman` |
| 15 | ++ `romver` |
| 16 | ++ `semver` |
| 17 | ++ `serial` |
| 18 | ++ `zerover` |
| 19 | + |
| 20 | +Available rules (and aliases): |
| 21 | + |
| 22 | ++ `init` -- initialize versioning |
| 23 | ++ Main parts: |
| 24 | + + `major` (`breaking`) |
| 25 | + + `minor` (`feature`) |
| 26 | + + `patch` (`fix`, `micro`) |
| 27 | ++ Additional parts: |
| 28 | + + `dev` |
| 29 | + + `local` |
| 30 | + + `post` |
| 31 | ++ Pre-release management: |
| 32 | + + `pre` (`rc`, `alpha`, `beta`) |
| 33 | + + `premajor` (`prebreaking`) |
| 34 | + + `preminor` (`prefeature`) |
| 35 | + + `prepatch` (`prefix`, `premicro`) |
| 36 | + + `release` |
| 37 | + |
| 38 | +Read more about schemes and rules in the documentation for [dephell project bump](https://dephell.readthedocs.io/en/latest/cmd-project-bump.html). |
| 39 | + |
| 40 | +## Installation |
| 41 | + |
| 42 | +install from [PyPI](https://pypi.org/project/dephell-versioning/): |
| 43 | + |
| 44 | +```bash |
| 45 | +python3 -m pip install --user dephell_versioning |
| 46 | +``` |
| 47 | + |
| 48 | +## Usage |
| 49 | + |
| 50 | +Get available schemes, rules, and aliases: |
| 51 | + |
| 52 | +```python |
| 53 | +from dephell_versioning import get_aliases, get_rules, get_schemes |
| 54 | +get_schemes() |
| 55 | +# frozenset({'roman', 'pep', ..., 'comver'}) |
| 56 | + |
| 57 | +get_rules() |
| 58 | +# frozenset({'local', 'minor', ..., 'dev', 'preminor'}) |
| 59 | + |
| 60 | +get_aliases() |
| 61 | +# frozenset({'alpha', 'rc', ..., 'micro', 'breaking'}) |
| 62 | + |
| 63 | +# get rules for some scheme: |
| 64 | +get_rules(scheme='calver') |
| 65 | +# frozenset({'major', 'patch', 'init'}) |
| 66 | + |
| 67 | +# get aliases for specific rules: |
| 68 | +get_aliases(rules={'major', 'minor'}) |
| 69 | +# frozenset({'feature', 'breaking'}) |
| 70 | + |
| 71 | +``` |
| 72 | + |
| 73 | +Bump version: |
| 74 | + |
| 75 | +```python |
| 76 | +from dephell_versioning import bump_version |
| 77 | + |
| 78 | +bump_version(version='1.2.3', rule='minor', scheme='semver') |
| 79 | +# '1.3.0' |
| 80 | + |
| 81 | +# pass aliase instead of rule: |
| 82 | +bump_version(version='1.2.3', rule='feature', scheme='semver') |
| 83 | +# '1.3.0' |
| 84 | + |
| 85 | +# start rule from `+` to attach local version number: |
| 86 | +bump_version(version='1.2.3', rule='+456', scheme='semver') |
| 87 | +# '1.2.3+456' |
| 88 | + |
| 89 | +# for `init` version is optional |
| 90 | +bump_version(version='', rule='init', scheme='semver') |
| 91 | +# '0.1.0' |
| 92 | +``` |
| 93 | + |
| 94 | +Bump version in a python file: |
| 95 | + |
| 96 | +```python |
| 97 | +from dephell_versioning import bump_file |
| 98 | +from pathlib import Path |
| 99 | + |
| 100 | +# returns `True` if version was bumped |
| 101 | +bump_file(path=Path('dephell_versioning', '__init__.py'), old='0.1.0', new='0.1.1') |
| 102 | +# True |
| 103 | + |
| 104 | +# old version is optional: any version will be bumped if old isn't found |
| 105 | +bump_file(path=Path('dephell_versioning', '__init__.py'), old='', new='0.1.2') |
| 106 | +# True |
| 107 | +``` |
| 108 | + |
| 109 | +Use [dephell_discover](https://github.com/dephell/dephell_discover) to find out the current version in a python project: |
| 110 | + |
| 111 | +```python |
| 112 | +from dephell_discover import Root |
| 113 | +from pathlib import Path |
| 114 | +root = Root(path=Path(), name='dephell_discover') |
| 115 | + |
| 116 | +# root.metainfo can be None if project isn't found in the given directory |
| 117 | +if root.metainfo: |
| 118 | + print(root.metainfo.version) |
| 119 | +# '0.1.2' |
| 120 | +``` |
0 commit comments