Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
obar1 committed Sep 7, 2024
1 parent d752379 commit 77d995f
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 60 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 2 additions & 9 deletions demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"


Expand Down
33 changes: 19 additions & 14 deletions zero_to_one_hundred/configs/a_config_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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)
4 changes: 0 additions & 4 deletions zero_to_one_hundred/configs/ztoh_config_map.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
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

ZTOH_MAP = "ztoh-map"


class ZTOHConfigMap(AConfigMap):


def __init__(self, persist_fs: ZTOHPersistFS):
super().__init__(persist_fs)

Expand All @@ -22,4 +19,3 @@ def get_repo_map_md(self):
@property
def get_repo_sorted(self) -> bool:
return self.load["repo"].get("sorted")

14 changes: 6 additions & 8 deletions zero_to_one_hundred/models/map.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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)}
Expand Down
12 changes: 5 additions & 7 deletions zero_to_one_hundred/models/section.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion zero_to_one_hundred/repository/ztoh_persist_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
5 changes: 2 additions & 3 deletions zero_to_one_hundred/tests/test_ztoh/test_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`"
)
23 changes: 11 additions & 12 deletions zero_to_one_hundred/tests/test_ztoh/test_ztoh_config_map.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit 77d995f

Please sign in to comment.