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

Fixes run_container with installed scripts. #214

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions docker/src/lodocker/run_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class RunContainer:
def __init__(self):
self.shared_doc_dir = "parts"
self.git_root = Path(__file__).resolve().parents[3]
if not Path(self.git_root, '.git').is_dir():
self.git_root = Path(__file__).resolve().parents[5]
Copy link
Collaborator

@hakonhagland hakonhagland Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need a more general approach: What if the user installs the scripts globally instead of inside a venv?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

diff --git a/docker/src/lodocker/run_container.py b/docker/src/lodocker/run_container.py
index 0a71583..1a510b0 100644
--- a/docker/src/lodocker/run_container.py
+++ b/docker/src/lodocker/run_container.py
@@ -14,7 +14,7 @@ from lodocker.helpers import Helpers
 class RunContainer:
     def __init__(self):
         self.shared_doc_dir = "parts"
-        self.git_root = Path(__file__).resolve().parents[3]
+        self.git_root = self.find_git_root()
         logging.info(f"git_root: {self.git_root}")
         self.document_dir = self.git_root / self.shared_doc_dir
         # The home directory of the user in the Docker container
@@ -29,6 +29,20 @@ class RunContainer:
     def doc_mount_string(self) -> str:
         return f"{self.document_dir}:{self.docker_home}/{self.shared_doc_dir}"
 
+    def find_git_root(self) -> Path:
+        # First check if environment variable OPM_REFERENCE_MANUAL_ROOT is set
+        if git_root := os.getenv("OPM_REFERENCE_MANUAL_ROOT"):
+            return Path(git_root)
+        # Assume we are inside the git repository when running this script
+        # Search in the parent directories for the .git directory that also contains
+        # a "parts" directory with a main.fodt file inside it
+        cur_dir = Path.cwd()
+        while cur_dir != "/":
+            if (Path(".git").exists() and Path("parts").exists() and Path("parts/main.fodt").exists()):
+                return Path(cur_dir)
+            cur_dir = cur_dir.parent
+        raise ValueError("Could not find the root of the git repository.")
+
     def font_mount_string(self) -> str:
         return f"{self.font_dir}:{self.docker_font_dir}:ro"

logging.info(f"git_root: {self.git_root}")
self.document_dir = self.git_root / self.shared_doc_dir
# The home directory of the user in the Docker container
Expand Down