Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing link in Designer documentation #1222

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 19 additions & 21 deletions tools/_setup_generation/step_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


class ContributorsStep(SetupStep):

def __init__(self):
self.GH_TOKEN = os.getenv("GITHUB_TOKEN", None)
self.BASE_URL = "https://api.github.com"
Expand Down Expand Up @@ -49,33 +48,33 @@ def setup(self, setup: Setup) -> None:
def get_repo_urls(self):
response = self.__get(self.REPOS)
if response.status_code != 200:
print(f"WARNING - Couldn't get repositories. response.status_code: {response.status_code}", flush=True)
#print(f"WARNING - Couldn't get repositories. response.status_code: {response.status_code}", flush=True)
return
repos = response.json()
self.REPO_URLS = list(map(lambda _: _['url'], repos))
self.REPO_URLS = list(map(lambda _: _["url"], repos))

def get_avaiga_members(self):
response = self.__get(self.MEMBERS_URL, with_token=False)
response = self.__get(self.MEMBERS_URL)
if response.status_code != 200:
print(f"WARNING - Couldn't get members. response.status_code: {response.status_code}", flush=True)
#print(f"WARNING - Couldn't get members. response.status_code: {response.status_code}", flush=True)
return
members = response.json()
for member in members:
login = member['login']
login = member["login"]
if login not in self.MEMBERS and login not in self.ANONYMOUS:
self.MEMBERS[login] = {"avatar_url": member['avatar_url'], "html_url": member['html_url']}
self.MEMBERS[login] = {"avatar_url": member["avatar_url"], "html_url": member["html_url"]}

def get_contributors(self):
for url in self.REPO_URLS:
response = self.__get(url + "/contributors")
if response.status_code != 200:
print(f"WARNING - Couldn't get collaborators. response.status_code: {response.status_code}", flush=True)
#print(f"WARNING - Couldn't get contributors. response.status_code: {response.status_code}", flush=True)
return
contributors = response.json()
for contrib in contributors:
login = contrib['login']
login = contrib["login"]
if login not in self.CONTRIBUTORS and login not in self.ANONYMOUS:
self.CONTRIBUTORS[login] = {"avatar_url": contrib['avatar_url'], "html_url": contrib['html_url']}
self.CONTRIBUTORS[login] = {"avatar_url": contrib["avatar_url"], "html_url": contrib["html_url"]}

def build_content(self, *members_pattern_tuples):
pattern_content_tuples = []
Expand All @@ -87,17 +86,19 @@ def build_content(self, *members_pattern_tuples):
random.shuffle(members_list)
for login, member_info in members_list:
if login not in self.ANONYMOUS:
content += f"\n- [<img src='{member_info['avatar_url']}' alt='{login} GitHub avatar' width='20'/>" \
f"{login}]" \
f"({member_info['html_url']})"
content += (
f"\n- [<img src='{member_info['avatar_url']}' alt='{login} GitHub avatar' width='20'/>"
f"{login}]"
f"({member_info['html_url']})"
)
content += "\n"
pattern_content_tuples.append((pattern, content))

self._replace(self.PATH, *pattern_content_tuples)

def _replace(self, path, *pattern_content_tuples):
# Read in the file
with open(path + self.TEMPLATE_SUFFIX, 'r') as file:
with open(path + self.TEMPLATE_SUFFIX, "r") as file:
file_data = file.read()

# Replace the patterns by the contents
Expand All @@ -107,17 +108,14 @@ def _replace(self, path, *pattern_content_tuples):
file_data = file_data.replace(pattern, content)

# Write the file out without the template suffix
with open(path, 'w') as file:
with open(path, "w") as file:
file.write(file_data)

def __get(self, url, with_token=True):
if with_token and self.GH_TOKEN:
headers = {
"Accept": "application/vnd.github+json",
"Authorization": "Bearer "+self.GH_TOKEN
}
# {'Authorization': f'token {self.GH_TOKEN}'}
return requests.get(url, headers=headers)
return requests.get(
url, headers={"Accept": "application/vnd.github+json", "Authorization": "Bearer " + self.GH_TOKEN}
)
else:
return requests.get(url)

Expand Down
12 changes: 6 additions & 6 deletions tools/_setup_generation/step_designer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def get_id(self) -> str:
def get_description(self) -> str:
return "Retrieve the Designer documentation files."

def setup(self, setup: Setup): ...
def setup(self, _: Setup): ...

def enter(self, setup: Setup):
if os.path.exists(os.path.join(setup.docs_dir, DesignerStep.PREFIX)):
self.DESIGNER_PATH = os.path.join(
setup.docs_dir, *DesignerStep.PREFIX.split("/")
)
self.MKDOCS_TMPL = os.path.join(self.DESIGNER_PATH, "mkdocs.yml_template")
if not os.access(self.MKDOCS_TMPL, os.R_OK):
self.MKDOCS_TEMPLATE = os.path.join(self.DESIGNER_PATH, "mkdocs.yml_template")
if not os.access(self.MKDOCS_TEMPLATE, os.R_OK):
raise FileNotFoundError(
f"FATAL - Could not read docs/{DesignerStep.PREFIX}/mkdocs.yml_template"
)
Expand All @@ -46,18 +46,18 @@ def exit(self, setup: Setup):
def _read_mkdocs_template(self) -> str:
lines = []
indentation = 0
with open(self.MKDOCS_TMPL) as file:
with open(self.MKDOCS_TEMPLATE) as file:
collect = False
for line in file:
if line.startswith("nav:"): # Start collecting navigation
collect = True
elif re.match(r"^[\w_]+\s*?:", line): # Stop collecting navigation
if collect:
navigation = StringIO()
for navline in lines:
for nav_line in lines:
# Add each line with indentation removed
navigation.write(" ")
navigation.write(navline[indentation:])
navigation.write(nav_line[indentation:])
navigation.write("\n")
return navigation.getvalue()
elif collect:
Expand Down
19 changes: 7 additions & 12 deletions tools/_setup_generation/step_file_injection.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,19 @@ def get_description(self) -> str:

def setup(self, setup: Setup) -> None:
try:
with open(self.src_path, 'r') as file:
with open(self.src_path, "r", encoding="utf-8") as file:
content = file.read()
self._replace(self.dst_tpl_path, self.pattern, content, self.dst_path)
except Exception as e:
print(f"Error: cannot generate page: {e}")
print(f"ERROR - Cannot generate page: {e}")

@staticmethod
def _replace(in_tpl_file_path, pattern, by, into_file_path):
# Read template file
with open(in_tpl_file_path, 'r') as tpl_file:
from_file_content = tpl_file.read()

with open(in_tpl_file_path, "r", encoding="utf-8") as file:
content = file.read()
# Replace the pattern by the contents
content = from_file_content.replace(pattern, by)

content = content.replace(pattern, by)
# Write the file to_file
with open(into_file_path, 'w') as into_file:
into_file.write(content)

def exit(self, setup: Setup):
pass
with open(into_file_path, "w", encoding="utf-8") as file:
file.write(content)
Loading