Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3087 from pypeclub/enhancement/remove_repos_relat…
Browse files Browse the repository at this point in the history
…ed_logic

General: Remove repos related logic
  • Loading branch information
iLLiCiTiT authored Apr 25, 2022
2 parents b9b199c + 9fd2a7b commit 37f348f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 69 deletions.
67 changes: 18 additions & 49 deletions igniter/bootstrap_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,6 @@ class BootstrapRepos:
Attributes:
data_dir (Path): local OpenPype installation directory.
live_repo_dir (Path): path to repos directory if running live,
otherwise `None`.
registry (OpenPypeSettingsRegistry): OpenPype registry object.
zip_filter (list): List of files to exclude from zip
openpype_filter (list): list of top level directories to
Expand All @@ -654,7 +652,7 @@ def __init__(self, progress_callback: Callable = None, message=None):
self.registry = OpenPypeSettingsRegistry()
self.zip_filter = [".pyc", "__pycache__"]
self.openpype_filter = [
"openpype", "repos", "schema", "LICENSE"
"openpype", "schema", "LICENSE"
]
self._message = message

Expand All @@ -667,11 +665,6 @@ def empty_progress(x: int):
progress_callback = empty_progress
self._progress_callback = progress_callback

if getattr(sys, "frozen", False):
self.live_repo_dir = Path(sys.executable).parent / "repos"
else:
self.live_repo_dir = Path(Path(__file__).parent / ".." / "repos")

@staticmethod
def get_version_path_from_list(
version: str, version_list: list) -> Union[Path, None]:
Expand Down Expand Up @@ -736,11 +729,12 @@ def create_version_from_live_code(
# if repo dir is not set, we detect local "live" OpenPype repository
# version and use it as a source. Otherwise repo_dir is user
# entered location.
if not repo_dir:
version = OpenPypeVersion.get_installed_version_str()
repo_dir = self.live_repo_dir
else:
if repo_dir:
version = self.get_version(repo_dir)
else:
installed_version = OpenPypeVersion.get_installed_version()
version = str(installed_version)
repo_dir = installed_version.path

if not version:
self._print("OpenPype not found.", LOG_ERROR)
Expand All @@ -756,7 +750,7 @@ def create_version_from_live_code(
Path(temp_dir) / f"openpype-v{version}.zip"
self._print(f"creating zip: {temp_zip}")

self._create_openpype_zip(temp_zip, repo_dir.parent)
self._create_openpype_zip(temp_zip, repo_dir)
if not os.path.exists(temp_zip):
self._print("make archive failed.", LOG_ERROR)
return None
Expand Down Expand Up @@ -1057,27 +1051,11 @@ def add_paths_from_archive(archive: Path) -> None:
if not archive.is_file() and not archive.exists():
raise ValueError("Archive is not file.")

with ZipFile(archive, "r") as zip_file:
name_list = zip_file.namelist()

roots = []
paths = []
for item in name_list:
if not item.startswith("repos/"):
continue

root = item.split("/")[1]

if root not in roots:
roots.append(root)
paths.append(
f"{archive}{os.path.sep}repos{os.path.sep}{root}")
sys.path.insert(0, paths[-1])

sys.path.insert(0, f"{archive}")
archive_path = str(archive)
sys.path.insert(0, archive_path)
pythonpath = os.getenv("PYTHONPATH", "")
python_paths = pythonpath.split(os.pathsep)
python_paths += paths
python_paths.insert(0, archive_path)

os.environ["PYTHONPATH"] = os.pathsep.join(python_paths)

Expand All @@ -1094,24 +1072,8 @@ def add_paths_from_directory(directory: Path) -> None:
directory (Path): path to directory.
"""
sys.path.insert(0, directory.as_posix())
directory /= "repos"
if not directory.exists() and not directory.is_dir():
return

roots = []
for item in directory.iterdir():
if item.is_dir():
root = item.as_posix()
if root not in roots:
roots.append(root)
sys.path.insert(0, root)

pythonpath = os.getenv("PYTHONPATH", "")
paths = pythonpath.split(os.pathsep)
paths += roots

os.environ["PYTHONPATH"] = os.pathsep.join(paths)
sys.path.insert(0, directory.as_posix())

@staticmethod
def find_openpype_version(version, staging):
Expand Down Expand Up @@ -1437,6 +1399,7 @@ def install_version(self,
# create destination parent directories even if they don't exist.
destination.mkdir(parents=True)

remove_source_file = False
# version is directory
if openpype_version.path.is_dir():
# create zip inside temporary directory.
Expand Down Expand Up @@ -1470,6 +1433,8 @@ def install_version(self,
self._progress_callback(35)
openpype_version.path = self._copy_zip(
openpype_version.path, destination)
# Mark zip to be deleted when done
remove_source_file = True

# extract zip there
self._print("extracting zip to destination ...")
Expand All @@ -1478,6 +1443,10 @@ def install_version(self,
zip_ref.extractall(destination)
self._progress_callback(100)

# Remove zip file copied to local app data
if remove_source_file:
os.remove(openpype_version.path)

return destination

def _copy_zip(self, source: Path, destination: Path) -> Path:
Expand Down
4 changes: 0 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ def validate_thirdparty_binaries():
"README.md"
]

repos_path = openpype_root / "repos"
if repos_path.exists():
include_files.append("repos")

if IS_WINDOWS:
install_requires.extend([
# `pywin32` packages
Expand Down
20 changes: 6 additions & 14 deletions start.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,23 +823,15 @@ def _bootstrap_from_code(use_version, use_staging):
version_path = Path(_openpype_root)
os.environ["OPENPYPE_REPOS_ROOT"] = _openpype_root

repos = []
# Check for "openpype/repos" directory for sumodules
# NOTE: Is not used at this moment but can be re-used in future
repos_dir = os.path.join(_openpype_root, "repos")
if os.path.exists(repos_dir):
for name in os.listdir(repos_dir):
repos.append(os.path.join(repos_dir, name))

# add self to python paths
repos.insert(0, _openpype_root)
for repo in repos:
sys.path.insert(0, repo)
# add self to sys.path of current process
# NOTE: this seems to be duplicate of 'add_paths_from_directory'
sys.path.insert(0, _openpype_root)
# add venv 'site-packages' to PYTHONPATH
python_path = os.getenv("PYTHONPATH", "")
split_paths = python_path.split(os.pathsep)
# Add repos as first in list
split_paths = repos + split_paths
# add self to python paths
split_paths.insert(0, _openpype_root)

# last one should be venv site-packages
# this is slightly convoluted as we can get here from frozen code too
# in case when we are running without any version installed.
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/igniter/test_bootstrap_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ def test_install_live_repos(fix_bootstrap, printer, monkeypatch, pytestconfig):
openpype_version = fix_bootstrap.create_version_from_live_code()
sep = os.path.sep
expected_paths = [
f"{openpype_version.path}{sep}repos{sep}avalon-core",
f"{openpype_version.path}{sep}repos{sep}avalon-unreal-integration",
f"{openpype_version.path}"
]
printer("testing zip creation")
Expand Down

0 comments on commit 37f348f

Please sign in to comment.