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

Backport 4.0 - Fix missing link in Designer documentation #1223

Merged
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
36 changes: 17 additions & 19 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 @@ -48,21 +47,21 @@ 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:
Expand All @@ -86,7 +85,7 @@ def get_contributors(self):
continue
response = self.__get(url+"/contributors")
if response.status_code != 200:
print(f"WARNING - Couldn't get contributors. response.status_code: {response.status_code}", flush=True)
#print(f"WARNING - Couldn't get contributors. response.status_code: {response.status_code}", flush=True)
continue
for c in response.json():
login = c['login']
Expand All @@ -103,17 +102,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 @@ -123,17 +124,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
50 changes: 38 additions & 12 deletions tools/fetch_source_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,50 @@ def move_files(repo: str, src_path: str):
elif repo == "taipy-designer":
designer_doc_dir = os.path.join(ROOT_DIR, "docs", "userman", "ecosystem", "designer")
safe_rmtree(designer_doc_dir)
src_documentation_dir = os.path.join(src_path, "documentation")
saved_dir = os.getcwd()
os.chdir(saved_dir)
doc_src_dir = os.path.join(src_path, "documentation")
taipy_docs_src_dir = os.path.join(doc_src_dir, "taipy_docs")
tools_src_dir = os.path.join(doc_src_dir, "tools")
shutil.copytree(os.path.join(doc_src_dir, "taipy_docs"), designer_doc_dir)
shutil.copy(
os.path.join(doc_src_dir, "mkdocs_taipy.yml"),
os.path.join(designer_doc_dir, "mkdocs.yml_template"),
)
dest_dir = os.path.join(designer_doc_dir, "designer-examples")
safe_rmtree(dest_dir)
os.mkdir(dest_dir)
subprocess.run(
f"python {os.path.join(src_path, 'copy_examples.py')}",
f"python \"{os.path.join(tools_src_dir, 'zip_examples.py')}\" "
# src_directory
f"\"{taipy_docs_src_dir}\" "
# intermediate_directory
f"\"{dest_dir}\" "
# target_directory
f"\"{designer_doc_dir}\" "
# zip)file
"examples.zip",
shell=True,
capture_output=True,
text=True,
)
os.chdir(saved_dir)
shutil.copytree(os.path.join(src_documentation_dir, "taipy_docs"), designer_doc_dir)
shutil.copy(
os.path.join(src_documentation_dir, "mkdocs_taipy.yml"),
os.path.join(designer_doc_dir, "mkdocs.yml_template"),
safe_rmtree(dest_dir)
dest_dir = os.path.join(designer_doc_dir, "designer-training")
safe_rmtree(dest_dir)
os.mkdir(dest_dir)
subprocess.run(
f"python \"{os.path.join(tools_src_dir, 'zip_examples.py')}\" "
# src_directory
f"\"{os.path.join(taipy_docs_src_dir, 'training')}\" "
# intermediate_directory
f"\"{dest_dir}\" "
# target_directory
f"\"{os.path.join(designer_doc_dir, 'training')}\" "
# zip)file
"training.zip",
shell=True,
capture_output=True,
text=True,
)
safe_rmtree(dest_dir)
else:
try:

Expand Down Expand Up @@ -313,9 +342,6 @@ def copy(item: str, src: str, dst: str, rel_path: str):

finally:
pass
"""
shutil.rmtree(tmp_dir)
"""


frontend_dir = os.path.join(ROOT_DIR, "taipy-fe")
Expand Down