16 Commits
1.0.0 ... 1.0.3

Author SHA1 Message Date
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
04a9c712f9 update changelog 2021-05-09 19:42:01 -07:00
d35b7fee83 Fixed broken header in new changelogs 2021-05-09 19:39:48 -07:00
38560702f4 Path metavar 2021-05-08 00:00:41 -07:00
2d1cc4ede4 Metavar capitalization 2021-05-07 23:59:44 -07:00
9 changed files with 169 additions and 46 deletions

View File

@ -10,6 +10,7 @@ jobs:
strategy: strategy:
matrix: matrix:
python-version: [ 3.8, 3.9 ] python-version: [ 3.8, 3.9 ]
click-version: [ click~=7.0, click~=8.0 ]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -23,6 +24,7 @@ jobs:
run: | run: |
python -m pip install --upgrade pip python -m pip install --upgrade pip
python -m pip install flake8 python -m pip install flake8
python -m pip install ${{ matrix.click-version }}
- name: Install module - name: Install module
run: python -m pip install . run: python -m pip install .
@ -64,7 +66,7 @@ jobs:
- name: Get version name and body - name: Get version name and body
run: | run: |
echo "VERSION_TILE=Version $(yaclog show -n)" >> $GITHUB_ENV echo "VERSION_TILE=$(yaclog show -n)" >> $GITHUB_ENV
echo "$(yaclog show -mb)" >> RELEASE.md echo "$(yaclog show -mb)" >> RELEASE.md
- name: Publish to PyPI - name: Publish to PyPI

View File

@ -2,7 +2,35 @@
All notable changes to this project will be documented in this file All notable changes to this project will be documented in this file
## 1.0.0 - 2021-05-07 ## 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
- Fixed broken header in new changelogs
- Improved consistency in command documentation metavars
## Version 1.0.0 - 2021-05-07
### Changed ### Changed
@ -25,7 +53,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. - 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 ### Added
@ -40,7 +68,7 @@ All notable changes to this project will be documented in this file
- `release` now works with logs that have only unreleased changes - `release` now works with logs that have only unreleased changes
## 0.3.2 - 2021-04-24 ## Version 0.3.2 - 2021-04-24
### Added ### Added
@ -56,7 +84,7 @@ All notable changes to this project will be documented in this file
- `release` and `entry` commands now work using empty changelogs. - `release` and `entry` commands now work using empty changelogs.
## 0.3.1 - 2021-04-24 ## Version 0.3.1 - 2021-04-24
### Added ### Added
@ -69,7 +97,7 @@ All notable changes to this project will be documented in this file
- `release` command for creating releases - `release` command for creating releases
## 0.2.0 - 2021-04-19 ## Version 0.2.0 - 2021-04-19
### Added ### Added
@ -83,7 +111,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. - 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 First release

View File

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

View File

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

View File

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

View File

@ -29,7 +29,7 @@ project_urls =
[options] [options]
install_requires = install_requires =
Click ~= 7.0 Click >= 7.0, < 9.0
GitPython >= 3 GitPython >= 3
packaging >= 20 packaging >= 20
python_requires = >= 3.8 python_requires = >= 3.8

View File

@ -28,6 +28,12 @@ class TestCreation(unittest.TestCase):
self.assertTrue(os.path.exists(os.path.abspath(location)), 'yaclog init did not create a file') self.assertTrue(os.path.exists(os.path.abspath(location)), 'yaclog init did not create a file')
self.assertIn(location, result.output, "yaclog init did not echo the file's correct location") self.assertIn(location, result.output, "yaclog init did not echo the file's correct location")
with open(location, 'r') as fp:
self.assertEqual('# Changelog\n', fp.readline())
self.assertEqual('\n', fp.readline())
self.assertEqual('All notable changes to this project will be documented in this file',
fp.readline().rstrip())
with open(location, 'w') as fp: with open(location, 'w') as fp:
fp.write(err_str) fp.write(err_str)
@ -204,7 +210,7 @@ class TestRelease(unittest.TestCase):
runner.invoke(cli, ['init']) # create the changelog runner.invoke(cli, ['init']) # create the changelog
runner.invoke(cli, ['entry', '-b', 'entry number 1']) 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) check_result(self, result)
self.assertIn('Created commit', result.output) self.assertIn('Created commit', result.output)
self.assertIn('Created tag', result.output) self.assertIn('Created tag', result.output)
@ -212,5 +218,70 @@ class TestRelease(unittest.TestCase):
self.assertEqual(repo.tags[0].name, '1.0.0') self.assertEqual(repo.tags[0].name, '1.0.0')
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__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -223,7 +223,7 @@ class Changelog:
""" """
def __init__(self, path=None, def __init__(self, path=None,
preamble: str = "Changelog\n\nAll notable changes to this project will be documented in this file"): preamble: str = "# Changelog\n\nAll notable changes to this project will be documented in this file"):
""" """
Contents will be automatically read from disk if the file exists Contents will be automatically read from disk if the file exists
@ -381,14 +381,15 @@ class Changelog:
def get_version(self, name: Optional[str] = None) -> VersionEntry: 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 :return: The first version with the selected name
""" """
for version in self.versions: for version in self.versions:
if version.name == name or name is None: if name in version.name or name is None:
return version return version
raise KeyError(f'Version {name} not found in changelog') raise KeyError(f'Version {name} not found in changelog')

View File

@ -25,7 +25,7 @@ from yaclog.changelog import Changelog
@click.group() @click.group()
@click.option('--path', envvar='YACLOG_PATH', default='CHANGELOG.md', show_default=True, @click.option('--path', envvar='YACLOG_PATH', metavar='FILE', default='CHANGELOG.md', show_default=True,
type=click.Path(dir_okay=False, writable=True, readable=True), type=click.Path(dir_okay=False, writable=True, readable=True),
help='Location of the changelog file.') help='Location of the changelog file.')
@click.version_option() @click.version_option()
@ -59,24 +59,36 @@ def reformat(obj: Changelog):
click.echo(f'Reformatted changelog file at {obj.path}') click.echo(f'Reformatted changelog file at {obj.path}')
# noinspection PyShadowingNames
@cli.command(short_help='Show changes from the changelog file') @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('--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('--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.') 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('--name', '-n', 'mode', flag_value='name',
@click.option('--body', '-b', 'str_func', flag_value=lambda v, k: v.body(**k), help='Show only the version body.') help='Show only the version name')
@click.option('--header', '-h', 'str_func', flag_value=lambda v, k: v.preamble(**k), @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.') help='Show only the version header.')
@click.argument('version_names', metavar='VERSIONS', type=str, nargs=-1) @click.argument('version_names', metavar='VERSIONS', type=str, nargs=-1)
@click.pass_obj @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. Show the changes for VERSIONS.
VERSIONS is a list of versions to print. If not given, the most recent version is used. 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: try:
if all_versions: if all_versions:
versions = obj.versions versions = obj.versions
@ -85,16 +97,14 @@ def show(obj: Changelog, all_versions, markdown, str_func, version_names):
else: else:
versions = [obj.get_version(name) for name in version_names] versions = [obj.get_version(name) for name in version_names]
except KeyError as k: except KeyError as k:
raise click.BadArgumentUsage(k) raise click.BadArgumentUsage(str(k))
except ValueError as v: except ValueError as v:
raise click.ClickException(v) raise click.ClickException(str(v))
kwargs = {'md': markdown, 'color': True} kwargs = {'md': markdown, 'color': True}
for v in versions: sep = '\n\n' if mode == 'body' or mode == 'full' else '\n'
text = str_func(v, kwargs) click.echo(sep.join([str_func(v, kwargs) for v in versions]))
click.echo(text)
click.echo('\n')
@cli.command(short_help='Modify version tags') @cli.command(short_help='Modify version tags')
@ -115,9 +125,9 @@ def tag(obj: Changelog, add, tag_name: str, version_name: str):
else: else:
version = obj.current_version() version = obj.current_version()
except KeyError as k: except KeyError as k:
raise click.BadArgumentUsage(k) raise click.BadArgumentUsage(str(k))
except ValueError as v: except ValueError as v:
raise click.ClickException(v) raise click.ClickException(str(v))
if add: if add:
version.tags.append(tag_name) version.tags.append(tag_name)
@ -131,8 +141,8 @@ def tag(obj: Changelog, add, tag_name: str, version_name: str):
@cli.command(short_help='Add entries to the changelog.') @cli.command(short_help='Add entries to the changelog.')
@click.option('--bullet', '-b', 'bullets', metavar='text', multiple=True, type=str, help='Add a bullet point.') @click.option('--bullet', '-b', 'bullets', metavar='TEXT', multiple=True, type=str, help='Add a bullet point.')
@click.option('--paragraph', '-p', 'paragraphs', metavar='text', multiple=True, type=str, help='Add a paragraph') @click.option('--paragraph', '-p', 'paragraphs', metavar='TEXT', multiple=True, type=str, help='Add a paragraph')
@click.argument('section_name', metavar='SECTION', type=str, default='', required=False) @click.argument('section_name', metavar='SECTION', type=str, default='', required=False)
@click.argument('version_name', metavar='VERSION', type=str, default=None, required=False) @click.argument('version_name', metavar='VERSION', type=str, default=None, required=False)
@click.pass_obj @click.pass_obj
@ -153,7 +163,7 @@ def entry(obj: Changelog, bullets, paragraphs, section_name, version_name):
else: else:
version = obj.current_version(released=False, new_version=True) version = obj.current_version(released=False, new_version=True)
except KeyError as k: except KeyError as k:
raise click.BadArgumentUsage(k) raise click.BadArgumentUsage(str(k))
for p in paragraphs: for p in paragraphs:
version.add_entry(p, section_name) version.add_entry(p, section_name)
@ -172,13 +182,20 @@ def entry(obj: Changelog, bullets, paragraphs, section_name, version_name):
@cli.command(short_help='Release versions.') @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', '--major', 'rel_seg', flag_value=0, type=int, default=None,
@click.option('-m', '--minor', 'rel_seg', flag_value=1, help='Increment minor version number.') help='Increment major version number.')
@click.option('-p', '--patch', 'rel_seg', flag_value=2, help='Increment patch number.') @click.option('-m', '--minor', 'rel_seg', flag_value=1, type=int,
@click.option('-a', '--alpha', 'pre_seg', flag_value='a', default=None, help='Increment alpha version number.') help='Increment minor version number.')
@click.option('-b', '--beta', 'pre_seg', flag_value='b', help='Increment beta version number.') @click.option('-p', '--patch', 'rel_seg', flag_value=2, type=int,
@click.option('-r', '--rc', 'pre_seg', flag_value='rc', help='Increment release candidate version number.') help='Increment patch number.')
@click.option('-f', '--full', 'pre_seg', flag_value='', help='Clear the prerelease value creating a full release.') @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, @click.option('-c', '--commit', is_flag=True,
help='Create a git commit tagged with the new version number. ' 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.') 'If there are no changes to commit, the current commit will be tagged instead.')
@ -240,7 +257,7 @@ def release(obj: Changelog, version_name, rel_seg, pre_seg, commit):
tracked = len(repo.index.diff(repo.head.commit)) tracked = len(repo.index.diff(repo.head.commit))
untracked = len(repo.index.diff(None)) 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: if not cur_version.released:
message.append('non-release') message.append('non-release')
@ -255,12 +272,16 @@ def release(obj: Changelog, version_name, rel_seg, pre_seg, commit):
click.confirm(' '.join(message), abort=True) click.confirm(' '.join(message), abort=True)
if tracked > 0: 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')}") click.echo(f"Created commit {click.style(repo.head.commit.hexsha[0:7], fg='green')}")
else: else:
commit = repo.head.commit commit = repo.head.commit
repo_tag = repo.create_tag(cur_version.name, ref=commit, message=cur_version.body(False)) short_version, *_ = yaclog.version.extract_version(cur_version.name)
if not short_version:
short_version = cur_version.name.replace(' ', '-')
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')}.") click.echo(f"Created tag {click.style(repo_tag.name, fg='green')}.")