Compare commits
1 Commits
2.0.0.post
...
2.0.0.post
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d68edd4ab |
@@ -8,7 +8,7 @@
|
||||
|
||||

|
||||
|
||||
# pyChangeLogFactory
|
||||
# pyChangelogFactory
|
||||
|
||||
A simple changelog formater that consume raw changes list text and produce nice pre-formated changelogs.
|
||||
The input data mainly aim to be a merged commit report.
|
||||
|
||||
@@ -42,7 +42,7 @@ From master git repository:
|
||||
|
||||
### Sample code
|
||||
``` py
|
||||
from pychangelogfactory import ChangeLogFactory
|
||||
from pychangelogfactory import ChangelogFactory
|
||||
|
||||
raw_changelog = (
|
||||
"feat: add a nice feature to the project\n"
|
||||
@@ -52,7 +52,7 @@ raw_changelog = (
|
||||
"improve core performances by reducing complexity\n"
|
||||
"some random changes in the text content\n"
|
||||
)
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr = ChangelogFactory()
|
||||
hdlr.ProcessFullChangelog(self.raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog()
|
||||
print(changelog)
|
||||
@@ -61,13 +61,13 @@ print(changelog)
|
||||
#### Or shorted version:
|
||||
|
||||
``` py
|
||||
hdlr = ChangeLogFactory(self.raw_changelog)
|
||||
hdlr = ChangelogFactory(self.raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog()
|
||||
```
|
||||
#### Or one-liner version:
|
||||
|
||||
``` py
|
||||
changelog = ChangeLogFactory(self.raw_changelog).RenderFullChangelog()
|
||||
changelog = ChangelogFactory(self.raw_changelog).RenderFullChangelog()
|
||||
```
|
||||
|
||||
### Output(Raw)
|
||||
@@ -97,7 +97,7 @@ changelog = ChangeLogFactory(self.raw_changelog).RenderFullChangelog()
|
||||
### Options
|
||||
#### Display unknown messages types
|
||||
``` py
|
||||
from pychangelogfactory import ChangeLogFormater
|
||||
from pychangelogfactory import ChangelogFormater
|
||||
|
||||
raw_changelog = (
|
||||
"feat: add a nice feature to the project\n"
|
||||
@@ -107,7 +107,7 @@ raw_changelog = (
|
||||
"improve core performances by reducing complexity\n"
|
||||
"some random changes in the text content\n"
|
||||
)
|
||||
changelog = ChangeLogFactory(self.raw_changelog).RenderFullChangelog(include_unknown=True)
|
||||
changelog = ChangelogFactory(self.raw_changelog).RenderFullChangelog(include_unknown=True)
|
||||
print(changelog)
|
||||
```
|
||||
### Output (rendered)
|
||||
@@ -145,14 +145,14 @@ print(changelog)
|
||||
|
||||
## Add new types
|
||||
|
||||
New formaters can be easily added by subclassing `ChangeLogFormater`:
|
||||
New formaters can be easily added by subclassing `ChangelogFormater`:
|
||||
|
||||
### Inject custom formater locally (prefered way)
|
||||
|
||||
``` py
|
||||
from pychangelogfactory import ChangeLogFormater,ChangeLogFactory
|
||||
from pychangelogfactory import ChangelogFormater,ChangelogFactory
|
||||
|
||||
class ChangeLogFormater_others(ChangeLogFormater):
|
||||
class ChangelogFormater_others(ChangelogFormater):
|
||||
"""My formater"""
|
||||
|
||||
prefix: str = "mytag"
|
||||
@@ -160,18 +160,18 @@ class ChangeLogFormater_others(ChangeLogFormater):
|
||||
keywords: list[str] = ["foo","42"]
|
||||
priority: int = 10
|
||||
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr.RegisterFormater(ChangeLogFormater_others)
|
||||
hdlr = ChangelogFactory()
|
||||
hdlr.RegisterFormater(ChangelogFormater_others)
|
||||
...
|
||||
```
|
||||
|
||||
### Inject custom formater module-wide
|
||||
|
||||
``` py
|
||||
from pychangelogfactory import ChangeLogFormater,ChangelogFormaterRecordType
|
||||
from pychangelogfactory import ChangelogFormater,ChangelogFormaterRecordType
|
||||
|
||||
@ChangelogFormaterRecordType
|
||||
class ChangeLogFormater_others(ChangeLogFormater):
|
||||
class ChangelogFormater_others(ChangelogFormater):
|
||||
"""My formater"""
|
||||
|
||||
prefix: str = "mytag"
|
||||
@@ -179,7 +179,7 @@ class ChangeLogFormater_others(ChangeLogFormater):
|
||||
keywords: list[str] = ["foo","42"]
|
||||
priority: int = 10
|
||||
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr = ChangelogFactory()
|
||||
...
|
||||
```
|
||||
|
||||
@@ -193,7 +193,7 @@ raw_changelog = ("mytag: add a nice feature to the project\n"
|
||||
"foo modification in my file\n"
|
||||
"need 42 coffee\n"
|
||||
)
|
||||
hdlr = ChangeLogFactory(raw_changelog)
|
||||
hdlr = ChangelogFactory(raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=True)
|
||||
print(changelog)
|
||||
```
|
||||
@@ -207,22 +207,22 @@ print(changelog)
|
||||
> need 42 coffee
|
||||
|
||||
|
||||
### revert changes
|
||||
### Revert changes
|
||||
#### Reset to original list class-wise (all modules):
|
||||
``` py
|
||||
ChangeLogFactory.ResetFormaterList()
|
||||
ChangelogFactory.ResetFormaterList()
|
||||
...
|
||||
```
|
||||
#### Reset to original list instance-wise:
|
||||
``` py
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr = ChangelogFactory()
|
||||
hdlr.ResetFormaterList()
|
||||
...
|
||||
```
|
||||
#### Removing a specific formater:
|
||||
``` py
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr.unRegisterFormater(ChangeLogFormater_others)
|
||||
hdlr = ChangelogFactory()
|
||||
hdlr.unRegisterFormater(ChangelogFormater_others)
|
||||
...
|
||||
```
|
||||
/// warning
|
||||
|
||||
@@ -20,4 +20,4 @@ except PackageNotFoundError: # pragma: no cover
|
||||
warnings.warn("can not read __version__, assuming local test context, setting it to ?.?.?")
|
||||
__version__ = "?.?.?"
|
||||
|
||||
from .changelogfactory import ChangeLogFactory, ChangelogFormaterRecordType, ChangeLogFormater
|
||||
from .changelogfactory import ChangelogFactory, ChangelogFormaterRecordType, ChangelogFormater
|
||||
|
||||
@@ -27,7 +27,7 @@ def ChangelogFormaterRecordType(Klass: type) -> type:
|
||||
Klass: class to register in the factory
|
||||
Returns:
|
||||
untouched class"""
|
||||
ChangeLogFactory.ar_FormaterKlass.add(Klass)
|
||||
ChangelogFactory.ar_FormaterKlass.add(Klass)
|
||||
return Klass
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ def _ChangelogFormaterRecordType(Klass: type) -> type:
|
||||
return ChangelogFormaterRecordType(Klass)
|
||||
|
||||
|
||||
class ChangeLogFormater(ABC):
|
||||
"""ChangeLogFormater class
|
||||
class ChangelogFormater(ABC):
|
||||
"""ChangelogFormater class
|
||||
|
||||
This class is the base formater class.
|
||||
|
||||
@@ -66,7 +66,7 @@ class ChangeLogFormater(ABC):
|
||||
_lines: list[str] = []
|
||||
|
||||
def __init__(self):
|
||||
"""ChangeLogFormater class constructor"""
|
||||
"""ChangelogFormater class constructor"""
|
||||
self._lines = []
|
||||
|
||||
def Clear(self) -> None:
|
||||
@@ -138,15 +138,15 @@ class ChangeLogFormater(ABC):
|
||||
return False
|
||||
|
||||
|
||||
class ChangeLogFactory:
|
||||
class ChangelogFactory:
|
||||
"""The main changelog class"""
|
||||
|
||||
ar_FormaterKlass: set[type[ChangeLogFormater]] = set()
|
||||
ar_Formater: None | dict[ChangeLogFormater] = None
|
||||
ar_FormaterKlass: set[type[ChangelogFormater]] = set()
|
||||
ar_Formater: None | dict[ChangelogFormater] = None
|
||||
checkCommentPattern: str = r"^[ \t]*(?:\/\/|#)"
|
||||
|
||||
def __init__(self, ChangelogString: None | str = None):
|
||||
"""Main ChangeLogFormater class constructor
|
||||
"""Main ChangelogFormater class constructor
|
||||
|
||||
Args:
|
||||
ChangelogString: optionnal input string to start with
|
||||
@@ -160,7 +160,7 @@ class ChangeLogFactory:
|
||||
if isinstance(ChangelogString, str):
|
||||
self.ProcessFullChangelog(ChangelogString)
|
||||
|
||||
def ResetFormaterList(self=None) -> None | ChangeLogFactory:
|
||||
def ResetFormaterList(self=None) -> None | ChangelogFactory:
|
||||
"""Reset the formater class list to original
|
||||
|
||||
This method can be call both from class or from instance.
|
||||
@@ -177,10 +177,10 @@ class ChangeLogFactory:
|
||||
self.ar_Formater = {}
|
||||
for FormaterKlass in self.ar_FormaterKlass:
|
||||
self.ar_Formater[FormaterKlass.__name__] = FormaterKlass()
|
||||
ChangeLogFactory.ar_FormaterKlass = _savedFormaterList.copy()
|
||||
ChangelogFactory.ar_FormaterKlass = _savedFormaterList.copy()
|
||||
return None
|
||||
|
||||
def RegisterFormater(self, FormaterKlass: ChangeLogFormater) -> None:
|
||||
def RegisterFormater(self, FormaterKlass: ChangelogFormater) -> None:
|
||||
"""Register a new formater in the current instance
|
||||
|
||||
Args:
|
||||
@@ -192,7 +192,7 @@ class ChangeLogFactory:
|
||||
self.ar_Formater[FormaterKlass.__name__] = FormaterKlass()
|
||||
return self
|
||||
|
||||
def unRegisterFormater(self, FormaterKlass: ChangeLogFormater) -> None:
|
||||
def unRegisterFormater(self, FormaterKlass: ChangelogFormater) -> None:
|
||||
"""unRegister a new formater in the current instance
|
||||
|
||||
Args:
|
||||
@@ -204,7 +204,7 @@ class ChangeLogFactory:
|
||||
del self.ar_Formater[FormaterKlass.__name__]
|
||||
return self
|
||||
|
||||
def Clear(self) -> ChangeLogFactory:
|
||||
def Clear(self) -> ChangelogFactory:
|
||||
"""Clear internal memory
|
||||
Returns:
|
||||
self for convenience
|
||||
@@ -248,10 +248,10 @@ class ChangeLogFactory:
|
||||
formater.PushLine(RawChangelogLine)
|
||||
return True
|
||||
|
||||
self.ar_Formater[ChangeLogFormater_others.__name__].PushLine(RawChangelogLine)
|
||||
self.ar_Formater[ChangelogFormater_others.__name__].PushLine(RawChangelogLine)
|
||||
return False
|
||||
|
||||
def ProcessFullChangelog(self, RawChangelogMessage: str) -> ChangeLogFactory:
|
||||
def ProcessFullChangelog(self, RawChangelogMessage: str) -> ChangelogFactory:
|
||||
"""Process all input lines
|
||||
|
||||
This function handles the main 2-round changes search algo.
|
||||
@@ -292,7 +292,7 @@ class ChangeLogFactory:
|
||||
"""
|
||||
full_changelog = ""
|
||||
for formater in sorted(self.ar_Formater.values(), key=lambda x: x.priority, reverse=True):
|
||||
if (include_unknown is False) and (isinstance(formater, ChangeLogFormater_others)):
|
||||
if (include_unknown is False) and (isinstance(formater, ChangelogFormater_others)):
|
||||
continue
|
||||
full_changelog = full_changelog + formater.Render()
|
||||
|
||||
@@ -351,10 +351,10 @@ for RecordType, Config in {
|
||||
# fmt: on
|
||||
}.items():
|
||||
# then we instantiate all of them
|
||||
_name = f"ChangeLogFormater_{RecordType}"
|
||||
_name = f"ChangelogFormater_{RecordType}"
|
||||
_tmp = globals()[_name] = type(
|
||||
_name,
|
||||
(ChangeLogFormater,),
|
||||
(ChangelogFormater,),
|
||||
{
|
||||
"prefix": RecordType,
|
||||
"title": Config[2],
|
||||
@@ -362,12 +362,12 @@ for RecordType, Config in {
|
||||
"priority": Config[0],
|
||||
},
|
||||
)
|
||||
ChangeLogFactory.ar_FormaterKlass.add(_tmp)
|
||||
ChangelogFactory.ar_FormaterKlass.add(_tmp)
|
||||
_savedFormaterList.add(_tmp)
|
||||
|
||||
|
||||
@_ChangelogFormaterRecordType
|
||||
class ChangeLogFormater_revert(ChangeLogFormater):
|
||||
class ChangelogFormater_revert(ChangelogFormater):
|
||||
"""Revert scope formater"""
|
||||
|
||||
prefix: str = "revert"
|
||||
@@ -387,7 +387,7 @@ class ChangeLogFormater_revert(ChangeLogFormater):
|
||||
|
||||
|
||||
@_ChangelogFormaterRecordType
|
||||
class ChangeLogFormater_others(ChangeLogFormater):
|
||||
class ChangelogFormater_others(ChangelogFormater):
|
||||
"""Others / unknown scope formater"""
|
||||
|
||||
prefix: str = "other"
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from src.pychangelogfactory import ChangeLogFormater, ChangeLogFactory, ChangelogFormaterRecordType
|
||||
from src.pychangelogfactory import ChangelogFormater, ChangelogFactory, ChangelogFormaterRecordType
|
||||
|
||||
|
||||
class Testtest_module(unittest.TestCase):
|
||||
def setUp(self):
|
||||
ChangeLogFactory.ResetFormaterList()
|
||||
ChangelogFactory.ResetFormaterList()
|
||||
|
||||
def simplegeneration(self, inputstr, teststrs: list[str], withunknown: bool = False):
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr = ChangelogFactory()
|
||||
hdlr.ProcessFullChangelog(inputstr)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=withunknown)
|
||||
for test in teststrs:
|
||||
@@ -25,7 +25,7 @@ class Testtest_module(unittest.TestCase):
|
||||
def test_simplegeneration_ignored2(self):
|
||||
raw = "break: testbreak break" + "\n" + "#doc: testdoc doc" + "\n" + "#style: teststyle beautify" + "\n" + "//test: testtest check"
|
||||
|
||||
hdlr = ChangeLogFactory(raw)
|
||||
hdlr = ChangelogFactory(raw)
|
||||
changelog = hdlr.RenderFullChangelog()
|
||||
|
||||
self.assertIn("testbreak", changelog)
|
||||
@@ -36,7 +36,7 @@ class Testtest_module(unittest.TestCase):
|
||||
def test_simplegeneration_ignored(self):
|
||||
raw = "break: testbreak" + "\n" + "#doc: testdoc" + "\n" + "#style: teststyle" + "\n" + "//test: testtest"
|
||||
|
||||
hdlr = ChangeLogFactory(raw)
|
||||
hdlr = ChangelogFactory(raw)
|
||||
changelog = hdlr.RenderFullChangelog()
|
||||
self.assertIn("testbreak", changelog)
|
||||
self.assertNotIn("testdoc", changelog)
|
||||
@@ -45,7 +45,7 @@ class Testtest_module(unittest.TestCase):
|
||||
|
||||
def test_simplegeneration_order(self):
|
||||
raw = "break: testbreak" + "\n" + "doc: testdoc" + "\n" + "style: teststyle" + "\n" + "test: testtest"
|
||||
hdlr = ChangeLogFactory(raw)
|
||||
hdlr = ChangelogFactory(raw)
|
||||
changelog = hdlr.RenderFullChangelog().splitlines()
|
||||
self.assertIn("testbreak", changelog[1])
|
||||
self.assertIn("teststyle", changelog[3])
|
||||
@@ -156,22 +156,22 @@ class Testtest_module(unittest.TestCase):
|
||||
# fmt: on
|
||||
|
||||
def test_sample(self):
|
||||
hdlr = ChangeLogFactory(self.raw_changelog)
|
||||
hdlr = ChangelogFactory(self.raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=True)
|
||||
self.assertEqual(changelog, self.expected_formated)
|
||||
|
||||
def test_sample_aio(self):
|
||||
changelog = ChangeLogFactory(self.raw_changelog).RenderFullChangelog(include_unknown=True)
|
||||
changelog = ChangelogFactory(self.raw_changelog).RenderFullChangelog(include_unknown=True)
|
||||
self.assertEqual(changelog, self.expected_formated)
|
||||
|
||||
def test_sample_exploded(self):
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr = ChangelogFactory()
|
||||
hdlr.ProcessFullChangelog(self.raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=True)
|
||||
self.assertEqual(changelog, self.expected_formated)
|
||||
|
||||
def test_sample_clear(self):
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr = ChangelogFactory()
|
||||
hdlr.ProcessFullChangelog(self.raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=True)
|
||||
self.assertEqual(changelog, self.expected_formated)
|
||||
@@ -182,7 +182,7 @@ class Testtest_module(unittest.TestCase):
|
||||
|
||||
class Testtest_module_othercontext(unittest.TestCase):
|
||||
def setUp(self):
|
||||
ChangeLogFactory.ResetFormaterList()
|
||||
ChangelogFactory.ResetFormaterList()
|
||||
|
||||
def test_custom(self):
|
||||
"""
|
||||
@@ -190,7 +190,7 @@ class Testtest_module_othercontext(unittest.TestCase):
|
||||
"""
|
||||
|
||||
@ChangelogFormaterRecordType
|
||||
class ChangeLogFormater_TEST(ChangeLogFormater):
|
||||
class ChangelogFormater_TEST(ChangelogFormater):
|
||||
"""My formater"""
|
||||
|
||||
prefix: str = "mytag"
|
||||
@@ -211,7 +211,7 @@ class Testtest_module_othercontext(unittest.TestCase):
|
||||
)
|
||||
# fmt: on
|
||||
|
||||
hdlr = ChangeLogFactory(raw_changelog)
|
||||
hdlr = ChangelogFactory(raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=True)
|
||||
self.assertEqual(changelog, expected_formated_orig)
|
||||
|
||||
@@ -219,7 +219,7 @@ class Testtest_module_othercontext(unittest.TestCase):
|
||||
2nd PART: cheking the custom formater is still here after new object creation
|
||||
"""
|
||||
|
||||
hdlr = ChangeLogFactory(raw_changelog)
|
||||
hdlr = ChangelogFactory(raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=True)
|
||||
self.assertEqual(changelog, expected_formated_orig)
|
||||
|
||||
@@ -227,8 +227,8 @@ class Testtest_module_othercontext(unittest.TestCase):
|
||||
3rd PART: removing the custom formater at runtime
|
||||
"""
|
||||
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr.unRegisterFormater(ChangeLogFormater_TEST)
|
||||
hdlr = ChangelogFactory()
|
||||
hdlr.unRegisterFormater(ChangelogFormater_TEST)
|
||||
hdlr.ProcessFullChangelog(raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=True)
|
||||
|
||||
@@ -248,7 +248,7 @@ class Testtest_module_othercontext(unittest.TestCase):
|
||||
4th PART: checking it is back when create new obj
|
||||
"""
|
||||
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr = ChangelogFactory()
|
||||
hdlr.ProcessFullChangelog(raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=True)
|
||||
self.assertEqual(changelog, expected_formated_orig)
|
||||
@@ -257,7 +257,7 @@ class Testtest_module_othercontext(unittest.TestCase):
|
||||
3.1rd PART: removing the custom formater at runtime
|
||||
"""
|
||||
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr = ChangelogFactory()
|
||||
hdlr.ResetFormaterList()
|
||||
hdlr.ProcessFullChangelog(raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=True)
|
||||
@@ -267,7 +267,7 @@ class Testtest_module_othercontext(unittest.TestCase):
|
||||
4.1th PART: checking it is back when create new obj
|
||||
"""
|
||||
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr = ChangelogFactory()
|
||||
hdlr.ProcessFullChangelog(raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=True)
|
||||
self.assertEqual(changelog, expected_formated_orig)
|
||||
@@ -275,8 +275,8 @@ class Testtest_module_othercontext(unittest.TestCase):
|
||||
"""
|
||||
5th PART: reseting class list globally
|
||||
"""
|
||||
ChangeLogFactory.ResetFormaterList()
|
||||
hdlr = ChangeLogFactory()
|
||||
ChangelogFactory.ResetFormaterList()
|
||||
hdlr = ChangelogFactory()
|
||||
hdlr.ProcessFullChangelog(raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=True)
|
||||
self.assertEqual(changelog, expected_formated)
|
||||
@@ -284,7 +284,7 @@ class Testtest_module_othercontext(unittest.TestCase):
|
||||
"""
|
||||
6th PART: checking it is still not here
|
||||
"""
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr = ChangelogFactory()
|
||||
hdlr.ProcessFullChangelog(raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=True)
|
||||
self.assertEqual(changelog, expected_formated)
|
||||
@@ -292,10 +292,10 @@ class Testtest_module_othercontext(unittest.TestCase):
|
||||
|
||||
class Testtest_module_othercontext2(unittest.TestCase):
|
||||
def setUp(self):
|
||||
ChangeLogFactory.ResetFormaterList()
|
||||
ChangelogFactory.ResetFormaterList()
|
||||
|
||||
def test_custom2(self):
|
||||
class ChangeLogFormater_TEST2(ChangeLogFormater):
|
||||
class ChangelogFormater_TEST2(ChangelogFormater):
|
||||
"""My formater"""
|
||||
|
||||
prefix: str = "mytag"
|
||||
@@ -316,9 +316,9 @@ class Testtest_module_othercontext2(unittest.TestCase):
|
||||
)
|
||||
# fmt: on
|
||||
|
||||
hdlr = ChangeLogFactory()
|
||||
hdlr = ChangelogFactory()
|
||||
|
||||
hdlr.RegisterFormater(ChangeLogFormater_TEST2)
|
||||
hdlr.RegisterFormater(ChangelogFormater_TEST2)
|
||||
|
||||
hdlr.ProcessFullChangelog(raw_changelog)
|
||||
changelog = hdlr.RenderFullChangelog(include_unknown=True)
|
||||
|
||||
Reference in New Issue
Block a user