Fixes run_container with installed scripts. - #214
Open
blattms wants to merge 1 commit into
Open
Conversation
In that case the scripts are installed below venv/lib/python3.?/site-packages and we need to go further up the directory tree.
Collaborator
@blattms Yes, good catch. |
| 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] |
Collaborator
There was a problem hiding this comment.
Maybe we need a more general approach: What if the user installs the scripts globally instead of inside a venv?
Collaborator
There was a problem hiding this comment.
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"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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