python-kacl 0.4.7__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. {python_kacl-0.4.7/python_kacl.egg-info → python_kacl-0.5.0}/PKG-INFO +9 -10
  2. {python_kacl-0.4.7 → python_kacl-0.5.0}/README.md +8 -9
  3. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/__init__.py +1 -1
  4. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/document.py +41 -22
  5. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/kacl_cli.py +65 -31
  6. {python_kacl-0.4.7 → python_kacl-0.5.0/python_kacl.egg-info}/PKG-INFO +9 -10
  7. {python_kacl-0.4.7 → python_kacl-0.5.0}/setup.py +1 -1
  8. {python_kacl-0.4.7 → python_kacl-0.5.0}/tests/test_cli.py +34 -0
  9. {python_kacl-0.4.7 → python_kacl-0.5.0}/tests/test_kacl.py +11 -0
  10. {python_kacl-0.4.7 → python_kacl-0.5.0}/LICENSE +0 -0
  11. {python_kacl-0.4.7 → python_kacl-0.5.0}/MANIFEST.in +0 -0
  12. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/__main__.py +0 -0
  13. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/changes.py +0 -0
  14. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/config/kacl-default.yml +0 -0
  15. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/config.py +0 -0
  16. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/element.py +0 -0
  17. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/exception.py +0 -0
  18. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/link_provider.py +0 -0
  19. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/parser.py +0 -0
  20. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/serializer.py +0 -0
  21. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/validation.py +0 -0
  22. {python_kacl-0.4.7 → python_kacl-0.5.0}/kacl/version.py +0 -0
  23. {python_kacl-0.4.7 → python_kacl-0.5.0}/python_kacl.egg-info/SOURCES.txt +0 -0
  24. {python_kacl-0.4.7 → python_kacl-0.5.0}/python_kacl.egg-info/dependency_links.txt +0 -0
  25. {python_kacl-0.4.7 → python_kacl-0.5.0}/python_kacl.egg-info/entry_points.txt +0 -0
  26. {python_kacl-0.4.7 → python_kacl-0.5.0}/python_kacl.egg-info/not-zip-safe +0 -0
  27. {python_kacl-0.4.7 → python_kacl-0.5.0}/python_kacl.egg-info/requires.txt +0 -0
  28. {python_kacl-0.4.7 → python_kacl-0.5.0}/python_kacl.egg-info/top_level.txt +0 -0
  29. {python_kacl-0.4.7 → python_kacl-0.5.0}/setup.cfg +0 -0
  30. {python_kacl-0.4.7 → python_kacl-0.5.0}/tests/__init__.py +0 -0
  31. {python_kacl-0.4.7 → python_kacl-0.5.0}/tests/snapshot_directory.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-kacl
3
- Version: 0.4.7
3
+ Version: 0.5.0
4
4
  Summary: Python module and CLI tool for validating and modifying Changelogs in "keep-a-changelog" format"
5
5
  Home-page: https://gitlab.com/schmieder.matthias/python-kacl.git
6
6
  Author: Matthias Schmieder
@@ -441,13 +441,12 @@ in order to generate the correct urls, `python-kacl` allows you to define three
441
441
 
442
442
  ```yaml
443
443
  kacl:
444
- git:
445
- links:
446
- # The host url is optional and will be automatically determined using your the git repository. If run on gitlab CI the host will be determined by CI_PROJECT_URL if not specified here.
447
- host_url: https://github.com/mschmieder/kacl-cli
448
- compare_versions_template: '{host}/compare/v{previous_version}...v{version}'
449
- unreleased_changes_template: '{host}/tree/v{latest_version}...HEAD'
450
- initial_version_template: '{host}/tree/v{version}'
444
+ links:
445
+ # The host url is optional and will be automatically determined using your git repository. If run on gitlab CI the host will be determined by CI_PROJECT_URL if not specified here.
446
+ host_url: https://github.com/mschmieder/kacl-cli
447
+ compare_versions_template: '{host}/compare/v{previous_version}...v{version}'
448
+ unreleased_changes_template: '{host}/compare/v{latest_version}...HEAD'
449
+ initial_version_template: '{host}/tree/v{version}'
451
450
  ```
452
451
 
453
452
  Using the python format syntax you can generate any links you want. The available replacement variables are `version`, `previous_version`, `host` and `latest_version`.
@@ -554,7 +553,7 @@ kacl:
554
553
  tag_name: "v{new_version}"
555
554
  tag_description: "Version v{new_version} released"
556
555
  links:
557
- # The host url is optional and will be automatically determined using your the git repository
556
+ # The host url is optional and will be automatically determined using your git repository
558
557
  # host_url: https://github.com/mschmieder/kacl-cli
559
558
  compare_versions_template: '{host}/compare/{previous_version}...{version}'
560
559
  unreleased_changes_template: '{host}/compare/{latest_version}...master'
@@ -581,7 +580,7 @@ source ./venv/bin/activate
581
580
  pip install -e .
582
581
 
583
582
  # install development requirements
584
- pip install -r dev-requirements
583
+ pip install -r dev-requirements.txt
585
584
 
586
585
  # run the tests
587
586
  python3 -m pytest --snapshot-update --allow-snapshot-deletion
@@ -420,13 +420,12 @@ in order to generate the correct urls, `python-kacl` allows you to define three
420
420
 
421
421
  ```yaml
422
422
  kacl:
423
- git:
424
- links:
425
- # The host url is optional and will be automatically determined using your the git repository. If run on gitlab CI the host will be determined by CI_PROJECT_URL if not specified here.
426
- host_url: https://github.com/mschmieder/kacl-cli
427
- compare_versions_template: '{host}/compare/v{previous_version}...v{version}'
428
- unreleased_changes_template: '{host}/tree/v{latest_version}...HEAD'
429
- initial_version_template: '{host}/tree/v{version}'
423
+ links:
424
+ # The host url is optional and will be automatically determined using your git repository. If run on gitlab CI the host will be determined by CI_PROJECT_URL if not specified here.
425
+ host_url: https://github.com/mschmieder/kacl-cli
426
+ compare_versions_template: '{host}/compare/v{previous_version}...v{version}'
427
+ unreleased_changes_template: '{host}/compare/v{latest_version}...HEAD'
428
+ initial_version_template: '{host}/tree/v{version}'
430
429
  ```
431
430
 
432
431
  Using the python format syntax you can generate any links you want. The available replacement variables are `version`, `previous_version`, `host` and `latest_version`.
@@ -533,7 +532,7 @@ kacl:
533
532
  tag_name: "v{new_version}"
534
533
  tag_description: "Version v{new_version} released"
535
534
  links:
536
- # The host url is optional and will be automatically determined using your the git repository
535
+ # The host url is optional and will be automatically determined using your git repository
537
536
  # host_url: https://github.com/mschmieder/kacl-cli
538
537
  compare_versions_template: '{host}/compare/{previous_version}...{version}'
539
538
  unreleased_changes_template: '{host}/compare/{latest_version}...master'
@@ -560,7 +559,7 @@ source ./venv/bin/activate
560
559
  pip install -e .
561
560
 
562
561
  # install development requirements
563
- pip install -r dev-requirements
562
+ pip install -r dev-requirements.txt
564
563
 
565
564
  # run the tests
566
565
  python3 -m pytest --snapshot-update --allow-snapshot-deletion
@@ -1,5 +1,5 @@
1
1
  # Version of the python-kacl package
2
- __version__ = "0.4.7"
2
+ __version__ = "0.5.0"
3
3
 
4
4
  from kacl.document import KACLDocument
5
5
  from kacl.serializer import KACLMarkdownSerializer
@@ -220,7 +220,14 @@ class KACLDocument:
220
220
  self.__versions.insert(0, unreleased_version)
221
221
  unreleased_version.add(section.capitalize(), data)
222
222
 
223
- def release(self, version=None, link=None, auto_link=False, increment=None):
223
+ def release(
224
+ self,
225
+ version=None,
226
+ link=None,
227
+ auto_link=False,
228
+ increment=None,
229
+ allow_no_changes=False,
230
+ ):
224
231
  """Creates a new release version by copying the 'unreleased' changes into the
225
232
  new version
226
233
 
@@ -228,32 +235,14 @@ class KACLDocument:
228
235
  link {[str]} -- url the version will be linked with (default: {None})
229
236
  version {[str]} -- semantic versioning string
230
237
  increment {[str]} -- use either 'patch', 'minor', or 'major' to automatically increment the last version
238
+ allow_no_changes {[bool]} -- allow releasing a version without changes (default: {False})
231
239
  """
232
240
 
233
241
  # check if 'post_release_version_prefix' is set
234
242
  post_release_version_prefix = self.config.post_release_version_prefix
235
243
 
236
244
  if increment:
237
- v = self.current_version()
238
- if v:
239
- sv = semver.VersionInfo.parse(v)
240
- if "post" == increment:
241
- if not post_release_version_prefix:
242
- raise KACLException(
243
- "No 'post_release_version_prefix' set in the config. Incrementing not possible"
244
- )
245
- sv = sv.bump_prerelease(token=post_release_version_prefix)
246
- elif "patch" == increment:
247
- sv = sv.bump_patch()
248
- elif "minor" == increment:
249
- sv = sv.bump_minor()
250
- elif "major" == increment:
251
- sv = sv.bump_major()
252
- version = str(sv)
253
- else:
254
- raise KACLException(
255
- "No previously released version found. Incrementing not possible"
256
- )
245
+ version = self.next_version(increment=increment)
257
246
 
258
247
  # check that version is a valid semantic version
259
248
  future_version = semver.VersionInfo.parse(
@@ -261,7 +250,7 @@ class KACLDocument:
261
250
  ) # --> will throw a ValueError if version is not a valid semver
262
251
 
263
252
  # check if there are changes to release
264
- if self.has_changes() is False:
253
+ if not allow_no_changes and not self.has_changes():
265
254
  raise KACLException(
266
255
  "The current changelog has no changes. You can only release if changes are available."
267
256
  )
@@ -382,6 +371,36 @@ class KACLDocument:
382
371
  if res and len(res):
383
372
  return res[0]
384
373
 
374
+ def next_version(self, increment="patch"):
375
+ """returns the current version (last released)
376
+ increment {[str]} -- use either 'patch', 'minor', or 'major' to automatically increment the last version
377
+ Returns:
378
+ [str] -- latest released version, None if none is available
379
+ """
380
+ v = self.current_version()
381
+ next_version = None
382
+ if v:
383
+ sv = semver.VersionInfo.parse(v)
384
+ if "post" == increment:
385
+ if not self.config.post_release_version_prefix:
386
+ raise KACLException(
387
+ "No 'post_release_version_prefix' set in the config. Incrementing not possible"
388
+ )
389
+ sv = sv.bump_prerelease(token=self.config.post_release_version_prefix)
390
+ elif "patch" == increment:
391
+ sv = sv.bump_patch()
392
+ elif "minor" == increment:
393
+ sv = sv.bump_minor()
394
+ elif "major" == increment:
395
+ sv = sv.bump_major()
396
+ next_version = str(sv)
397
+ else:
398
+ raise KACLException(
399
+ "No previously released version found. Incrementing not possible"
400
+ )
401
+
402
+ return next_version
403
+
385
404
  def current_version(self):
386
405
  """returns the current version (last released)
387
406
 
@@ -15,6 +15,35 @@ from kacl.config import KACLConfig
15
15
  from kacl.exception import KACLException
16
16
 
17
17
 
18
+ def check_auto_increment(version):
19
+ # check if the version string indicates automatic increment
20
+ increment = None
21
+ if version in ["major", "minor", "patch", "post"]:
22
+ increment = version
23
+ version = None # reset
24
+ else:
25
+ # check if version is a valid semantic version
26
+ try:
27
+ semver.VersionInfo.parse(version)
28
+ except Exception:
29
+ click.echo(
30
+ click.style("Error: ", fg="red")
31
+ + f'"{version}" not a valid semantic version.'
32
+ )
33
+ sys.exit(1)
34
+
35
+ return version, increment
36
+
37
+
38
+ def raise_on_invalid(kacl_changelog):
39
+ if not kacl_changelog.is_valid():
40
+ click.echo(
41
+ click.style("Error: ", fg="red")
42
+ + "Changelog is not valid. Run 'kacl-cli verify' for more information."
43
+ )
44
+ sys.exit(1)
45
+
46
+
18
47
  def load_changelog(ctx):
19
48
  config_file_path = ctx.obj["config"]
20
49
  input_file = ctx.obj["file"]
@@ -124,6 +153,27 @@ def current(ctx):
124
153
  click.echo(current_version)
125
154
 
126
155
 
156
+ @cli.command()
157
+ @click.pass_context
158
+ @click.argument("version", type=str)
159
+ def next(ctx, version):
160
+ """Returns the next version based on the current version from the Changelog."""
161
+ kacl_changelog = load_changelog(ctx)
162
+ raise_on_invalid(kacl_changelog)
163
+
164
+ version, increment = check_auto_increment(version)
165
+
166
+ if increment:
167
+ version = kacl_changelog.next_version(increment=increment)
168
+
169
+ # check that version is a valid semantic version
170
+ future_version = semver.VersionInfo.parse(
171
+ version
172
+ ) # --> will throw a ValueError if version is not a valid semver
173
+
174
+ click.echo(future_version)
175
+
176
+
127
177
  @cli.command()
128
178
  @click.pass_context
129
179
  @click.argument("version", type=str)
@@ -343,6 +393,11 @@ def verify(ctx, as_json):
343
393
  is_flag=True,
344
394
  help='If passed this will allow to commit/tag even on a "dirty".',
345
395
  )
396
+ @click.option(
397
+ "--allow-no-changes",
398
+ is_flag=True,
399
+ help="If passed this will allow to release without any changes.",
400
+ )
346
401
  def release(
347
402
  ctx,
348
403
  version,
@@ -356,6 +411,7 @@ def release(
356
411
  tag_name,
357
412
  tag_description,
358
413
  allow_dirty,
414
+ allow_no_changes,
359
415
  ):
360
416
  """Creates a release for the latest 'unreleased' changes. Use '--modify' to directly modify the changelog file.
361
417
  You can automatically use the latest version by using the version keywords 'major', 'minor', 'patch', 'post'
@@ -368,31 +424,11 @@ def release(
368
424
  """
369
425
  kacl_changelog = load_changelog(ctx)
370
426
  kacl_config = kacl_changelog.config
427
+ raise_on_invalid(kacl_changelog)
371
428
 
372
- if not kacl_changelog.is_valid():
373
- click.echo(
374
- click.style("Error: ", fg="red")
375
- + "Changelog is not valid. Run 'kacl-cli verify' for more information."
376
- )
377
- sys.exit(1)
378
-
379
- # check if the version string indicates automatic increment
380
- increment = None
381
- if version in ["major", "minor", "patch", "post"]:
382
- increment = version
383
- version = None # reset
384
- else:
385
- # check if version is a valid semantic version
386
- try:
387
- semver.VersionInfo.parse(version)
388
- except Exception:
389
- click.echo(
390
- click.style("Error: ", fg="red")
391
- + f'"{version}" not a valid semantic version.'
392
- )
393
- sys.exit(1)
429
+ version, increment = check_auto_increment(version)
394
430
 
395
- if not kacl_changelog.has_changes():
431
+ if not allow_no_changes and not kacl_changelog.has_changes():
396
432
  click.echo(
397
433
  click.style("Error: ", fg="red")
398
434
  + "The current changelog has no changes. You can only release if changes are available."
@@ -407,7 +443,11 @@ def release(
407
443
  auto_link = True
408
444
 
409
445
  kacl_changelog.release(
410
- version=version, link=link, auto_link=auto_link, increment=increment
446
+ version=version,
447
+ link=link,
448
+ auto_link=auto_link,
449
+ increment=increment,
450
+ allow_no_changes=allow_no_changes,
411
451
  )
412
452
 
413
453
  # get the new version
@@ -511,13 +551,7 @@ def squash(
511
551
  """Squshes all changes from a given version into a single section. Use '--modify' to directly modify the changelog file."""
512
552
 
513
553
  kacl_changelog = load_changelog(ctx)
514
-
515
- if not kacl_changelog.is_valid():
516
- click.echo(
517
- click.style("Error: ", fg="red")
518
- + "Changelog is not valid. Run 'kacl-cli verify' for more information."
519
- )
520
- sys.exit(1)
554
+ raise_on_invalid(kacl_changelog)
521
555
 
522
556
  if not to_version:
523
557
  to_version = kacl_changelog.current_version()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-kacl
3
- Version: 0.4.7
3
+ Version: 0.5.0
4
4
  Summary: Python module and CLI tool for validating and modifying Changelogs in "keep-a-changelog" format"
5
5
  Home-page: https://gitlab.com/schmieder.matthias/python-kacl.git
6
6
  Author: Matthias Schmieder
@@ -441,13 +441,12 @@ in order to generate the correct urls, `python-kacl` allows you to define three
441
441
 
442
442
  ```yaml
443
443
  kacl:
444
- git:
445
- links:
446
- # The host url is optional and will be automatically determined using your the git repository. If run on gitlab CI the host will be determined by CI_PROJECT_URL if not specified here.
447
- host_url: https://github.com/mschmieder/kacl-cli
448
- compare_versions_template: '{host}/compare/v{previous_version}...v{version}'
449
- unreleased_changes_template: '{host}/tree/v{latest_version}...HEAD'
450
- initial_version_template: '{host}/tree/v{version}'
444
+ links:
445
+ # The host url is optional and will be automatically determined using your git repository. If run on gitlab CI the host will be determined by CI_PROJECT_URL if not specified here.
446
+ host_url: https://github.com/mschmieder/kacl-cli
447
+ compare_versions_template: '{host}/compare/v{previous_version}...v{version}'
448
+ unreleased_changes_template: '{host}/compare/v{latest_version}...HEAD'
449
+ initial_version_template: '{host}/tree/v{version}'
451
450
  ```
452
451
 
453
452
  Using the python format syntax you can generate any links you want. The available replacement variables are `version`, `previous_version`, `host` and `latest_version`.
@@ -554,7 +553,7 @@ kacl:
554
553
  tag_name: "v{new_version}"
555
554
  tag_description: "Version v{new_version} released"
556
555
  links:
557
- # The host url is optional and will be automatically determined using your the git repository
556
+ # The host url is optional and will be automatically determined using your git repository
558
557
  # host_url: https://github.com/mschmieder/kacl-cli
559
558
  compare_versions_template: '{host}/compare/{previous_version}...{version}'
560
559
  unreleased_changes_template: '{host}/compare/{latest_version}...master'
@@ -581,7 +580,7 @@ source ./venv/bin/activate
581
580
  pip install -e .
582
581
 
583
582
  # install development requirements
584
- pip install -r dev-requirements
583
+ pip install -r dev-requirements.txt
585
584
 
586
585
  # run the tests
587
586
  python3 -m pytest --snapshot-update --allow-snapshot-deletion
@@ -11,7 +11,7 @@ this_directory = path.abspath(path.dirname(__file__))
11
11
  with open(path.join(this_directory, "README.md"), encoding="utf-8") as f:
12
12
  long_description = f.read()
13
13
 
14
- version = "0.4.7"
14
+ version = "0.5.0"
15
15
 
16
16
  version = f"{version}{os.environ.get('PIP_VERSION_POSTFIX', '')}"
17
17
 
@@ -38,6 +38,40 @@ def test_verify_with_json_output():
38
38
  assert validation_result["valid"] is False
39
39
 
40
40
 
41
+ def test_current(tmp_path, snapshot):
42
+ runner = CliRunner()
43
+ resources_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data/")
44
+ changelog_file = os.path.join(resources_dir, "CHANGELOG_with_changes.md")
45
+
46
+ with runner.isolated_filesystem(temp_dir=tmp_path):
47
+ result = runner.invoke(
48
+ cli,
49
+ [
50
+ "-f",
51
+ changelog_file,
52
+ "current",
53
+ ],
54
+ catch_exceptions=False,
55
+ )
56
+ assert result.exit_code == 0, result.output
57
+ assert result.output == "1.0.0\n"
58
+
59
+
60
+ def test_next(tmp_path, snapshot):
61
+ runner = CliRunner()
62
+ resources_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data/")
63
+ changelog_file = os.path.join(resources_dir, "CHANGELOG_with_changes.md")
64
+
65
+ with runner.isolated_filesystem(temp_dir=tmp_path):
66
+ result = runner.invoke(
67
+ cli,
68
+ ["-f", changelog_file, "next", "patch"],
69
+ catch_exceptions=False,
70
+ )
71
+ assert result.exit_code == 0, result.output
72
+ assert result.output == "1.0.1\n"
73
+
74
+
41
75
  @freeze_time("2023-01-01")
42
76
  def test_release_patch(tmp_path, snapshot):
43
77
  runner = CliRunner()
@@ -216,6 +216,17 @@ class TestKacl(TestCase):
216
216
  "https://gitlab.com/schmieder.matthias/python-kacl.git/-/compare/v1.0.0...HEAD",
217
217
  )
218
218
 
219
+ def test_release_with_allow_no_changes_flag(self):
220
+ changelog_file = os.path.join(
221
+ os.path.dirname(os.path.realpath(__file__)),
222
+ "data/CHANGELOG_without_changes.md",
223
+ )
224
+ changelog = kacl.load(changelog_file)
225
+
226
+ self.assertFalse(changelog.has_changes())
227
+ changelog.release("1.0.1", allow_no_changes=True)
228
+ self.assertEqual("1.0.1", changelog.current_version())
229
+
219
230
  def test_release_with_increment(self):
220
231
  tests = {
221
232
  "major": "2.0.0",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes