39 Commits
1.0.1 ... 1.1.2

Author SHA1 Message Date
0666f7f593 Release Version 1.1.2
### Changed

- yaclog now only tries to use git when invoked with a command that needs it, meaning most sub commands can now be used on systems without git
2022-12-29 00:34:58 -08:00
51e28e4ef0 cleanup 2022-12-29 00:34:27 -08:00
a7cbacb687 Update changelog 2022-12-28 20:49:58 -08:00
3fa529a05c Bump actions/setup-python from 4.3.1 to 4.4.0
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.3.1 to 4.4.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4.3.1...v4.4.0)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-27 20:26:05 -08:00
396960fae0 Only import toml and gitpython when necessary
Allows for using most commands on platforms without git installed (like the a-shell app on ios where gitpython doesnt quite work)
2022-12-27 20:21:18 -08:00
c661be05dc Bump actions/setup-python from 4.2.0 to 4.3.1
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.2.0 to 4.3.1.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4.2.0...v4.3.1)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-12 23:34:48 -08:00
2f4124c0fc Test with python 3.11 2022-12-12 23:33:48 -08:00
465b818ca2 Release Version 1.1.1
### Fixed

- Fixed `yaclog release -C -c` not committing changes to cargo.toml
2022-08-14 17:39:12 -07:00
32f20e677e Release Version 1.1.0
### Added

- Added a flag to update Rust Cargo.toml files when releasing a new version
2022-08-13 20:03:24 -07:00
8421d38164 Add cargo.toml support
Added a flag to update Rust Cargo.toml files when releasing a new version
2022-08-13 20:02:45 -07:00
c5030b6060 Bump actions/setup-python from 4.0.0 to 4.2.0
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.0.0 to 4.2.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v4.0.0...v4.2.0)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-04 23:57:53 -07:00
4ce3de25c7 Bump actions/setup-python from 3.1.2 to 4.0.0
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3.1.2 to 4.0.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v3.1.2...v4.0.0)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-09 23:15:47 -07:00
6bc99c585b Merge pull request #3 from drewcassidy/dependabot/github_actions/actions/setup-python-3.1.2
Bump actions/setup-python from 3.1.1 to 3.1.2
2022-04-12 18:24:29 -07:00
32abd7bc6b Bump actions/setup-python from 3.1.1 to 3.1.2
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3.1.1 to 3.1.2.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v3.1.1...v3.1.2)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-12 11:18:19 +00:00
06df766f9f Remove license metadata (troves are fine)
oops: https://cybre.space/@cinebox/108095181597001366
2022-04-08 00:13:06 -07:00
9b0ae90ee2 Release Version 1.0.4
### Fixed

- Fixed tests folder being installed as a package
2022-04-08 00:02:03 -07:00
15e4d691f5 Add python 3.10 classifier 2022-04-08 00:01:45 -07:00
9a7e3da60d Stop gh actions from parsing "3.10" is a number 2022-04-07 23:53:19 -07:00
94f692e6c5 Run tests on Python 3.10 2022-04-07 23:47:51 -07:00
c7583388c6 Merge pull request #2 from drewcassidy/dependabot/github_actions/actions/setup-python-3.1.1
Bump actions/setup-python from 2 to 3.1.1
2022-04-07 23:45:34 -07:00
fe9aa937d2 Merge pull request #1 from drewcassidy/dependabot/github_actions/actions/checkout-3
Bump actions/checkout from 2 to 3
2022-04-07 23:44:59 -07:00
caa4560d6d Bump actions/setup-python from 2 to 3.1.1
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 2 to 3.1.1.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v2...v3.1.1)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-08 06:43:41 +00:00
03841ad07e Bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-04-08 06:43:38 +00:00
aa2390312a Enable dependabot 2022-04-07 23:43:17 -07:00
07d76cdc09 Update changelog 2022-04-07 23:35:37 -07:00
8c79e158c8 Slim package finding now that I understand it 2022-04-07 23:33:39 -07:00
21defeffce Migrate to PEP621 2022-04-07 00:10:16 -07:00
dccde1909b Release Version 1.0.3
### Fixed

- Fixed `show` command not working with Click version 8
- Fixed release message incorrectly stating if a commit will be created or not
2021-05-11 22:27:07 -07:00
c25b780772 Run tests with multiple versions of click
will be removed once click 8.0.0 reaches critical mass I guess?
2021-05-11 22:21:09 -07:00
bf2e8f670f Fix release messages 2021-05-11 22:13:50 -07:00
dc90731f3d Fix show command 2021-05-11 22:10:13 -07:00
5a6cb51d71 Release Version 1.0.2
### Changed

- Updated to support Click version 8
- Modified module documentation page titles to include a module role

### Fixed

- Fixed tag names with spaces in versions
2021-05-11 19:33:56 -07:00
52fc36ab70 Version Version 1.0.2
### Changed

- Updated to support Click version 8
- Modified module documentation page titles to include a module role

### Fixed

- Fixed tag names with spaces in versions
2021-05-11 19:26:46 -07:00
c696071b8f Fix last commit
gdi pycharm please stop doing that
2021-05-11 19:25:03 -07:00
b0419dad80 Fix tagging with spaces in version names 2021-05-11 19:23:21 -07:00
2bfaa78053 Version Version 1.0.2
### Changed

- Updated to support Click version 8
- Modified module documentation page titles to include a module role
2021-05-11 19:19:50 -07:00
524a1da4c6 Add 'Version' prefix to log 2021-05-11 19:18:54 -07:00
acedf2b401 Update docs 2021-05-11 19:12:31 -07:00
21b530c256 Update to support Click 8 2021-05-11 19:04:31 -07:00
12 changed files with 318 additions and 104 deletions

8
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,8 @@
# Set update schedule for GitHub Actions
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every weekday
interval: "daily"

View File

@ -9,13 +9,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.8, 3.9 ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
click-version: [ "click~=7.0", "click~=8.0" ]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4.4.0
with:
python-version: ${{ matrix.python-version }}
@ -23,6 +24,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install flake8
python -m pip install ${{ matrix.click-version }}
- name: Install module
run: python -m pip install .
@ -43,10 +45,10 @@ jobs:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4.4.0
with:
python-version: '3.x'
@ -64,7 +66,7 @@ jobs:
- name: Get version name and body
run: |
echo "VERSION_TILE=Version $(yaclog show -n)" >> $GITHUB_ENV
echo "VERSION_TILE=$(yaclog show -n)" >> $GITHUB_ENV
echo "$(yaclog show -mb)" >> RELEASE.md
- name: Publish to PyPI

View File

@ -2,7 +2,55 @@
All notable changes to this project will be documented in this file
## 1.0.1 - 2021-05-10
## Version 1.1.2 - 2022-12-29
### Changed
- yaclog now only tries to use git when invoked with a command that needs it, meaning most sub commands can now be used on systems without git
## Version 1.1.1 - 2022-08-15
### Fixed
- Fixed `yaclog release -C -c` not committing changes to cargo.toml
## Version 1.1.0 - 2022-08-14
### Added
- Added a flag to update Rust Cargo.toml files when releasing a new version
## Version 1.0.4 - 2022-04-08
### Fixed
- Fixed tests folder being installed as a package
## Version 1.0.3 - 2021-05-12
### Fixed
- Fixed `show` command not working with Click version 8
- Fixed release message incorrectly stating if a commit will be created or not
## Version 1.0.2 - 2021-05-12
### Changed
- Updated to support Click version 8
- Modified module documentation page titles to include a module role
### Fixed
- Fixed tag names with spaces in versions
## Version 1.0.1 - 2021-05-10
### Fixed
@ -10,7 +58,7 @@ All notable changes to this project will be documented in this file
- Improved consistency in command documentation metavars
## 1.0.0 - 2021-05-07
## Version 1.0.0 - 2021-05-07
### Changed
@ -33,7 +81,7 @@ All notable changes to this project will be documented in this file
- Extra newlines are added between versions to improve readability of the raw markdown file.
## 0.3.3 - 2021-04-27
## Version 0.3.3 - 2021-04-27
### Added
@ -48,7 +96,7 @@ All notable changes to this project will be documented in this file
- `release` now works with logs that have only unreleased changes
## 0.3.2 - 2021-04-24
## Version 0.3.2 - 2021-04-24
### Added
@ -64,7 +112,7 @@ All notable changes to this project will be documented in this file
- `release` and `entry` commands now work using empty changelogs.
## 0.3.1 - 2021-04-24
## Version 0.3.1 - 2021-04-24
### Added
@ -77,7 +125,7 @@ All notable changes to this project will be documented in this file
- `release` command for creating releases
## 0.2.0 - 2021-04-19
## Version 0.2.0 - 2021-04-19
### Added
@ -91,7 +139,7 @@ All notable changes to this project will be documented in this file
- Parser can now handle setext-style headers and H2s not conforming to the schema.
## 0.1.0 - 2021-04-16
## Version 0.1.0 - 2021-04-16
First release

View File

@ -1,5 +1,5 @@
Changelog Module
================
:py:mod:`changelog` Module
==========================
.. automodule:: yaclog.changelog
:members:

View File

@ -1,5 +1,5 @@
Markdown Module
===============
:py:mod:`markdown` Module
=========================
.. automodule:: yaclog.markdown
:members:

View File

@ -1,5 +1,5 @@
Version Module
==============
:py:mod:`version` Module
========================
.. automodule:: yaclog.version
:members:

View File

@ -1,9 +1,59 @@
[build-system]
requires = [
"setuptools >= 35.0.2",
"setuptools_scm[toml] >= 3.4",
"setuptools>=61",
"setuptools_scm>=6.2",
"wheel"
]
build-backend = "setuptools.build_meta"
[tool.setuptools_scm]
[project]
name = "yaclog"
description = "Yet another changelog CLI tool."
readme = "README.md"
authors = [{ name = "Andrew Cassidy", email = "drewcassidy@me.com" }]
keywords = ["changelog", "commandline", "markdown"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Topic :: Text Processing :: Markup :: Markdown",
"Topic :: Software Development :: Version Control :: Git",
"Topic :: Utilities"
]
requires-python = ">= 3.8"
dependencies = [
"Click >= 7.0",
"GitPython >= 3",
"packaging >= 20",
"tomlkit >= 0.11"
]
dynamic = ["version"]
[project.optional-dependencies]
docs = [
"Sphinx >= 3.5",
"sphinx-click >= 2.7",
"sphinx-rtd-theme",
"myst-parser >= 0.14",
]
[project.scripts]
yaclog = "yaclog.cli.__main__:cli"
[project.urls]
Source = "https://github.com/drewcassidy/yaclog"
Changelog = "https://github.com/drewcassidy/yaclog/blob/main/CHANGELOG.md"
Docs = "https://yaclog.readthedocs.io/"
[tool.setuptools_scm]
[tool.setuptools.packages.find]
include = ["yaclog"]

View File

@ -1,50 +0,0 @@
[metadata]
# until setuptools supports PEP621, this will have to do
name = yaclog
description = Yet another changelog CLI tool.
author = Andrew Cassidy
license = AGPLv3
license_file = LICENSE.md
long_description = file: README.md
long_description_content_type = text/markdown
keywords = changelog, commandline, markdown
classifiers =
Development Status :: 5 - Production/Stable
Intended Audience :: Developers
License :: OSI Approved :: GNU Affero General Public License v3
Operating System :: OS Independent
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Topic :: Text Processing :: Markup :: Markdown
Topic :: Software Development :: Version Control :: Git
Topic :: Utilities
project_urls =
Source = https://github.com/drewcassidy/yaclog
Changelog = https://github.com/drewcassidy/yaclog/blob/main/CHANGELOG.md
Docs = https://yaclog.readthedocs.io/
[options]
install_requires =
Click ~= 7.0
GitPython >= 3
packaging >= 20
python_requires = >= 3.8
packages = find:
[options.extras_require]
docs =
Sphinx >= 3.5
sphinx-click >= 2.7
sphinx-rtd-theme
myst-parser >= 0.14
[options.entry_points]
console_scripts =
yaclog = yaclog.cli.__main__:cli
[options.packages.find]
exclude = tests.*

View File

@ -210,13 +210,103 @@ class TestRelease(unittest.TestCase):
runner.invoke(cli, ['init']) # create the changelog
runner.invoke(cli, ['entry', '-b', 'entry number 1'])
result = runner.invoke(cli, ['release', '1.0.0', '-c'], input='y\n')
result = runner.invoke(cli, ['release', 'Version 1.0.0', '-c'], input='y\n')
check_result(self, result)
self.assertIn('Created commit', result.output)
self.assertIn('Created tag', result.output)
self.assertIn(repo.head.commit.hexsha[0:7], result.output)
self.assertEqual(repo.tags[0].name, '1.0.0')
def test_cargo(self):
"""Test updating cargo.toml files"""
runner = CliRunner()
with runner.isolated_filesystem():
with open("Cargo.toml", "w") as fp:
fp.write((
'[package]\n'
'name = "dummy"\n'
'version = "0.3.4"\n'
'authors = ["Andrew Cassidy <drewcassidy@me.com>"]\n'
'description = "A dummy crate used for testing yaclog"\n'
'keywords = ["does", "not", "exist"]\n'
'edition = "2018"\n'
))
runner.invoke(cli, ['init']) # create the changelog
runner.invoke(cli, ['entry', '-b', 'entry number 1'])
result = runner.invoke(cli, ['release', 'Version 1.0.0', '-C'])
check_result(self, result)
with open("Cargo.toml", "r") as fp:
self.assertIn('version = "1.0.0"', fp.read())
# we're just going to trust tomlkit not to mangle everything else
class TestShow(unittest.TestCase):
# noinspection PyShadowingNames
def setUp(self):
self.runner = CliRunner()
self.location = 'CHANGELOG.md'
self.log = yaclog.Changelog()
self.log.add_version(name='1.0.0').add_entry('- entry number 1')
self.log.add_version(name='Version 2.0.0').add_entry('- entry number 2', 'Added')
self.log.add_version(name='Three Point Oh').add_entry('entry number 3')
v = self.log.add_version(name='4.0.0 "Euclid"')
v.add_entry('- entry number 4')
v.add_entry('- entry number 5')
v.tags.append('TAGGED')
self.modes = {
'full': ([], lambda v, k: v.text(**k), '\n\n'),
'name': (['-n'], lambda v, k: v.name, '\n'),
'body': (['-b'], lambda v, k: v.body(**k), '\n\n'),
'header': (['-h'], lambda v, k: v.header(**k), '\n'),
}
def test_show_all(self):
"""Test showing all version information"""
with self.runner.isolated_filesystem():
self.log.write(self.location)
for mode, t in self.modes.items():
with self.subTest(mode, flags=t[0]):
check_result(self, result := self.runner.invoke(cli, ['show', '-a'] + t[0]))
self.assertEqual(t[2].join([t[1](v, {'md': False}) for v in self.log.versions]),
result.output.strip(), 'incorrect plaintext output')
check_result(self, result := self.runner.invoke(cli, ['show', '-am'] + t[0]))
self.assertEqual(t[2].join([t[1](v, {'md': True}) for v in self.log.versions]),
result.output.strip(), 'incorrect markdown output')
def test_show_version(self):
with self.runner.isolated_filesystem():
self.log.write(self.location)
for mode, t in self.modes.items():
with self.subTest(mode, flags=t[0]):
for version in self.log.versions:
check_result(self, result := self.runner.invoke(cli, ['show', version.name] + t[0]))
self.assertEqual(t[1](version, {'md': False}),
result.output.strip(), 'incorrect plaintext output')
check_result(self, result := self.runner.invoke(cli, ['show', version.name[-5:]] + t[0]))
self.assertEqual(t[1](version, {'md': False}),
result.output.strip(), 'incorrect plaintext output')
check_result(self, result := self.runner.invoke(cli, ['show', version.name, '-m'] + t[0]))
self.assertEqual(t[1](version, {'md': True}),
result.output.strip(), 'incorrect markdown output')
check_result(self, result := self.runner.invoke(cli, ['show', version.name[-5:], '-m'] + t[0]))
self.assertEqual(t[1](version, {'md': True}),
result.output.strip(), 'incorrect markdown output')
if __name__ == '__main__':
unittest.main()

View File

@ -381,14 +381,15 @@ class Changelog:
def get_version(self, name: Optional[str] = None) -> VersionEntry:
"""
Get a version from the changelog by name
Get a version from the changelog by name.
:param name: The name of the version to get, or `None` to return the most recent
:param name: The name of the version to get, or `None` to return the most recent.
The first version with this value in its name is returned.
:return: The first version with the selected name
"""
for version in self.versions:
if version.name == name or name is None:
if name in version.name or name is None:
return version
raise KeyError(f'Version {name} not found in changelog')

View File

@ -18,7 +18,6 @@ import datetime
import os.path
import click
import git
import yaclog.version
from yaclog.changelog import Changelog
@ -51,7 +50,7 @@ def init(obj: Changelog):
click.echo(f'Created new changelog file at {obj.path}')
@cli.command('format') # dont accidentally hide the `format` python builtin
@cli.command('format') # don't accidentally hide the `format` python builtin
@click.pass_obj
def reformat(obj: Changelog):
"""Reformat the changelog file."""
@ -59,24 +58,36 @@ def reformat(obj: Changelog):
click.echo(f'Reformatted changelog file at {obj.path}')
# noinspection PyShadowingNames
@cli.command(short_help='Show changes from the changelog file')
@click.option('--all', '-a', 'all_versions', is_flag=True, help='Show the entire changelog.')
@click.option('--markdown/--txt', '-m/-t', default=False, help='Display as markdown or plain text.')
@click.option('--full', '-f', 'str_func', flag_value=lambda v, k: v.text(**k), default=True,
@click.option('--full', '-f', 'mode', flag_value='full', default=True,
help='Show version header and body.')
@click.option('--name', '-n', 'str_func', flag_value=lambda v, k: v.name, help='Show only the version name')
@click.option('--body', '-b', 'str_func', flag_value=lambda v, k: v.body(**k), help='Show only the version body.')
@click.option('--header', '-h', 'str_func', flag_value=lambda v, k: v.preamble(**k),
@click.option('--name', '-n', 'mode', flag_value='name',
help='Show only the version name')
@click.option('--body', '-b', 'mode', flag_value='body',
help='Show only the version body.')
@click.option('--header', '-h', 'mode', flag_value='header',
help='Show only the version header.')
@click.argument('version_names', metavar='VERSIONS', type=str, nargs=-1)
@click.pass_obj
def show(obj: Changelog, all_versions, markdown, str_func, version_names):
def show(obj: Changelog, all_versions, markdown, mode, version_names):
"""
Show the changes for VERSIONS.
VERSIONS is a list of versions to print. If not given, the most recent version is used.
"""
functions = {
'full': (lambda v, k: v.text(**k)),
'name': (lambda v, k: v.name),
'body': (lambda v, k: v.body(**k)),
'header': (lambda v, k: v.header(**k)),
}
str_func = functions[mode]
try:
if all_versions:
versions = obj.versions
@ -85,16 +96,14 @@ def show(obj: Changelog, all_versions, markdown, str_func, version_names):
else:
versions = [obj.get_version(name) for name in version_names]
except KeyError as k:
raise click.BadArgumentUsage(k)
raise click.BadArgumentUsage(str(k))
except ValueError as v:
raise click.ClickException(v)
raise click.ClickException(str(v))
kwargs = {'md': markdown, 'color': True}
for v in versions:
text = str_func(v, kwargs)
click.echo(text)
click.echo('\n')
sep = '\n\n' if mode == 'body' or mode == 'full' else '\n'
click.echo(sep.join([str_func(v, kwargs) for v in versions]))
@cli.command(short_help='Modify version tags')
@ -115,9 +124,9 @@ def tag(obj: Changelog, add, tag_name: str, version_name: str):
else:
version = obj.current_version()
except KeyError as k:
raise click.BadArgumentUsage(k)
raise click.BadArgumentUsage(str(k))
except ValueError as v:
raise click.ClickException(v)
raise click.ClickException(str(v))
if add:
version.tags.append(tag_name)
@ -153,7 +162,7 @@ def entry(obj: Changelog, bullets, paragraphs, section_name, version_name):
else:
version = obj.current_version(released=False, new_version=True)
except KeyError as k:
raise click.BadArgumentUsage(k)
raise click.BadArgumentUsage(str(k))
for p in paragraphs:
version.add_entry(p, section_name)
@ -172,19 +181,28 @@ def entry(obj: Changelog, bullets, paragraphs, section_name, version_name):
@cli.command(short_help='Release versions.')
@click.option('-M', '--major', 'rel_seg', flag_value=0, default=None, help='Increment major version number.')
@click.option('-m', '--minor', 'rel_seg', flag_value=1, help='Increment minor version number.')
@click.option('-p', '--patch', 'rel_seg', flag_value=2, help='Increment patch number.')
@click.option('-a', '--alpha', 'pre_seg', flag_value='a', default=None, help='Increment alpha version number.')
@click.option('-b', '--beta', 'pre_seg', flag_value='b', help='Increment beta version number.')
@click.option('-r', '--rc', 'pre_seg', flag_value='rc', help='Increment release candidate version number.')
@click.option('-f', '--full', 'pre_seg', flag_value='', help='Clear the prerelease value creating a full release.')
@click.option('-M', '--major', 'rel_seg', flag_value=0, type=int, default=None,
help='Increment major version number.')
@click.option('-m', '--minor', 'rel_seg', flag_value=1, type=int,
help='Increment minor version number.')
@click.option('-p', '--patch', 'rel_seg', flag_value=2, type=int,
help='Increment patch number.')
@click.option('-a', '--alpha', 'pre_seg', flag_value='a', type=str, default=None,
help='Increment alpha version number.')
@click.option('-b', '--beta', 'pre_seg', flag_value='b', type=str,
help='Increment beta version number.')
@click.option('-r', '--rc', 'pre_seg', flag_value='rc', type=str,
help='Increment release candidate version number.')
@click.option('-f', '--full', 'pre_seg', flag_value='',
help='Clear the prerelease value creating a full release.')
@click.option('-c', '--commit', is_flag=True,
help='Create a git commit tagged with the new version number. '
'If there are no changes to commit, the current commit will be tagged instead.')
@click.option('-C', '--cargo', '-🦀', is_flag=True,
help='Update the version in a Rust cargo.toml manifest file.')
@click.argument('version_name', metavar='VERSION', type=str, default=None, required=False)
@click.pass_obj
def release(obj: Changelog, version_name, rel_seg, pre_seg, commit):
def release(obj: Changelog, version_name, rel_seg, pre_seg, commit, cargo):
"""
Release VERSION, or a version incremented from the last release.
@ -196,7 +214,7 @@ def release(obj: Changelog, version_name, rel_seg, pre_seg, commit):
other kinds of prerelease.
"""
if rel_seg is None and pre_seg is None and not version_name and not commit:
if rel_seg is None and pre_seg is None and not version_name and not commit and not cargo:
click.echo('Nothing to release!')
raise click.Abort
@ -229,7 +247,17 @@ def release(obj: Changelog, version_name, rel_seg, pre_seg, commit):
obj.write()
click.echo(f"Renamed {click.style(old_name, fg='blue')} to {click.style(new_name, fg='blue')}")
short_version, *_ = yaclog.version.extract_version(cur_version.name)
if not short_version:
short_version = cur_version.name.replace(' ', '-')
if cargo:
from ..cli import cargo_toml
cargo_toml.set_version("Cargo.toml", str(short_version))
click.echo("Updated Cargo.toml")
if commit:
import git
repo = git.Repo(os.curdir)
if repo.bare:
@ -237,10 +265,13 @@ def release(obj: Changelog, version_name, rel_seg, pre_seg, commit):
repo.index.add(obj.path)
if cargo:
repo.index.add("Cargo.toml")
tracked = len(repo.index.diff(repo.head.commit))
untracked = len(repo.index.diff(None))
message = [['Commit and create tag', 'Create tag'][min(tracked, 1)], 'for']
message = [['Create tag', 'Commit and create tag'][min(tracked, 1)], 'for']
if not cur_version.released:
message.append('non-release')
@ -255,12 +286,13 @@ def release(obj: Changelog, version_name, rel_seg, pre_seg, commit):
click.confirm(' '.join(message), abort=True)
if tracked > 0:
commit = repo.index.commit(f'Version {cur_version.name}\n\n{cur_version.body()}')
commit = repo.index.commit(f'Release {cur_version.name}\n\n{cur_version.body()}')
click.echo(f"Created commit {click.style(repo.head.commit.hexsha[0:7], fg='green')}")
else:
commit = repo.head.commit
repo_tag = repo.create_tag(cur_version.name, ref=commit, message=cur_version.body(False))
# noinspection PyTypeChecker
repo_tag = repo.create_tag(short_version, ref=commit, message=cur_version.body(False))
click.echo(f"Created tag {click.style(repo_tag.name, fg='green')}.")

33
yaclog/cli/cargo_toml.py Normal file
View File

@ -0,0 +1,33 @@
# yaclog: yet another changelog tool
# Copyright (c) 2022. Andrew Cassidy
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from tomlkit import dumps
from tomlkit import parse
def set_version(path, version):
"""
Set the version string in a cargo.toml file
:param path: path-like file location
:param version: version string to overwrite with
"""
with open(path, 'r+') as fp:
toml = parse(fp.read())
toml['package']['version'] = version
fp.seek(0)
fp.write(dumps(toml))
fp.truncate()