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

Conversation

blattms
Copy link
Member

@blattms blattms commented Mar 18, 2024

In that case the scripts are installed below
venv/lib/python3.?/site-packages and we need to go further up the directory tree.

Closes #213

In that case the scripts are installed below
venv/lib/python3.?/site-packages and we need to go further up the
directory tree.
@hakonhagland
Copy link
Collaborator

In that case the scripts are installed below venv/lib/python3.?/site-packages and we need to go further up the directory tree.

@blattms Yes, good catch.

@@ -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

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"

@blattms blattms requested review from lisajulia and removed request for lisajulia April 12, 2024 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problems with docker scripts
2 participants