FIXUP: Factor out git_root

This commit is contained in:
Alex Pyrgiotis 2024-10-09 20:03:44 +03:00
parent e690b2503f
commit 6a5b6e4249
No known key found for this signature in database
GPG key ID: B6C15EBA0357C9AA
4 changed files with 21 additions and 36 deletions

14
dev_scripts/dev_utils.py Normal file
View file

@ -0,0 +1,14 @@
import pathlib
import subprocess
def git_root():
"""Get the root directory of the Git repo."""
# FIXME: Use a Git Python binding for this.
# FIXME: Make this work if called outside the repo.
path = (
subprocess.check_output(["git", "rev-parse", "--show-toplevel"])
.decode()
.strip("\n")
)
return pathlib.Path(path)

View file

@ -11,6 +11,8 @@ import sys
import urllib.request import urllib.request
from datetime import date from datetime import date
from dev_utils import git_root
DEFAULT_GUI = True DEFAULT_GUI = True
DEFAULT_USER = "user" DEFAULT_USER = "user"
DEFAULT_DRY = False DEFAULT_DRY = False
@ -272,14 +274,6 @@ def run(*args):
).stdout ).stdout
def git_root():
"""Get the root directory of the Git repo."""
# FIXME: Use a Git Python binding for this.
# FIXME: Make this work if called outside the repo.
path = run("git", "rev-parse", "--show-toplevel").decode().strip("\n")
return pathlib.Path(path)
def user_data(): def user_data():
"""Get the user data dir in (which differs on different OSes)""" """Get the user data dir in (which differs on different OSes)"""
home = pathlib.Path.home() home = pathlib.Path.home()

View file

@ -9,6 +9,8 @@ import selectors
import subprocess import subprocess
import sys import sys
from dev_utils import git_root
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
CONTENT_QA = r"""## QA CONTENT_QA = r"""## QA
@ -561,18 +563,7 @@ class QABase(abc.ABC):
self.debug = debug self.debug = debug
self.try_auto = try_auto self.try_auto = try_auto
self.skip_manual = skip_manual self.skip_manual = skip_manual
self.src = ( self.src = git_root()
subprocess.run(
[
"git",
"rev-parse",
"--show-toplevel",
],
stdout=subprocess.PIPE,
)
.stdout.decode()
.strip("\n")
)
def task(*msgs, ref=None, auto=False): def task(*msgs, ref=None, auto=False):
"""Decorator for running a task automatically. """Decorator for running a task automatically.

View file

@ -1,13 +1,12 @@
import hashlib import hashlib
import io import io
import json import json
import pathlib
import re
import subprocess
import sys import sys
import tarfile import tarfile
import urllib.request import urllib.request
from dev_utils import git_root
TESSDATA_RELEASES_URL = ( TESSDATA_RELEASES_URL = (
"https://api.github.com/repos/tesseract-ocr/tessdata_fast/releases/latest" "https://api.github.com/repos/tesseract-ocr/tessdata_fast/releases/latest"
) )
@ -15,19 +14,6 @@ TESSDATA_ARCHIVE_URL = "https://github.com/tesseract-ocr/tessdata_fast/archive/{
TESSDATA_CHECKSUM = "d0e3bb6f3b4e75748680524a1d116f2bfb145618f8ceed55b279d15098a530f9" TESSDATA_CHECKSUM = "d0e3bb6f3b4e75748680524a1d116f2bfb145618f8ceed55b279d15098a530f9"
def git_root():
"""Get the root directory of the Git repo."""
# FIXME: Use a Git Python binding for this.
# FIXME: Make this work if called outside the repo.
cmd = ["git", "rev-parse", "--show-toplevel"]
path = (
subprocess.run(cmd, check=True, stdout=subprocess.PIPE)
.stdout.decode()
.strip("\n")
)
return pathlib.Path(path)
def main(): def main():
share_dir = git_root() / "share" share_dir = git_root() / "share"
tessdata_dir = share_dir / "tessdata" tessdata_dir = share_dir / "tessdata"