diff --git a/Makefile b/Makefile index 187abf2..3003ff0 100644 --- a/Makefile +++ b/Makefile @@ -7,11 +7,10 @@ test: testint: bash demo.sh 0to100 && bash demo.sh 0to100_sb - format: black zero_to_one_hundred lint: pylint --disable=C0116,C0115,W0702,C0114,C0301,C0103,C0209,R0913,R0902,R0903,E1101,W0612,W0718,R0801,W0150,W0613 zero_to_one_hundred -refactor: format lint +pr: format lint test testint install diff --git a/demo.sh b/demo.sh index c89616a..5b76ddc 100644 --- a/demo.sh +++ b/demo.sh @@ -32,11 +32,6 @@ function 0to100 { setup0to100 ./main.py help -# - name: Course -# - name: Game -# - name: Lab -# - name: Quest -# - name: Template content=$(cat << 'EOF' https://www.cloudskillsboost.google/games/4424/labs/28651 https://www.cloudskillsboost.google/course_templates/3 @@ -45,10 +40,8 @@ https://storage.googleapis.com/cloud-training/cls-html5-courses/T-BQRS-I/M1/inde EOF ) -while IFS= read -r line || [[ -n "$line" ]]; do - echo "Processing: $line" - - ./main.py create_section "$line" +while IFS= read -r section || [[ -n "$section" ]]; do + ./main.py create_section "$section" done <<< "$content" diff --git a/zero_to_one_hundred/configs/a_config_map.py b/zero_to_one_hundred/configs/a_config_map.py index 2412eb8..6a90dd5 100644 --- a/zero_to_one_hundred/configs/a_config_map.py +++ b/zero_to_one_hundred/configs/a_config_map.py @@ -2,7 +2,6 @@ import os from abc import ABC from dataclasses import dataclass -from enum import Enum from zero_to_one_hundred.exceptions.errors import SomeError from zero_to_one_hundred.repository.a_persist_fs import APersistFS @@ -15,12 +14,14 @@ class AConfigMap(ABC): class LegendIcons: name: str icon: str - regex:str + regex: str def __init__(self, persist_fs: APersistFS): self.map_yaml_path = os.getenv(AConfigMap.MAP_YAML_PATH) if self.map_yaml_path is None: - raise SomeError(f"map_yaml_path {self.map_yaml_path} is not valid, please set it in the env") + raise SomeError( + f"map_yaml_path {self.map_yaml_path} is not valid, please set it in the env" + ) self.persist_fs = persist_fs def __repr__(self): @@ -38,25 +39,29 @@ def get_type(self): @property def get_legend_icons(self): - legend = self.load.get("legend") + legend = self.load.get("legend") if legend: return [ - AConfigMap.LegendIcons(name=icon_data['name'], icon=icon_data['icon'], regex=icon_data['regex']) - for icon_data in legend.get('icons', []) - if isinstance(icon_data, dict)] + AConfigMap.LegendIcons( + name=icon_data["name"], + icon=icon_data["icon"], + regex=icon_data["regex"], + ) + for icon_data in legend.get("icons", []) + if isinstance(icon_data, dict) + ] return [] - @property def get_legend_type(self) -> str | None: - return None if self.load.get("legend") is None else self.load.get("legend").get("type") - + return ( + None + if self.load.get("legend") is None + else self.load.get("legend").get("type") + ) @property def get_legend_icons_as_md(self): icons = self.get_legend_icons res = [f"`{i.name}` {i.icon}" for i in icons] - if res is []: - return "" - return "**legend_icons**\n" + "\n".join(res) - + return "" if res == "" else "**legend_icons**\n" + "\n".join(res) diff --git a/zero_to_one_hundred/configs/ztoh_config_map.py b/zero_to_one_hundred/configs/ztoh_config_map.py index cfe4588..5832022 100644 --- a/zero_to_one_hundred/configs/ztoh_config_map.py +++ b/zero_to_one_hundred/configs/ztoh_config_map.py @@ -1,4 +1,3 @@ -from dataclasses import dataclass from zero_to_one_hundred.configs.a_config_map import AConfigMap from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS @@ -6,8 +5,6 @@ class ZTOHConfigMap(AConfigMap): - - def __init__(self, persist_fs: ZTOHPersistFS): super().__init__(persist_fs) @@ -22,4 +19,3 @@ def get_repo_map_md(self): @property def get_repo_sorted(self) -> bool: return self.load["repo"].get("sorted") - diff --git a/zero_to_one_hundred/models/map.py b/zero_to_one_hundred/models/map.py index 034b60e..0dc5f5f 100644 --- a/zero_to_one_hundred/models/map.py +++ b/zero_to_one_hundred/models/map.py @@ -1,6 +1,5 @@ from typing import List -from zero_to_one_hundred.configs.a_config_map import AConfigMap from zero_to_one_hundred.configs.ztoh_config_map import ZTOHConfigMap from zero_to_one_hundred.models.section import Section from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS @@ -26,14 +25,13 @@ def __repr__(self): return f"Map {str(self.sections)}" def get_sections(self): - - res :List[Section] = self.sections + res: List[Section] = self.sections if self.config_map.get_repo_sorted == "abc": - print('*** abc') - res= sorted(self.sections, key=lambda s: s.dir_name) + print("*** abc") + res = sorted(self.sections, key=lambda s: s.dir_name) if self.config_map.get_repo_sorted == "00:00:00": - print('*** 00:00:00') - res = sorted(self.sections, key=lambda s: s.get_readme_md_time()) + print("*** 00:00:00") + res = sorted(self.sections, key=lambda s: s.get_readme_md_time()) return res def asMarkDown(self) -> str: @@ -46,7 +44,7 @@ def get_legend_as_md(self): txt += lf_char txt += self.config_map.get_legend_icons_as_md return txt - + txt = f"""{f"# map {self.readme_md}, {len(self.sections)}"} {get_legend_as_md(self)} diff --git a/zero_to_one_hundred/models/section.py b/zero_to_one_hundred/models/section.py index d30821d..2280de1 100644 --- a/zero_to_one_hundred/models/section.py +++ b/zero_to_one_hundred/models/section.py @@ -1,6 +1,6 @@ # pylint: disable= R0904 +import re -from zero_to_one_hundred.configs.a_config_map import AConfigMap from zero_to_one_hundred.configs.ztoh_config_map import ZTOHConfigMap from zero_to_one_hundred.models.readme_md import ReadMeMD from zero_to_one_hundred.repository.ztoh_persist_fs import ZTOHPersistFS @@ -86,9 +86,7 @@ def write_done_section(self): ) def get_readme_md_time(self): - return self.persist_fs.get_biz_ts( - self.dir_readme_md - ) + return self.persist_fs.get_biz_ts(self.dir_readme_md) @classmethod def from_http_url_to_dir_to(cls, dir_name): @@ -217,9 +215,9 @@ def is_datacamp_course(self): @property def get_matching_icon_as_md(self): icons = self.config_map.get_legend_icons - import re - res= [i.icon for i in icons if re.search(i.regex, self.http_url )] - return ' '.join(res) + + res = [i.icon for i in icons if re.search(i.regex, self.http_url)] + return " ".join(res) def __eq__(self, other): if other is self: diff --git a/zero_to_one_hundred/repository/ztoh_persist_fs.py b/zero_to_one_hundred/repository/ztoh_persist_fs.py index 64a4091..854715a 100644 --- a/zero_to_one_hundred/repository/ztoh_persist_fs.py +++ b/zero_to_one_hundred/repository/ztoh_persist_fs.py @@ -34,7 +34,6 @@ def done_section_status(cls, abs_repo_path, path): @classmethod def get_biz_ts(cls, path): - # print(f"path {path}") exists = os.path.exists(path) # print(f"exists {exists}") diff --git a/zero_to_one_hundred/tests/test_ztoh/test_section.py b/zero_to_one_hundred/tests/test_ztoh/test_section.py index 0fac370..55b5041 100644 --- a/zero_to_one_hundred/tests/test_ztoh/test_section.py +++ b/zero_to_one_hundred/tests/test_ztoh/test_section.py @@ -96,7 +96,6 @@ def test_gcp_get_format_as_md(get_gcp_config_map, persist_fs, process_fs): def test_asMarkDown(get_config_map, persist_fs, process_fs, http_url_1): actual = Section(get_config_map, persist_fs, process_fs, http_url_1) current = actual.asMarkDown() - assert ( - str_relaxed(current) - == str_relaxed("1. [`here`](./0to100/https§§§cloud.google.com§abc/readme.md) `wip`") + assert str_relaxed(current) == str_relaxed( + "1. [`here`](./0to100/https§§§cloud.google.com§abc/readme.md) `wip`" ) diff --git a/zero_to_one_hundred/tests/test_ztoh/test_ztoh_config_map.py b/zero_to_one_hundred/tests/test_ztoh/test_ztoh_config_map.py index 874016e..54a7b88 100644 --- a/zero_to_one_hundred/tests/test_ztoh/test_ztoh_config_map.py +++ b/zero_to_one_hundred/tests/test_ztoh/test_ztoh_config_map.py @@ -1,6 +1,5 @@ -from typing import List from zero_to_one_hundred.configs.ztoh_config_map import ZTOH_MAP, ZTOHConfigMap - + # pylint: disable=W0621,W0613 @@ -27,12 +26,12 @@ def test_gcp_config_map(get_gcp_config_map: ZTOHConfigMap): assert actual.get_repo_map_md == "toc.md" assert actual.get_legend_type == "gcp" assert actual.get_legend_icons == [ - ZTOHConfigMap.LegendIcons("Quest", ":cyclone:", "quest"), - ZTOHConfigMap.LegendIcons("Lab", ":floppy_disk:", "lab"), - ZTOHConfigMap.LegendIcons("Template", ":whale:", "template"), - ZTOHConfigMap.LegendIcons("Game", ":snake:", "game"), - ZTOHConfigMap.LegendIcons("Course", ":pushpin:", "course") -] + ZTOHConfigMap.LegendIcons("Quest", ":cyclone:", "quest"), + ZTOHConfigMap.LegendIcons("Lab", ":floppy_disk:", "lab"), + ZTOHConfigMap.LegendIcons("Template", ":whale:", "template"), + ZTOHConfigMap.LegendIcons("Game", ":snake:", "game"), + ZTOHConfigMap.LegendIcons("Course", ":pushpin:", "course"), + ] def test_datacamp_config_map(get_datacamp_config_map: ZTOHConfigMap): @@ -42,10 +41,10 @@ def test_datacamp_config_map(get_datacamp_config_map: ZTOHConfigMap): assert actual.get_repo_map_md == "toc.md" assert actual.get_legend_type == "datacamp" assert actual.get_legend_icons == [ - ZTOHConfigMap.LegendIcons("Project", ":cyclone:", "project"), - ZTOHConfigMap.LegendIcons("Tutorial", ":floppy_disk:", "tutorial"), - ZTOHConfigMap.LegendIcons("Course", ":whale:", "course") -] + ZTOHConfigMap.LegendIcons("Project", ":cyclone:", "project"), + ZTOHConfigMap.LegendIcons("Tutorial", ":floppy_disk:", "tutorial"), + ZTOHConfigMap.LegendIcons("Course", ":whale:", "course"), + ] def test_unsupported_config_map(get_unsupported_config_map: ZTOHConfigMap):