Skip to content

Commit

Permalink
refactor(python): Replace os.path with pathlib (#5243)
Browse files Browse the repository at this point in the history
Signed-off-by: Chi-Sheng Liu <[email protected]>
  • Loading branch information
MortalHappiness authored Apr 20, 2024
1 parent 7e99ba4 commit 6f0c274
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
27 changes: 11 additions & 16 deletions docs/_ext/import_projects.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import inspect
import os
import re
import shutil
import subprocess
Expand Down Expand Up @@ -83,27 +82,23 @@ def parse(self):


def update_sys_path_for_flytekit(import_project_config: ImportProjectsConfig):
flytekit_dir = Path(import_project_config.flytekit_api_dir).resolve(strict=True)
flytekit_src_dir = flytekit_dir / "flytekit"
plugins_dir = flytekit_dir / "plugins"

# create flytekit/_version.py file manually
with open(
f"{import_project_config.flytekit_api_dir}/flytekit/_version.py", "w"
) as f:
with (flytekit_src_dir / "_version.py").open("w") as f:
f.write(f'__version__ = "dev"')

# add flytekit to python path
flytekit_dir = os.path.abspath(import_project_config.flytekit_api_dir)
flytekit_src_dir = os.path.abspath(os.path.join(flytekit_dir, "flytekit"))
plugins_dir = os.path.abspath(os.path.join(flytekit_dir, "plugins"))

sys.path.insert(0, flytekit_src_dir)
sys.path.insert(0, flytekit_dir)
sys.path.insert(0, str(flytekit_src_dir))
sys.path.insert(0, str(flytekit_dir))

# add plugins to python path
for possible_plugin_dir in os.listdir(plugins_dir):
dir_path = os.path.abspath((os.path.join(plugins_dir, possible_plugin_dir)))
plugin_path = os.path.abspath(os.path.join(dir_path, "flytekitplugins"))
if os.path.isdir(dir_path) and os.path.exists(plugin_path):
sys.path.insert(0, dir_path)

for possible_plugin_dir in plugins_dir.iterdir():
plugin_path = possible_plugin_dir / "flytekitplugins"
if possible_plugin_dir.is_dir() and plugin_path.exists():
sys.path.insert(0, str(possible_plugin_dir))

def update_html_context(project: Project, tag: str, commit: str, config: Config):
tag_url = "#" if tag == "dev" else f"{project.source}/releases/tag/{tag}"
Expand Down
7 changes: 4 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# documentation root, use pathlib.Path.resolve(strict=True) to make it absolute, like shown here.

import os
from pathlib import Path
import logging
import sys

Expand All @@ -21,8 +22,8 @@
from sphinx.util import logging as sphinx_logging


sys.path.insert(0, os.path.abspath("../"))
sys.path.append(os.path.abspath("./_ext"))
sys.path.insert(0, str(Path("../").resolve(strict=True)))
sys.path.append(str(Path("./_ext").resolve(strict=True)))

sphinx.application.ExtensionError = sphinx.errors.ExtensionError

Expand Down
2 changes: 1 addition & 1 deletion flyteidl/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# documentation root, use pathlib.Path.resolve(strict=True) to make it absolute, like shown here.
#
import os
import re
Expand Down

0 comments on commit 6f0c274

Please sign in to comment.