Compare commits

...

24 Commits

Author SHA1 Message Date
cclecle
9e5f0de5c4 add badges in readme
fix float value for quality
2023-03-23 23:23:24 +00:00
cclecle
99f38741fd add code quality badge 2023-03-23 23:13:55 +00:00
cclecle
eee2bf551c bvlabnaal 2023-03-23 23:02:57 +00:00
cclecle
01ce809823 add missing import 2023-03-23 22:57:14 +00:00
cclecle
4ab70409a0 switch to BigDecimal grrrrr 2023-03-23 22:49:08 +00:00
cclecle
7b9752a17a cast to decimalformat 2023-03-23 22:47:52 +00:00
cclecle
879a7ca03d fix wrong method name :-/ 2023-03-23 22:42:07 +00:00
cclecle
bd3389aeb2 cast to double + fix complexity 2023-03-23 22:37:45 +00:00
cclecle
886a22bef2 add missing java lib in groovy 2023-03-23 22:23:57 +00:00
cclecle
e9355471ba cast float to strings 2023-03-23 22:19:48 +00:00
cclecle
3bbbe946a1 switch to readfile 2023-03-23 21:54:21 +00:00
cclecle
cc2f6353ac add coverage results publishing 2023-03-23 21:40:03 +00:00
cclecle
6e1bff135b add missing test 2023-03-23 01:12:51 +00:00
cclecle
f74633cee3 feat: remove coverage pragma because we need to be realistic
test: add missing unit test
2023-03-23 00:07:53 +00:00
cclecle
3bb580689a improve formating
fix kwargs call
2023-03-22 23:32:36 +00:00
cclecle
235af0fd6d apply black 2023-03-22 23:21:39 +00:00
cclecle
8bdc425b3c updates 2023-03-22 23:13:40 +00:00
cclecle
4701015ba8 update name 2023-03-22 23:06:20 +00:00
cclecle
bf9b4f2207 update from pychangelogfactory 2023-03-22 23:05:20 +00:00
cclecle
31df26eb48 fix: twine cmd line 2023-03-22 09:43:00 +00:00
cclecle
7fa5de67a6 remove mermaid caus pyaml is having issue.. 2023-03-22 08:52:17 +00:00
cclecle
99ee668fe0 add mermaid 2023-03-22 01:34:07 +00:00
cclecle
e13561007b add mermaid2 and markdownextradata doc exts 2023-03-22 01:30:17 +00:00
cclecle
fe0bb13d86 revert yo mkdocs-with-pdf 2023-03-22 01:18:28 +00:00
14 changed files with 920 additions and 972 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>gitversionhelper</name>
<name>pygitversionhelper</name>
<comment></comment>
<projects>
</projects>

60
Jenkinsfile vendored
View File

@@ -6,7 +6,13 @@
// You should have received a copy of the license along with this
// work. If not, see <https://creativecommons.org/licenses/by-nc-sa/4.0/>.
import groovy.xml.XmlUtil
import static javax.xml.xpath.XPathConstants.*
import javax.xml.xpath.*
import groovy.xml.DOMBuilder
import groovy.xml.dom.DOMCategory
import java.math.RoundingMode
import java.math.BigDecimal
// configurable settings:
// use to send email if workflow problem
@@ -28,6 +34,11 @@ def _MkDocsWebURL = "dabauto--mkdocs-web.dmz.chacha.home/mkdocs-web/"
def _MkDocsWebCredentials = "2c5b684e-3787-4b37-8aca-b3dd4a383fe2"
def _PypiCredentials = "Pypi"
def badge_coverage = addEmbeddableBadgeConfiguration(id: "coverage", subject: "coverage")
def badge_complexity = addEmbeddableBadgeConfiguration(id: "complexity", subject: "code complexity")
def badge_quality = addEmbeddableBadgeConfiguration(id: "quality", subject: "quality score")
// commands Helper: /!\ Made for GITEA /!\
String determineRepoUserName() {
return scm.getUserRemoteConfigs()[0].getUrl().tokenize('/')[3].split("\\.")[0]
@@ -63,6 +74,28 @@ String ExtractBaseVersion(inVersion) {
return matcher[0][1]
}
int GetCoverageValue(String CoverageFilePath,String XPath)
{
//File file = new File(CoverageFilePath)
//coverageReportRaw = file.getText('UTF-8')
coverageReportRaw = readFile(CoverageFilePath)
coverageReport = DOMBuilder.parse(new StringReader(coverageReportRaw), false, false)
coverageReportRoot = coverageReport.documentElement
def xpath = XPathFactory.newInstance().newXPath()
res = xpath.evaluate(XPath,coverageReportRoot,NUMBER)
return res
}
int GetCoverageValue_lines_valid(String CoverageFilePath) { return GetCoverageValue(CoverageFilePath,"/coverage/@lines-valid") }
int GetCoverageValue_lines_covered(String CoverageFilePath) { return GetCoverageValue(CoverageFilePath,"/coverage/@lines-covered") }
int GetCoverageValue_line_rate(String CoverageFilePath) { return GetCoverageValue(CoverageFilePath,"/coverage/@line-rate") }
int GetCoverageValue_branches_valid(String CoverageFilePath) { return GetCoverageValue(CoverageFilePath,"/coverage/@branches-valid") }
int GetCoverageValue_branches_covered(String CoverageFilePath) { return GetCoverageValue(CoverageFilePath,"/coverage/@branches-covered") }
int GetCoverageValue_branch_rate(String CoverageFilePath) { return GetCoverageValue(CoverageFilePath,"/coverage/@branch-rate") }
int GetCoverageValue_complexity(String CoverageFilePath) { return GetCoverageValue(CoverageFilePath,"/coverage/@complexity") }
pipeline {
// for Docker based build (preferable)
@@ -137,7 +170,7 @@ pipeline {
script {
if(_PROJECT_NAME!="pygitversionhelper") {
sh(". ~/TOOLS_ENV/bin/activate && pip install git+https://chacha.ddns.net/gitea/chacha/pygitversionhelper.git@master")
sh(". ~/TOOLS_ENV/bin/activate && pip install pygitversionhelper")
}
else
{
@@ -334,6 +367,10 @@ pipeline {
steps {
dir("gitrepo") {
sh(". ~/TEST_ENV/bin/activate && python -m helpers --type-check --quality-check")
script {
def jsonObj = readJSON file: "helpers-results/quality_check/metrics.json"
badge_quality.setStatus(Float.toString(jsonObj["GlobalScore"]))
}
}
}
post {
@@ -400,6 +437,23 @@ pipeline {
println unit_test_full_name__html
unit_test_full_name__xml=findFiles(glob: "helpers-results/unit_test_full/*.xml")[0].getName()
println unit_test_full_name__xml
coverage_report_path = "helpers-results/unit_test_coverage/test_coverage.xml"
println GetCoverageValue_lines_valid(coverage_report_path)
println GetCoverageValue_lines_covered(coverage_report_path)
println GetCoverageValue_line_rate(coverage_report_path)
println GetCoverageValue_branches_valid(coverage_report_path)
println GetCoverageValue_branches_covered(coverage_report_path)
println GetCoverageValue_branch_rate(coverage_report_path)
println GetCoverageValue_complexity(coverage_report_path)
full_rate = new BigDecimal( (GetCoverageValue_line_rate(coverage_report_path) + GetCoverageValue_branch_rate(coverage_report_path)) / 2 )
sz_full_rate = Float.toString(full_rate.setScale(2, RoundingMode.HALF_EVEN))
badge_coverage.setStatus(sz_full_rate)
complexity = new BigDecimal( GetCoverageValue_complexity(coverage_report_path))
sz_complexity =Float.toString(complexity.setScale(2, RoundingMode.HALF_EVEN))
badge_complexity.setStatus(sz_complexity)
}
}
}
@@ -561,7 +615,7 @@ pipeline {
withCredentials([usernamePassword( credentialsId: _PypiCredentials, passwordVariable: 'PYPI_PASSWORD', usernameVariable: 'PYPI_USERNAME')]) {
sh(script: """#!/bin/sh -
|. ~/TOOLS_ENV/bin/activate
|exec twine upload -r ${PY_PROJECT_NAME} dist/* -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD} --non-interactive --disable-progress-bar
|exec twine upload -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD} --non-interactive --disable-progress-bar dist/*
""".stripMargin())
}
}

View File

@@ -1,5 +1,10 @@
![](https://chacha.ddns.net/jenkins/buildStatus/icon?subject=status&status=active&color=seagreen)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?subject=doc&status=MkDocs&color=blue)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?subject=jenkins-unittest&job={{repository}}-{{branch}})
![](https://chacha.ddns.net/jenkins/buildStatus/icon?subject=licence&status=CC%20BY-NC-SA%204.0&color=blue)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?job={{repository}}-{{branch}}&build=0&config=coverage&color=darkviolet)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?job={{repository}}-{{branch}}&build=0&config=complexity&color=darkviolet)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?job={{repository}}-{{branch}}&build=0&config=quality&color=darkviolet)
![](https://chacha.ddns.net/jenkins/buildStatus/icon?subject=licence&status=CC%20BY-NC-SA%204.0&color=teal)
![](docs-static/Library.jpg)

View File

@@ -4,4 +4,4 @@
# Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Unported License.
#
# You should have received a copy of the license along with this
# work. If not, see <https://creativecommons.org/licenses/by-nc-sa/4.0/>.
# work. If not, see <https://creativecommons.org/licenses/by-nc-sa/4.0/>.

View File

@@ -40,63 +40,24 @@ if __name__ == "__main__":
pyproject = tomli.load(fp)
parser = argparse.ArgumentParser(
prog="continuous-integration-helper",
description="A tiny set of scripts to help continous integration on python",
prog="continuous-integration-helper", description="A tiny set of scripts to help continous integration on python"
)
parser.add_argument("-tc", "--type-check", dest="typecheck", action="store_true", help="enable static typing check")
parser.add_argument("-ut", "--unit-test", dest="unittest", action="store_true", help="enable unit-test")
parser.add_argument(
"-tc",
"--type-check",
dest="typecheck",
action="store_true",
help="enable static typing check",
"-cc", "--coverage-check", dest="coveragecheck", action="store_true", help="enable unit-test coverage check (requires unit-test)"
)
parser.add_argument("-qc", "--quality-check", dest="qualitycheck", action="store_true", help="enable code quality check")
parser.add_argument("-dg", "--doc-gen", dest="docgen", action="store_true", help="enable documentation generation using MkDoc")
parser.add_argument(
"-ut",
"--unit-test",
dest="unittest",
action="store_true",
help="enable unit-test",
)
parser.add_argument(
"-cc",
"--coverage-check",
dest="coveragecheck",
action="store_true",
help="enable unit-test coverage check (requires unit-test)",
"-pdf", "--doc-gen-pdf", dest="docgenpdf", action="store_true", help="enable pdf documentation export (requires doc-gen)"
)
parser.add_argument(
"-qc",
"--quality-check",
dest="qualitycheck",
action="store_true",
help="enable code quality check",
)
parser.add_argument(
"-dg",
"--doc-gen",
dest="docgen",
action="store_true",
help="enable documentation generation using MkDoc",
)
parser.add_argument(
"-pdf",
"--doc-gen-pdf",
dest="docgenpdf",
action="store_true",
help="enable pdf documentation export (requires doc-gen)",
)
parser.add_argument(
"-clg",
"--changelog-gen",
dest="changeloggen",
action="store_true",
help="enable changelog generation",
)
parser.add_argument("-clg", "--changelog-gen", dest="changeloggen", action="store_true", help="enable changelog generation")
args = parser.parse_args()

View File

@@ -42,12 +42,8 @@ class doc_gen(helper_withresults_base):
cls._reset_dir(site_path)
# copy files from main project dir
shutil.copyfile(
str(cls.project_rootdir_path / "README.md"), str(doc_path / "README.md")
)
shutil.copyfile(
str(cls.project_rootdir_path / "LICENSE.md"), str(doc_path / "LICENSE.md")
)
shutil.copyfile(str(cls.project_rootdir_path / "README.md"), str(doc_path / "README.md"))
shutil.copyfile(str(cls.project_rootdir_path / "LICENSE.md"), str(doc_path / "LICENSE.md"))
# copy files from static-doc dir
copy_tree(str(cls.project_rootdir_path / "docs-static"), str(doc_path))
@@ -57,12 +53,8 @@ class doc_gen(helper_withresults_base):
cls._reset_dir(reference_path)
for path in sorted((cls.project_rootdir_path / "src").rglob("*.py")):
module_path = path.relative_to(
cls.project_rootdir_path / "src"
).with_suffix("")
doc_path = path.relative_to(cls.project_rootdir_path / "src").with_suffix(
".md"
)
module_path = path.relative_to(cls.project_rootdir_path / "src").with_suffix("")
doc_path = path.relative_to(cls.project_rootdir_path / "src").with_suffix(".md")
full_doc_path = Path(reference_path, doc_path)
parts = list(module_path.parts)
@@ -77,16 +69,7 @@ class doc_gen(helper_withresults_base):
identifier = "src." + ".".join(parts)
print("::: " + identifier, file=fd)
cmdopts = [
f"{sys.executable}",
"-m",
"mkdocs",
"-v",
"build",
"--site-dir",
str(site_path),
"--clean",
]
cmdopts = [f"{sys.executable}", "-m", "mkdocs", "-v", "build", "--site-dir", str(site_path), "--clean"]
# little hack here, to enable / disable pdf generation using own class config
# => reason is mkdocs seems to try loading the plugin even if we disable it, so we need to
@@ -100,12 +83,9 @@ class doc_gen(helper_withresults_base):
{
"with-pdf": {
"cover_subtitle": "User Manual",
"cover_logo": str(
cls.project_rootdir_path / "docs-static" / "Library.jpg"
),
"cover_logo": str(cls.project_rootdir_path / "docs-static" / "Library.jpg"),
"verbose": False,
"media_type": "print",
"headless_chrome_path": "chromium",
"exclude_pages": ["LICENSE"],
"output_path": str(site_path / "pdf" / "manual.pdf"),
}
@@ -119,11 +99,7 @@ class doc_gen(helper_withresults_base):
break
with open(cls.project_rootdir_path / "mkdocs.yml", "w") as mkdocsCfgFile:
mkdocsCfgFile.write(
yaml.dump(
mkdocsCfg, Dumper=Dumper, default_flow_style=False, sort_keys=False
)
)
mkdocsCfgFile.write(yaml.dump(mkdocsCfg, Dumper=Dumper, default_flow_style=False, sort_keys=False))
res = cls.run_cmd(cmdopts)
print(res.decode())

View File

@@ -53,13 +53,7 @@ class helper_base(ABC):
@classmethod
def run_cmd_(cls, cmdarray):
process = subprocess.run(
cmdarray,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
check=True,
)
process = subprocess.run(cmdarray, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, check=True)
return process.stdout
@classmethod
@@ -77,8 +71,4 @@ class helper_withresults_base(helper_base):
def get_result_dir(cls):
if cls.helper_results_dir == None:
cls.helper_results_dir = cls.__name__
return (
Path(__file__).parent.parent.absolute()
/ "helpers-results"
/ cls.helper_results_dir
)
return Path(__file__).parent.parent.absolute() / "helpers-results" / cls.helper_results_dir

View File

@@ -37,9 +37,7 @@ class quality_check(helper_withresults_base):
def GetPylintMessageList(cls):
Messagelist = dict()
regex = r"^:([a-zA-Z-]+) \(([^\)]+)\)"
for line in cls.run_cmd(
[sys.executable, "-m", "pylint", "--list-msgs"]
).splitlines():
for line in cls.run_cmd([sys.executable, "-m", "pylint", "--list-msgs"]).splitlines():
if res := re.search(regex, line.decode()):
Messagelist[res.group(1)] = res.group(2)
cls.PylintMessageList = Messagelist
@@ -73,9 +71,7 @@ class quality_check(helper_withresults_base):
exit=False,
)
with open(
cls.get_result_dir() / "report.json", "w+", encoding="utf-8"
) as Outfile:
with open(cls.get_result_dir() / "report.json", "w+", encoding="utf-8") as Outfile:
# hacky way of exctracting json + having overall score...
class TScanState(Enum):
TEXT_REPORT = 1
@@ -122,81 +118,45 @@ class quality_check(helper_withresults_base):
ScanState = TScanState.OTHER_REPORT_STATISTICS
elif ScanState == TScanState.OTHER_REPORT_STATISTICS:
if res := re.search(
r"^(\d+)(?= lines have been analyzed)", line
):
if res := re.search(r"^(\d+)(?= lines have been analyzed)", line):
RES_all["NbAnalysedLines"] = float(res.group(1))
elif line == "Raw metrics":
ScanState = TScanState.OTHER_REPORT_METRICS
else:
with suppress(PyLintMetricNotFound):
RES_all["Statistics"][
"module"
] = cls.TryExtractPYReportMetric(line, "module")
RES_all["Statistics"]["module"] = cls.TryExtractPYReportMetric(line, "module")
with suppress(PyLintMetricNotFound):
RES_all["Statistics"][
"class"
] = cls.TryExtractPYReportMetric(line, "class")
RES_all["Statistics"]["class"] = cls.TryExtractPYReportMetric(line, "class")
with suppress(PyLintMetricNotFound):
RES_all["Statistics"][
"method"
] = cls.TryExtractPYReportMetric(line, "method")
RES_all["Statistics"]["method"] = cls.TryExtractPYReportMetric(line, "method")
with suppress(PyLintMetricNotFound):
RES_all["Statistics"][
"function"
] = cls.TryExtractPYReportMetric(line, "function")
RES_all["Statistics"]["function"] = cls.TryExtractPYReportMetric(line, "function")
elif ScanState == TScanState.OTHER_REPORT_METRICS:
if line == "Duplication":
RES_all["RawMetricsPercent"]["code"] = (
RES_all["RawMetrics"]["code"]
/ RES_all["NbAnalysedLines"]
)
RES_all["RawMetricsPercent"]["docstring"] = (
RES_all["RawMetrics"]["docstring"]
/ RES_all["NbAnalysedLines"]
)
RES_all["RawMetricsPercent"]["comment"] = (
RES_all["RawMetrics"]["comment"]
/ RES_all["NbAnalysedLines"]
)
RES_all["RawMetricsPercent"]["empty"] = (
RES_all["RawMetrics"]["empty"]
/ RES_all["NbAnalysedLines"]
)
RES_all["RawMetricsPercent"]["code"] = RES_all["RawMetrics"]["code"] / RES_all["NbAnalysedLines"]
RES_all["RawMetricsPercent"]["docstring"] = RES_all["RawMetrics"]["docstring"] / RES_all["NbAnalysedLines"]
RES_all["RawMetricsPercent"]["comment"] = RES_all["RawMetrics"]["comment"] / RES_all["NbAnalysedLines"]
RES_all["RawMetricsPercent"]["empty"] = RES_all["RawMetrics"]["empty"] / RES_all["NbAnalysedLines"]
ScanState = TScanState.OTHER_REPORT_DUPLICATION
else:
with suppress(PyLintMetricNotFound):
RES_all["RawMetrics"][
"code"
] = cls.TryExtractPYReportMetric(line, "code")
RES_all["RawMetrics"]["code"] = cls.TryExtractPYReportMetric(line, "code")
with suppress(PyLintMetricNotFound):
RES_all["RawMetrics"][
"docstring"
] = cls.TryExtractPYReportMetric(line, "docstring")
RES_all["RawMetrics"]["docstring"] = cls.TryExtractPYReportMetric(line, "docstring")
with suppress(PyLintMetricNotFound):
RES_all["RawMetrics"][
"comment"
] = cls.TryExtractPYReportMetric(line, "comment")
RES_all["RawMetrics"]["comment"] = cls.TryExtractPYReportMetric(line, "comment")
with suppress(PyLintMetricNotFound):
RES_all["RawMetrics"][
"empty"
] = cls.TryExtractPYReportMetric(line, "empty")
RES_all["RawMetrics"]["empty"] = cls.TryExtractPYReportMetric(line, "empty")
elif ScanState == TScanState.OTHER_REPORT_DUPLICATION:
if line == "Messages by category":
ScanState = TScanState.OTHER_REPORT_MESSAGES_CAT
else:
with suppress(PyLintMetricNotFound):
RES_all["Duplication"][
"NbDupLines"
] = cls.TryExtractPYReportMetric(
line, "nb duplicated lines"
)
RES_all["Duplication"]["NbDupLines"] = cls.TryExtractPYReportMetric(line, "nb duplicated lines")
with suppress(PyLintMetricNotFound):
RES_all["Duplication"][
"PersentDuplicatedLines"
] = cls.TryExtractPYReportMetric(
RES_all["Duplication"]["PersentDuplicatedLines"] = cls.TryExtractPYReportMetric(
line, "percent duplicated lines"
)
@@ -205,21 +165,13 @@ class quality_check(helper_withresults_base):
ScanState = TScanState.OTHER_REPORT_MESSAGES
else:
with suppress(PyLintMetricNotFound):
RES_all["MessagesCat"][
"Convention"
] = cls.TryExtractPYReportMetric(line, "convention")
RES_all["MessagesCat"]["Convention"] = cls.TryExtractPYReportMetric(line, "convention")
with suppress(PyLintMetricNotFound):
RES_all["MessagesCat"][
"Refactor"
] = cls.TryExtractPYReportMetric(line, "refactor")
RES_all["MessagesCat"]["Refactor"] = cls.TryExtractPYReportMetric(line, "refactor")
with suppress(PyLintMetricNotFound):
RES_all["MessagesCat"][
"Warning"
] = cls.TryExtractPYReportMetric(line, "warning")
RES_all["MessagesCat"]["Warning"] = cls.TryExtractPYReportMetric(line, "warning")
with suppress(PyLintMetricNotFound):
RES_all["MessagesCat"][
"Error"
] = cls.TryExtractPYReportMetric(line, "error")
RES_all["MessagesCat"]["Error"] = cls.TryExtractPYReportMetric(line, "error")
elif ScanState == TScanState.OTHER_REPORT_MESSAGES:
# approx match because the number of '-' depend on screen width..
@@ -228,16 +180,10 @@ class quality_check(helper_withresults_base):
else:
for PylintMessage in cls.PylintMessageList.keys():
with suppress(PyLintMetricNotFound):
RES_all["Messages"][
PylintMessage
] = cls.TryExtractPYReportMetric(
line, PylintMessage
)
RES_all["Messages"][PylintMessage] = cls.TryExtractPYReportMetric(line, PylintMessage)
elif ScanState == TScanState.OTHER_REPORT_END:
if res := re.search(
r"(?<=Your code has been rated at )(\d+(?:\.\d+)?)/10", line
):
if res := re.search(r"(?<=Your code has been rated at )(\d+(?:\.\d+)?)/10", line):
RES_all["GlobalScore"] = float(res.group(1))
print(RES_all["GlobalScore"])
else:
@@ -251,9 +197,7 @@ class quality_check(helper_withresults_base):
# => to export a working full csv we need to a 'flat' dict (no more nested dict)
RES_all_trim = copy.deepcopy(RES_all)
del RES_all_trim["Messages"]
flat_RES_all = pandas.json_normalize(RES_all_trim, sep="_").to_dict(
orient="records"
)[0]
flat_RES_all = pandas.json_normalize(RES_all_trim, sep="_").to_dict(orient="records")[0]
with open(cls.get_result_dir() / "metrics.csv", "w", newline="") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=flat_RES_all.keys())
@@ -262,9 +206,7 @@ class quality_check(helper_withresults_base):
# splited csv exports for jenkins plots: RawMetricsPercent
RES_all_percent = RES_all["RawMetricsPercent"]
with open(
cls.get_result_dir() / "metrics_rawpercent.csv", "w", newline=""
) as csv_file:
with open(cls.get_result_dir() / "metrics_rawpercent.csv", "w", newline="") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=RES_all_percent.keys())
writer.writeheader()
writer.writerow(RES_all_percent)
@@ -272,40 +214,30 @@ class quality_check(helper_withresults_base):
# splited csv exports for jenkins plots: Statistics + Duplication + NbAnalysedStatments + NbAnalysedLines
RES_all_stats = copy.deepcopy(RES_all["Statistics"])
RES_all_stats["NbDupLines"] = RES_all["Duplication"]["NbDupLines"]
RES_all_stats["PersentDuplicatedLines"] = RES_all["Duplication"][
"PersentDuplicatedLines"
]
RES_all_stats["PersentDuplicatedLines"] = RES_all["Duplication"]["PersentDuplicatedLines"]
RES_all_stats["NbAnalysedStatments"] = RES_all["NbAnalysedStatments"]
RES_all_stats["NbAnalysedLines"] = RES_all["NbAnalysedLines"]
with open(
cls.get_result_dir() / "metrics_Statistics.csv", "w", newline=""
) as csv_file:
with open(cls.get_result_dir() / "metrics_Statistics.csv", "w", newline="") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=RES_all_stats.keys())
writer.writeheader()
writer.writerow(RES_all_stats)
# splited csv exports for jenkins plots: Statistics + Duplication
RES_all_MessagesCat = RES_all["MessagesCat"]
with open(
cls.get_result_dir() / "metrics_MessagesCat.csv", "w", newline=""
) as csv_file:
with open(cls.get_result_dir() / "metrics_MessagesCat.csv", "w", newline="") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=RES_all_MessagesCat.keys())
writer.writeheader()
writer.writerow(RES_all_MessagesCat)
# splited csv exports for jenkins plots: GlobalScore
RES_GlobalScore = {"GlobalScore": RES_all["GlobalScore"]}
with open(
cls.get_result_dir() / "metrics_GlobalScore.csv", "w", newline=""
) as csv_file:
with open(cls.get_result_dir() / "metrics_GlobalScore.csv", "w", newline="") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=RES_GlobalScore.keys())
writer.writeheader()
writer.writerow(RES_GlobalScore)
# converting the report using pylint_json2html (/!\ internal API, but as their is no leading '_' ...)
with open(
cls.get_result_dir() / "report.html", "w+", encoding="utf-8"
) as Outfile:
with open(cls.get_result_dir() / "report.html", "w+", encoding="utf-8") as Outfile:
raw_data = json.loads(JsonContent)
report = pylint_json2html.Report(raw_data)
Outfile.write(report.render())

View File

@@ -40,16 +40,11 @@ class unit_test(helper_withresults_base):
# we start coverage now because module files discovery is part of the coverage measurement
CoverageReportPath = Path(str(cls.get_result_dir()) + "_coverage")
cls._reset_dir(CoverageReportPath)
cov = coverage.Coverage(
cover_pylib=False,
branch=True,
source_pkgs=["src." + cls.pyproject["project"]["name"]],
)
cov = coverage.Coverage(cover_pylib=False, branch=True, source_pkgs=["src." + cls.pyproject["project"]["name"]])
cov.start()
package_tests = test_loader.discover(
start_dir=str(cls.project_rootdir_path / "test"),
top_level_dir=str(cls.project_rootdir_path / "test"),
start_dir=str(cls.project_rootdir_path / "test"), top_level_dir=str(cls.project_rootdir_path / "test")
)
if cls.enable_xml_export:
testRunner = xmlrunner.XMLTestRunner(output=str(str(cls.get_result_dir())))
@@ -64,9 +59,7 @@ class unit_test(helper_withresults_base):
cov.stop()
cov.save()
cov.html_report(directory=str(CoverageReportPath))
cov.xml_report(
outfile=(CoverageReportPath / f"{cls.CoverageReportName}.xml")
)
cov.xml_report(outfile=(CoverageReportPath / f"{cls.CoverageReportName}.xml"))
# computing results (Only if xml available)
if cls.enable_full_xml_export == True:
@@ -75,22 +68,14 @@ class unit_test(helper_withresults_base):
cls._reset_dir(FullReportPath)
FullJUnitReport = JUnitXml()
for fname in [
fname
for fname in os.listdir(cls.get_result_dir())
if fname.endswith(".xml")
]:
for fname in [fname for fname in os.listdir(cls.get_result_dir()) if fname.endswith(".xml")]:
FullJUnitReport += JUnitXml.fromfile(str(cls.get_result_dir() / fname))
current_datetime = datetime.datetime.utcnow().strftime("%Y%m%dT%H%M%SZ")
full_report_base_name = f'{cls.pyproject["project"]["name"]}-{cls.FullReportName}-{current_datetime}'
FullJUnitReport.write(str(FullReportPath / f"{full_report_base_name}.xml"))
report = junit2html_parser.Junit(
FullReportPath / f"{full_report_base_name}.xml"
)
report = junit2html_parser.Junit(FullReportPath / f"{full_report_base_name}.xml")
html = report.html()
with open(
FullReportPath / f"{full_report_base_name}.html", "wb"
) as outfile:
with open(FullReportPath / f"{full_report_base_name}.html", "wb") as outfile:
outfile.write(html.encode("utf-8"))
print("Done")

View File

@@ -1,11 +1,19 @@
# pyChaChaDummyProject (c) by chacha
#
# pyChaChaDummyProject is licensed under a
# Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Unported License.
#
# You should have received a copy of the license along with this
# work. If not, see <https://creativecommons.org/licenses/by-nc-sa/4.0/>.
docs_dir: docs
site_name: pygitversionhelper
site_url: 'https://chacha.ddns.net/mkdocs-web/chacha/pygitversionhelper/latest/'
site_description: pygitversionhelper
site_author: chacha
site_author: ChaCha
repo_url: 'https://chacha.ddns.net/gitea/chacha/pygitversionhelper'
use_directory_urls: false
copyright: Copyright &copy; 2016 - 2023 chacha
copyright: CC BY-NC-SA 4.0
theme:
name: material
features:
@@ -32,6 +40,8 @@ theme:
name: Switch to dark mode
plugins:
- search
- markdownextradata
- mermaid2
- localsearch
- autorefs
- mkdocstrings:
@@ -75,4 +85,8 @@ markdown_extensions:
- pymdownx.tasklist:
custom_checkbox: true
- pymdownx.tilde
- footnotes
- footnotes
extra:
branch: master
repository: pygitversionhelper

View File

@@ -59,7 +59,7 @@ test = ["junitparser>=2.8","junit2html>=30.1","xmlrunner>=1.7","myp
coverage-check = ["coverage>=7.0"]
quality-check = ["pylint>=2.15","pylint-json2html>=0.4","pandas>=1.5"]
type-check = ["mypy[reports]>=0.99" ]
doc-gen = ["mkdocs>=1.4.0", "mkdocs-material>=8.5", "mkdocs-localsearch>=0.9.0", "mkdocstrings[python]>=0.19", "mkdocs-pdf-export-plugin","pyyaml>=6.0","pymdown-extensions>=9"]
doc-gen = ["mkdocs>=1.4.0", "mkdocs-material>=8.5", "mkdocs-localsearch>=0.9.0", "mkdocstrings[python]>=0.19", "mkdocs-with-pdf>=0.9.3","pyyaml>=6.0","pymdown-extensions>=9","mkdocs-markdownextradata-plugin","mkdocs-mermaid2-plugin"]
#[project.scripts]
#my-script = "my_package.module:function"

View File

@@ -14,8 +14,9 @@ from importlib.metadata import version, PackageNotFoundError
try: # pragma: no cover
__version__ = version("pygitversionhelper")
except PackageNotFoundError: # pragma: no cover
except PackageNotFoundError: # pragma: no cover
import warnings
warnings.warn("can not read __version__, assuming local test context, setting it to ?.?.?")
__version__ = "?.?.?"

View File

@@ -37,9 +37,7 @@ import logging
from packaging.version import VERSION_PATTERN as packaging_VERSION_PATTERN
def _exec(
cmd: str, root: str | os.PathLike | None = None, raw: bool = False
) -> list[str]:
def _exec(cmd: str, root: str | os.PathLike | None = None, raw: bool = False) -> list[str]:
"""
helper function to handle system cmd execution
Args:
@@ -60,9 +58,9 @@ def _exec(
)
if re.search("not a git repository", p.stderr):
raise gitversionhelper.repository.notAGitRepository()
if re.search("fatal:", p.stderr): # pragma: nocover
if re.search("fatal:", p.stderr):
raise gitversionhelper.unknownGITFatalError(p.stderr)
if int(p.returncode) < 0: # pragma: nocover
if int(p.returncode) < 0:
raise gitversionhelper.unknownGITError(p.stderr)
if raw:
@@ -147,7 +145,7 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
def getMessagesSinceTag(cls, tag: str, **kwargs) -> str:
"""
retrieve a commits message history from repository
from LastCommit to the given tag
from Latest commit to the given tag
Keyword Arguments:
merged_output: output one single merged string
same_branch(bool): force searching only in the same branch
@@ -157,23 +155,15 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
current_commit_id = cls.getLast(**kwargs)
tag_commit_id = cls.getFromTag(tag)
if (cls.__OptDict["same_branch"] in kwargs) and (
kwargs[cls.__OptDict["same_branch"]] is True
):
commits = _exec(
f"git rev-list --first-parent --ancestry-path {tag_commit_id}..{current_commit_id}"
)
if (cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True):
commits = _exec(f"git rev-list --first-parent --ancestry-path {tag_commit_id}..{current_commit_id}")
else:
commits = _exec(
f"git rev-list --ancestry-path {tag_commit_id}..{current_commit_id}"
)
commits = _exec(f"git rev-list --ancestry-path {tag_commit_id}..{current_commit_id}")
result = []
for commit in commits:
result.append(cls.getMessage(commit))
if (cls.__OptDict["merged_output"] in kwargs) and (
kwargs[cls.__OptDict["merged_output"]] is True
):
if (cls.__OptDict["merged_output"] in kwargs) and (kwargs[cls.__OptDict["merged_output"]] is True):
print("JOIN")
return os.linesep.join(result)
return result
@@ -224,19 +214,13 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
Returns:
the commit Id
"""
if (cls.__OptDict["same_branch"] in kwargs) and (
kwargs[cls.__OptDict["same_branch"]] is True
):
if (cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True):
try:
res = _exec("git rev-parse HEAD")
except gitversionhelper.unknownGITFatalError as _e:
raise cls.commitNotFound(
"no commit found in commit history"
) from _e
raise cls.commitNotFound("no commit found in commit history") from _e
else:
res = _exec(
'git for-each-ref --sort=-committerdate refs/heads/ --count 1 --format="%(objectname)"'
)
res = _exec('git for-each-ref --sort=-committerdate refs/heads/ --count 1 --format="%(objectname)"')
if len(res) == 0:
raise cls.commitNotFound("no commit found in commit history")
@@ -286,29 +270,21 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
if sort not in cls.__validGitTagSort:
raise gitversionhelper.wrongArguments("sort option not in allowed list")
if (cls.__OptDict["same_branch"] in kwargs) and (
kwargs[cls.__OptDict["same_branch"]] is True
):
if (cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True):
currentBranch = _exec("git rev-parse --abbrev-ref HEAD")
return list(
reversed(
_exec(f"git tag --merged {currentBranch[0]} --sort={sort}")
)
)
return list(reversed(_exec(f"git tag --merged {currentBranch[0]} --sort={sort}")))
return list(reversed(_exec(f"git tag -l --sort={sort}")))
@classmethod
def getLastTag(cls, **kwargs) -> str | None:
"""
retrieve the last tag from a repository
retrieve the Latest tag from a repository
Keyword Arguments:
same_branch(bool): force searching only in the same branch
Returns:
the tag
"""
if (cls.__OptDict["same_branch"] in kwargs) and (
kwargs[cls.__OptDict["same_branch"]] is True
):
if (cls.__OptDict["same_branch"] in kwargs) and (kwargs[cls.__OptDict["same_branch"]] is True):
res = _exec("git describe --tags --first-parent --abbrev=0")
else:
res = _exec("git rev-list --tags --date-order --max-count=1")
@@ -317,14 +293,14 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
if len(res) == 0:
raise cls.tagNotFound("no tag found in commit history")
if len(res) != 1: # pragma: nocover
if len(res) != 1:
raise cls.moreThanOneTag("multiple tags on same commit is unsupported")
return res[0]
@classmethod
def getDistanceFromTag(cls, tag: str = None, **kwargs) -> int:
"""
retrieve the distance between HEAD and tag in the repository
retrieve the distance between Latest commit and tag in the repository
Arguments:
tag: reference tag, if None the most recent one will be used
Keyword Arguments:
@@ -428,15 +404,10 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
"""
BumpDevStrategy = cls.DefaultBumpDevStrategy
if cls.__OptDict["bump_dev_strategy"] in kwargs:
if (
kwargs[cls.__OptDict["bump_dev_strategy"]]
in cls.BumpDevStrategys
):
if kwargs[cls.__OptDict["bump_dev_strategy"]] in cls.BumpDevStrategys:
BumpDevStrategy = kwargs[cls.__OptDict["bump_dev_strategy"]]
else:
raise gitversionhelper.wrongArguments(
f"invalid {cls.__OptDict['bump_type']} requested"
)
raise gitversionhelper.wrongArguments(f"invalid {cls.__OptDict['bump_type']} requested")
return BumpDevStrategy
@classmethod
@@ -453,14 +424,10 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
if kwargs[cls.__OptDict["bump_type"]] in cls.BumpTypes:
BumpType = kwargs[cls.__OptDict["bump_type"]]
else:
raise gitversionhelper.wrongArguments(
f"invalid {cls.__OptDict['bump_type']} requested"
)
raise gitversionhelper.wrongArguments(f"invalid {cls.__OptDict['bump_type']} requested")
return BumpType
def bump(
self, amount: int = 1, **kwargs
) -> gitversionhelper.version.MetaVersion | str: # pylint: disable=R0912
def bump(self, amount: int = 1, **kwargs) -> gitversionhelper.version.MetaVersion | str: # pylint: disable=R0912
"""
bump the version to the next one
Keyword Arguments:
@@ -508,9 +475,7 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
_v.post_count = 0
_v.raw = _v.doFormatVersion(**kwargs)
if (self.__OptDict["formated_output"] in kwargs) and (
kwargs[self.__OptDict["formated_output"]] is True
):
if (self.__OptDict["formated_output"] in kwargs) and (kwargs[self.__OptDict["formated_output"]] is True):
return _v.doFormatVersion(**kwargs)
return _v
@@ -538,9 +503,7 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
if kwargs[cls.__OptDict["version_std"]] in cls.VersionStds:
VersionStd = kwargs[cls.__OptDict["version_std"]]
else:
raise gitversionhelper.wrongArguments(
f"invalid {cls.__OptDict['version_std']} requested"
)
raise gitversionhelper.wrongArguments(f"invalid {cls.__OptDict['version_std']} requested")
return VersionStd
@classmethod
@@ -557,10 +520,7 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
the last version
"""
if gitversionhelper.repository.isDirty() is not False:
raise gitversionhelper.repository.repositoryDirty(
"The repository is dirty and a current version"
" can not be generated."
)
raise gitversionhelper.repository.repositoryDirty("The repository is dirty and a current version can not be generated.")
saved_kwargs = copy(kwargs)
if "formated_output" in kwargs:
del saved_kwargs["formated_output"]
@@ -571,9 +531,7 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
amount = gitversionhelper.tag.getDistanceFromTag(_v.raw, **kwargs)
_v = _v.bump(amount, **saved_kwargs)
if (cls.__OptDict["formated_output"] in kwargs) and (
kwargs[cls.__OptDict["formated_output"]] is True
):
if (cls.__OptDict["formated_output"] in kwargs) and (kwargs[cls.__OptDict["formated_output"]] is True):
return _v.doFormatVersion(**kwargs)
return _v
@@ -583,7 +541,7 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
Same as getCurrentVersion() with formated_output kwarg activated
"""
kwargs["formated_output"] = True
return cls.getCurrentVersion(kwargs)
return cls.getCurrentVersion(**kwargs)
@classmethod
def _parseTag(cls, tag, **kwargs): # pylint: disable=R0914, R0912, R0915
@@ -618,31 +576,21 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
pre_count = 0
if _pre := _m.group("prerelease"):
if (
_match := re.search(
cls.VersionStds["SemVer"]["regex_preversion_num"], _pre
)
) is not None:
if (_match := re.search(cls.VersionStds["SemVer"]["regex_preversion_num"], _pre)) is not None:
pre_count = int(_match.group("num"))
else:
pre_count = 1
post_count = 0
if _post := _m.group("buildmetadata"):
if (
_match := re.search(
cls.VersionStds["SemVer"]["regex_build_num"], _post
)
) is not None:
if (_match := re.search(cls.VersionStds["SemVer"]["regex_build_num"], _post)) is not None:
post_count = int(_match.group("num"))
else:
post_count = 1
bFound = True
VersionStd = "SemVer"
if VersionStd == "PEP440" or (
(bAutoVersionStd is True) and (bFound is not True)
):
if VersionStd == "PEP440" or ((bAutoVersionStd is True) and (bFound is not True)):
_r = re.compile(
r"^\s*" + cls.VersionStds["PEP440"]["regex"] + r"\s*$",
re.VERBOSE | re.IGNORECASE,
@@ -663,22 +611,14 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
VersionStd = "PEP440"
if not bFound:
raise gitversionhelper.version.noValidVersion(
"no valid version found in tags"
)
raise gitversionhelper.version.noValidVersion("no valid version found in tags")
if pre_count > 0 and post_count > 0:
raise cls.PreAndPostVersionUnsupported(
"can not parse a version with both pre" " and post release number."
)
return cls.MetaVersion(
VersionStd, major, minor, patch, pre_count, post_count, tag
)
raise cls.PreAndPostVersionUnsupported("can not parse a version with both pre and post release number.")
return cls.MetaVersion(VersionStd, major, minor, patch, pre_count, post_count, tag)
@classmethod
def getLastVersion(
cls, **kwargs
) -> MetaVersion | str: # pylint: disable=R0914, R0912, R0915
def getLastVersion(cls, **kwargs) -> MetaVersion | str: # pylint: disable=R0914, R0912, R0915
"""get the last version from tags
Keyword Arguments:
version_std(str): the given version_std (can be None)
@@ -700,9 +640,7 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
try:
_v = cls._parseTag(lastTag, **kwargs)
except gitversionhelper.version.noValidVersion as _ex:
if (cls.__OptDict["ignore_unknown_tags"] in kwargs) and (
kwargs[cls.__OptDict["ignore_unknown_tags"]] is True
):
if (cls.__OptDict["ignore_unknown_tags"] in kwargs) and (kwargs[cls.__OptDict["ignore_unknown_tags"]] is True):
tags = gitversionhelper.tag.getTags(sort="taggerdate", **kwargs)
_v = None
for _tag in tags:
@@ -714,9 +652,7 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
if _v is None:
raise gitversionhelper.version.noValidVersion() from _ex
if (cls.__OptDict["formated_output"] in kwargs) and (
kwargs[cls.__OptDict["formated_output"]] is True
):
if (cls.__OptDict["formated_output"] in kwargs) and (kwargs[cls.__OptDict["formated_output"]] is True):
return _v.doFormatVersion(**kwargs)
return _v
@@ -750,8 +686,7 @@ class gitversionhelper: # pylint: disable=too-few-public-methods
OutputFormat = "{major}.{minor}.{patch}{revpattern}{revcount}"
if post_count > 0 and pre_count > 0:
raise gitversionhelper.version.PreAndPostVersionUnsupported(
"cannot output a version with both pre "
"and post release number."
"cannot output a version with both pre and post release number."
)
if VersionStd == "PEP440":
if post_count > 0:

File diff suppressed because it is too large Load Diff