latexgit.repository package
Interaction with repository.latexgit.repository.fix_path module
A tool for fixing all occurrences of a Path.
- latexgit.repository.fix_path.BASE_PATH_REPLACEMENT: Final[str] = '{...}'
the replacement string for base paths
- latexgit.repository.fix_path.replace_base_path(orig, base_path)[source]
Replace all occurrences of the base_path in the original string.
Any reasonably delimited occurrence of base_path as well as any sub-path under base_path that points to an existing file or directory are replaced with relativizations starting with {…}.
- Parameters:
- Return type:
str
- Returns:
the fixed string
>>> from pycommons.io.temp import temp_dir
>>> with temp_dir() as td:
... td.resolve_inside("x").ensure_dir_exists()
... td.resolve_inside("x/y").write_all_str("5")
... a = replace_base_path(f"blablabla {td}/x ", td)
... b = replace_base_path(f"{td}/x/y", td)
... c = replace_base_path(f"{td}/x.", td)
... d = replace_base_path("\n".join(("blaa", f"{td}/x.x", "y")), td)
... e = replace_base_path("\n".join(("blaa", f"{td}/x.", "y")), td)
... f = replace_base_path(f"xc'{td}/x/y'yy", td)
... g = replace_base_path(td, td)
... h = replace_base_path(td + "/", td)
>>> a
'blablabla {...}/x '
>>> e
'blaa\n{...}/x.\ny'
latexgit.repository.git module
Tools for interacting with repository.
- class latexgit.repository.git.GitRepository(path, url, commit, date_time)[source]
Bases: object
An immutable record of a repository repository.
- commit:
str
the commit
- date_time:
str
the date and time
- static download(url, dest_dir)[source]
Download a git repository.
- Parameters:
- Return type:
GitRepository
- Returns:
the repository information
- static from_local(path, url=None)[source]
Load all the information from a local repository.
- Parameters:
- Return type:
GitRepository
- Returns:
the repository information
- get_base_url()[source]
Get the base url of this git repository.
- Return type:
str
- Returns:
the base url of this git repository
- get_name()[source]
Get the name of this git repository in the form ‘user/name’.
- Return type:
str
- Returns:
the name of this git repository in the form ‘user/name’.
- make_url(relative_path)[source]
Make an url relative to this git repository.
- Parameters:
relative_path (str
) – the relative path
- Return type:
URL
- Returns:
the url
- path:
Path
the repository path
- url:
URL
the repository url
- latexgit.repository.git.git()[source]
Get the path to the git executable.
- Return type:
Path
- Returns:
the path to the git executable
latexgit.repository.gitmanager module
A manager for repository repositories.
This class allows to maintain a local stash of repository repositories that can consistently be accessed without loading any repository multiple times.
- class latexgit.repository.gitmanager.GitManager(base_dir)[source]
Bases: object
A git repository manager can provide a set of git repositories.
- base_dir:
Final
[Path
] the base directory of the repository manager
- get_file_and_url(repo_url, relative_path)[source]
Get a path to a file from the given git repository and also the URL.
- Parameters:
- Return type:
tuple
[Path
, URL
]
- Returns:
a tuple of file and URL
- get_repo(url)[source]
Get the git repository for the given URL.
- Parameters:
url (str
) – the URL to load
- Return type:
GitRepository
- Returns:
the repository
- is_git_repo_path(path)[source]
Check if the given path identifies a directory inside a repository.
- Parameters:
path (Path
| None
) – the path
- Return type:
bool
- Returns:
True if path identifies a directory located in a repository.
latexgit.repository.processed module
A post-processed representation of repository files.
- class latexgit.repository.processed.Processed(base_dir)[source]
Bases: AbstractContextManager
A manager for processed files.
- base_path:
Final
[Path
] the base path of the processor
- close()[source]
Close the processed repository and write cache list.
- Return type:
None
- get_file_and_url(repo_url, relative_path, processor=())[source]
Get a specified, potentially pre-processed file.
- Parameters:
repo_url (str
) – the repository url
relative_path (str
) – the relative path of the file
processor (Optional
[Iterable
[str
]], default: ()
) – the pre-processor commands
- Return type:
tuple
[Path
, URL
]
- Returns:
the file and the url into the git repository of the original
- get_output(command, repo_url=None, relative_dir=None)[source]
Get the output of a certain command.
- Parameters:
command (Union
[str
, Iterable
[str
]]) – the command itself
repo_url (str
| None
, default: None
) – the optional repository URL
relative_dir (str
| None
, default: None
) – the optional directory inside the repository where the command should be executed
- Return type:
tuple
[Path
, URL
| None
]
- Returns:
the path to the output and the url of the git repository, if any