diff --git a/tools/_setup_generation/step_contributors.py b/tools/_setup_generation/step_contributors.py index 085bd8ab4..e49d14088 100644 --- a/tools/_setup_generation/step_contributors.py +++ b/tools/_setup_generation/step_contributors.py @@ -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" @@ -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: @@ -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'] @@ -103,9 +102,11 @@ 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- [{login} GitHub avatar" \ - f"{login}]" \ - f"({member_info['html_url']})" + content += ( + f"\n- [{login} GitHub avatar" + f"{login}]" + f"({member_info['html_url']})" + ) content += "\n" pattern_content_tuples.append((pattern, content)) @@ -113,7 +114,7 @@ def build_content(self, *members_pattern_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 @@ -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) diff --git a/tools/_setup_generation/step_designer.py b/tools/_setup_generation/step_designer.py index b37652dbf..c6e76fa62 100644 --- a/tools/_setup_generation/step_designer.py +++ b/tools/_setup_generation/step_designer.py @@ -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" ) @@ -46,7 +46,7 @@ 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 @@ -54,10 +54,10 @@ def _read_mkdocs_template(self) -> str: 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: diff --git a/tools/fetch_source_files.py b/tools/fetch_source_files.py index f62d4004b..7c3d77f8f 100644 --- a/tools/fetch_source_files.py +++ b/tools/fetch_source_files.py @@ -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: @@ -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")