PyVCC 1.2.1__py3-none-any.whl

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.
pyvcc/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ """PyVCC - Python Version Controller for SemVer manangment with conventional commits"""
2
+
3
+ from .cli import main as main
4
+ from .semver import SemVer as SemVer
pyvcc/__main__.py ADDED
@@ -0,0 +1,27 @@
1
+ """
2
+ Entry point for running the package as a module.
3
+ """
4
+
5
+ import os
6
+ import sys
7
+ import argparse
8
+ import structlog
9
+ from pyvc.cli import main, validate_args
10
+
11
+
12
+ log = structlog.get_logger()
13
+
14
+ if __name__ == "__main__":
15
+ parser = argparse.ArgumentParser(prog="PyVC", description=__doc__)
16
+ parser.add_argument("--root", type=str, default=".", required=False)
17
+ parser.add_argument("--initial-version", type=str, required=False, default="0.1.0")
18
+ parser.add_argument("--initial-commit", type=str, required=False, default="")
19
+
20
+ args = parser.parse_args()
21
+ root = os.getenv(key="PYVC_REPO_ROOT", default=args.root)
22
+ version = os.getenv(key="PYVC_INITIAL_VERSION", default=args.initial_version)
23
+ commit = os.getenv(key="PYVC_INITIAL_COMMIT", default=args.initial_commit)
24
+ if not validate_args(root=root, version=version):
25
+ sys.exit(1)
26
+
27
+ main(root, version, commit)
pyvcc/cli.py ADDED
@@ -0,0 +1,55 @@
1
+ """
2
+ CLI parsing for pyvc command.
3
+ """
4
+
5
+ from pygit2 import Commit
6
+ import structlog
7
+ from pathlib import Path, PurePath
8
+ from pygit2.repository import Repository
9
+ from pygit2.enums import SortMode
10
+
11
+ from pyvcc.semver import SemVer
12
+
13
+
14
+ log = structlog.get_logger()
15
+
16
+
17
+ def validate_args(root: str, version: str) -> bool:
18
+ is_valid = True
19
+ repo_path = Path(root) / PurePath(".git")
20
+ if not repo_path.exists():
21
+ is_valid = False
22
+ log.error("repo root does not exist", path=repo_path)
23
+
24
+ try:
25
+ SemVer.semver_from_string(version)
26
+ except Exception as e:
27
+ log.error("invalid initial version", error=str(e))
28
+ is_valid = False
29
+
30
+ return is_valid
31
+
32
+
33
+ def main(root: str, version: str, start_commit_id: str | None = None) -> str:
34
+ repo_path = Path(root) / PurePath(".git")
35
+ semver = SemVer.semver_from_string(version)
36
+
37
+ repo = Repository(str(repo_path))
38
+
39
+ log.debug("starting repo walk", start_commit_id=start_commit_id)
40
+ commit_walker = repo.walk(repo.head.target, SortMode.TOPOLOGICAL | SortMode.REVERSE)
41
+
42
+ # if start_commit is defined for versioning, skip parents on walk
43
+ if start_commit_id:
44
+ start_commit = repo[start_commit_id]
45
+ if isinstance(start_commit, Commit):
46
+ for parent in start_commit.parent_ids:
47
+ commit_walker.hide(parent)
48
+
49
+ for commit in commit_walker:
50
+ message = commit.message
51
+ log.info("commit", id=commit.id, short=commit.short_id)
52
+ semver.bump_version(message)
53
+
54
+ log.info(f"final version {str(semver)}")
55
+ return str(semver)
pyvcc/semver.py ADDED
@@ -0,0 +1,136 @@
1
+ from enum import Enum, auto
2
+ import sys
3
+ import structlog
4
+
5
+ # Python 3.11+ has Self in typing module
6
+ if sys.version_info >= (3, 11):
7
+ from typing import Self
8
+ else:
9
+ from typing_extensions import Self
10
+
11
+
12
+ log = structlog.get_logger()
13
+
14
+
15
+ class CommitEnum(Enum):
16
+ FEAT = auto()
17
+ FIX = auto()
18
+ BUILD = auto()
19
+ CHORE = auto()
20
+ CI = auto()
21
+ DOCS = auto()
22
+ STYLE = auto()
23
+ REFACTOR = auto()
24
+ PERF = auto()
25
+ TEST = auto()
26
+
27
+
28
+ class BumpEnum(Enum):
29
+ MAJOR = auto()
30
+ MINOR = auto()
31
+ PATCH = auto()
32
+ NO_BUMP = auto()
33
+
34
+
35
+ class SemVer:
36
+ def __init__(self, major: int, minor: int, patch: int):
37
+ self.major = major
38
+ self.minor = minor
39
+ self.patch = patch
40
+
41
+ self.log = log
42
+
43
+ def __repr__(self):
44
+ return f"{self.major}.{self.minor}.{self.patch}"
45
+
46
+ @staticmethod
47
+ def is_breaking_change(type: str, message: str) -> bool:
48
+ """
49
+ SemVer defines that a breaking change is a commit with a type ending in '!'
50
+ OR that contains 'BREAKING CHANGE:' in the messsage body
51
+
52
+ # Parameters:
53
+ type (str): Commit message type (feat, fix, chore, etc)
54
+ message (str): commit message content
55
+ """
56
+ return type[-1] == "!" or "BREAKING CHANGE:" in message
57
+
58
+ @classmethod
59
+ def semver_from_string(cls, str_version: str) -> Self:
60
+ # TODO: regex?
61
+ list_version = str_version.split(".")
62
+ if len(list_version) != 3:
63
+ # TODO: custom exception
64
+ raise Exception("invalid string formating for semantic versioning")
65
+
66
+ major = int(list_version[0])
67
+ minor = int(list_version[1])
68
+ patch = int(list_version[2])
69
+ return cls(major, minor, patch)
70
+
71
+ @classmethod
72
+ def bump_type(cls, message: str) -> BumpEnum:
73
+ """
74
+ Given a version number MAJOR.MINOR.PATCH, increment the:
75
+
76
+ - MAJOR: version when you make incompatible API changes
77
+ - MINOR: version when you add functionality in a backward compatible manner
78
+ - PATCH: version when you make backward compatible bug fixes
79
+ Additional labels for pre-release and build metadata are available as
80
+ extensions to the MAJOR.MINOR.PATCH format.
81
+
82
+ fix: a commit of the type fix patches a bug in your codebase
83
+ (this correlates with PATCH in Semantic Versioning).
84
+
85
+ feat: a commit of the type feat introduces a new feature to the codebase
86
+ (this correlates with MINOR in Semantic Versioning).
87
+
88
+ BREAKING CHANGE: a commit that has a footer BREAKING CHANGE:, or appends a !
89
+ after the type/scope, introduces a breaking API change
90
+ (correlating with MAJOR in Semantic Versioning).
91
+ A BREAKING CHANGE can be part of commits of any type.
92
+
93
+ # Parameters:
94
+ message (str): commit message content
95
+ """
96
+
97
+ bump = BumpEnum.NO_BUMP
98
+ head = message.split("\n")[0]
99
+
100
+ # TODO: regex?
101
+ parsed_head = head.split(":")
102
+
103
+ if len(parsed_head) > 1:
104
+ commit_type = parsed_head[0].strip().upper()
105
+
106
+ if cls.is_breaking_change(commit_type, message):
107
+ bump = BumpEnum.MAJOR
108
+ elif commit_type == CommitEnum.FEAT.name:
109
+ bump = BumpEnum.MINOR
110
+ elif commit_type == CommitEnum.FIX.name:
111
+ bump = BumpEnum.PATCH
112
+ else:
113
+ bump = BumpEnum.NO_BUMP
114
+ else:
115
+ log.info("not in conventional commit spec", message=head)
116
+
117
+ return bump
118
+
119
+ def bump_version(self, message: str) -> None:
120
+ self.log = self.log.bind(message=message)
121
+
122
+ match self.bump_type(message):
123
+ case BumpEnum.MAJOR:
124
+ self.major += 1
125
+ self.minor = 0
126
+ self.patch = 0
127
+ self.log.debug("bump Major")
128
+ case BumpEnum.MINOR:
129
+ self.minor += 1
130
+ self.patch = 0
131
+ self.log.debug("bump Minor")
132
+ case BumpEnum.PATCH:
133
+ self.patch += 1
134
+ self.log.debug("bump Patch")
135
+ case BumpEnum.NO_BUMP:
136
+ self.log.debug("no bump")
@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.1
2
+ Name: PyVCC
3
+ Version: 1.2.1
4
+ Summary: PyVCC python version controller using conventional commits
5
+ Requires-Python: >=3.10
6
+ Requires-Dist: pygit2>=1.18.0
7
+ Requires-Dist: structlog>=25.3.0
8
+ Requires-Dist: typing-extensions>=4.0.0; python_version < "3.11"
9
+ Description-Content-Type: text/markdown
10
+
11
+ # python-version-controller
12
+ conventional version controller for python
13
+
14
+ [![codecov](https://codecov.io/gh/lcavalcante/python-version-controller/graph/badge.svg?token=H65NZV7N3Z)](https://codecov.io/gh/lcavalcante/python-version-controller)
15
+ [![tests](https://github.com/lcavalcante/python-version-controller/actions/workflows/code-quality.yml/badge.svg)](https://github.com/lcavalcante/python-version-controller/actions/workflows/code-quality.yml)
@@ -0,0 +1,9 @@
1
+ pyvcc-1.2.1.dist-info/METADATA,sha256=jjA4LTHTyQpS5LkAr2lz7hyj3yCrTNqYymRn5xmCRSU,757
2
+ pyvcc-1.2.1.dist-info/WHEEL,sha256=tSfRZzRHthuv7vxpI4aehrdN9scLjk-dCJkPLzkHxGg,90
3
+ pyvcc-1.2.1.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
+ pyvcc-1.2.1.dist-info/licenses/LICENSE,sha256=awOCsWJ58m_2kBQwBUGWejVqZm6wuRtCL2hi9rfa0X4,1211
5
+ pyvcc/__init__.py,sha256=RmBuVRJe0JPS5H6lt3ijpeDPJ8PA7FP757xlIEd5Gy4,156
6
+ pyvcc/__main__.py,sha256=QuN-SbZooLYU_z65E5GlLVRQRcQ6NZosX-FqTpH-vJ0,888
7
+ pyvcc/cli.py,sha256=hvrNbRW2dF1tTuanTw81fCWz_LtZXxn_Jv6y3uokMEY,1567
8
+ pyvcc/semver.py,sha256=4SVd4kcaP9-57f_QrJwLYEZq5mY0HWz0SykghbusHao,4196
9
+ pyvcc-1.2.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: pdm-backend (2.4.4)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+
3
+ [gui_scripts]
4
+
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org>