Skip to content

Commit

Permalink
Merge pull request #34 from Colin-b/develop
Browse files Browse the repository at this point in the history
Release 2.0.0.dev2
  • Loading branch information
Colin-b committed Aug 4, 2021
2 parents 8252311 + 128a920 commit 7c94109
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
repos:
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 21.7b0
hooks:
- id: black
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.0.0.dev2] - 2021-08-04
### Fixed
- `keepachangelog.release` will now properly bump version in case the number of digit to compare was previously increased (such as if version 9 and 10 existed).

### Added
- `keepachangelog.to_sorted_semantic` to be able to sort semantic versions.

## [2.0.0.dev1] - 2021-05-27
### Changed
- `keepachangelog.release` will now return `None` instead of throwing an exception if there is no Unreleased content.
Expand Down Expand Up @@ -77,7 +84,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial release.

[Unreleased]: https://github.com/Colin-b/keepachangelog/compare/v2.0.0.dev1...HEAD
[Unreleased]: https://github.com/Colin-b/keepachangelog/compare/v2.0.0.dev2...HEAD
[2.0.0.dev2]: https://github.com/Colin-b/keepachangelog/compare/v2.0.0.dev1...v2.0.0.dev2
[2.0.0.dev1]: https://github.com/Colin-b/keepachangelog/compare/v2.0.0.dev0...v2.0.0.dev1
[2.0.0.dev0]: https://github.com/Colin-b/keepachangelog/compare/v1.0.0...v2.0.0.dev0
[1.0.0]: https://github.com/Colin-b/keepachangelog/compare/v0.5.0...v1.0.0
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Colin Bounouar
Copyright (c) 2021 Colin Bounouar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<a href="https://travis-ci.com/Colin-b/keepachangelog"><img alt="Build status" src="https://api.travis-ci.com/Colin-b/keepachangelog.svg?branch=master"></a>
<a href="https://travis-ci.com/Colin-b/keepachangelog"><img alt="Coverage" src="https://img.shields.io/badge/coverage-100%25-brightgreen"></a>
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
<a href="https://travis-ci.com/Colin-b/keepachangelog"><img alt="Number of tests" src="https://img.shields.io/badge/tests-34 passed-blue"></a>
<a href="https://travis-ci.com/Colin-b/keepachangelog"><img alt="Number of tests" src="https://img.shields.io/badge/tests-40 passed-blue"></a>
<a href="https://pypi.org/project/keepachangelog/"><img alt="Number of downloads" src="https://img.shields.io/pypi/dm/keepachangelog"></a>
</p>

Expand Down
1 change: 1 addition & 0 deletions keepachangelog/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from keepachangelog.version import __version__
from keepachangelog._changelog import to_dict, to_raw_dict, release, from_dict
from keepachangelog._versioning import to_sorted_semantic
73 changes: 62 additions & 11 deletions keepachangelog/_versioning.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from typing import Tuple, Optional

from functools import cmp_to_key
from typing import Tuple, Optional, Iterable, List

initial_semantic_version = {
"major": 0,
Expand Down Expand Up @@ -60,25 +60,76 @@ def bump(unreleased: dict, semantic_version: dict) -> dict:
return semantic_version


def semantic_order(version: Tuple[str, dict]) -> str:
_, semantic_version = version
def _compare(first_version: str, second_version: str) -> int:
if first_version > second_version:
return 1

if first_version < second_version:
return -1

return 0


def semantic_order(
first_version: Tuple[str, dict], second_version: Tuple[str, dict]
) -> int:
_, semantic_first_version = first_version
_, semantic_second_version = second_version

major_difference = _compare(
semantic_first_version["major"], semantic_second_version["major"]
)
if major_difference:
return major_difference

minor_difference = _compare(
semantic_first_version["minor"], semantic_second_version["minor"]
)
if minor_difference:
return minor_difference

patch_difference = _compare(
semantic_first_version["patch"], semantic_second_version["patch"]
)
if patch_difference:
return patch_difference

# Ensure release is "bigger than" pre-release
pre_release_order = (
f"0{semantic_version['prerelease']}" if semantic_version["prerelease"] else "1"
pre_release_difference = _compare(
f"0{semantic_first_version['prerelease']}"
if semantic_first_version["prerelease"]
else "1",
f"0{semantic_second_version['prerelease']}"
if semantic_second_version["prerelease"]
else "1",
)
return f"{semantic_version['major']}.{semantic_version['minor']}.{semantic_version['patch']}.{pre_release_order}"

return pre_release_difference


def actual_version(changelog: dict) -> Tuple[Optional[str], dict]:
versions = sorted(
versions = to_sorted_semantic(changelog.keys())
return versions.pop() if versions else (None, initial_semantic_version.copy())


def to_sorted_semantic(versions: Iterable[str]) -> List[Tuple[str, dict]]:
"""
Convert a list of string semantic versions to a sorted list of semantic versions.
Note: unreleased is not considered as a semantic version and will thus be removed from the resulting versions.
:param versions: un-ordered list of semantic versions (as string). Can contains unreleased.
:return: An ordered (first element is the oldest version, last element is the newest (highest)) list of versions.
Each version is represented as a 2-tuple: first one is the string version, second one is a dictionary containing:
'major', 'minor', 'patch', 'prerelease', 'buildmetadata' keys.
"""
return sorted(
[
(version, to_semantic(version))
for version in changelog.keys()
for version in versions
if version != "unreleased"
],
key=semantic_order,
key=cmp_to_key(semantic_order),
)
return versions.pop() if versions else (None, initial_semantic_version.copy())


def guess_unreleased_version(
Expand Down
2 changes: 1 addition & 1 deletion keepachangelog/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Major should be incremented in case there is a breaking change. (eg: 2.5.8 -> 3.0.0)
# Minor should be incremented in case there is an enhancement. (eg: 2.5.8 -> 2.6.0)
# Patch should be incremented in case there is a bug fix. (eg: 2.5.8 -> 2.5.9)
__version__ = "2.0.0.dev1"
__version__ = "2.0.0.dev2"
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
"testing": [
# Used to check starlette endpoint
"requests==2.*",
"starlette==0.13.*",
"starlette==0.16.*",
# Used to check flask-restx endpoint
"flask-restx==0.4.*",
"flask-restx==0.5.*",
# Used to check coverage
"pytest-cov==2.*",
]
Expand Down
Loading

0 comments on commit 7c94109

Please sign in to comment.