2021-10-06 23:10:06 +02:00
|
|
|
from pathlib import *
|
|
|
|
import sys
|
2021-10-07 18:02:11 +02:00
|
|
|
import git
|
|
|
|
from datetime import *
|
2021-10-08 09:17:56 +02:00
|
|
|
|
2021-10-06 23:10:06 +02:00
|
|
|
sys.path.insert(0, 'PyTeX/')
|
|
|
|
|
|
|
|
from package_formatter import PackageFormatter
|
2021-10-08 16:35:32 +02:00
|
|
|
from class_formatter import ClassFormatter
|
2021-10-08 09:17:56 +02:00
|
|
|
from git_version import git_describe, get_latest_commit
|
2021-10-07 18:02:11 +02:00
|
|
|
|
|
|
|
BUILD_DETAILS = [
|
|
|
|
"Build details:",
|
|
|
|
" Build time: {build_time}",
|
|
|
|
" PyTeX version: {pytex_version} (commit {pytex_commit_hash})",
|
|
|
|
" LatexPackages version: {packages_version} (commit {packages_commit_hash})"
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def build_details():
|
|
|
|
repo = git.Repo()
|
2021-10-07 20:25:04 +02:00
|
|
|
repo_description = git_describe(get_latest_commit(repo))
|
2021-10-07 18:02:11 +02:00
|
|
|
pytex_repo = repo.submodule('PyTeX').module()
|
2021-10-07 20:25:04 +02:00
|
|
|
pytex_repo_description = git_describe(get_latest_commit(pytex_repo))
|
2021-10-07 18:02:11 +02:00
|
|
|
return list(map(lambda line: line.format(
|
2021-10-08 09:17:56 +02:00
|
|
|
build_time=datetime.now().strftime('%Y/%m/%d %H:%M'),
|
|
|
|
pytex_version=pytex_repo_description,
|
|
|
|
pytex_commit_hash=get_latest_commit(pytex_repo).hexsha[0:7],
|
|
|
|
packages_version=repo_description,
|
|
|
|
packages_commit_hash=get_latest_commit(repo).hexsha[0:7]
|
|
|
|
), BUILD_DETAILS)), repo_description
|
2021-10-07 18:02:11 +02:00
|
|
|
|
2021-10-06 23:10:06 +02:00
|
|
|
|
|
|
|
def build(build_dir: str):
|
2021-10-08 16:37:35 +02:00
|
|
|
input_root = Path('./src').resolve()
|
2021-10-06 23:10:06 +02:00
|
|
|
output = input_root / build_dir
|
2021-10-07 18:02:11 +02:00
|
|
|
print('[PyTeX] Getting git repository information...')
|
2021-10-08 09:17:56 +02:00
|
|
|
extra_header, repo_description = build_details()
|
|
|
|
print('[PyTeX] Building version {version} of LatexPackages'.format(version=repo_description))
|
|
|
|
print('[PyTeX] Latest commit message: ' + get_latest_commit(git.Repo()).message.strip())
|
2021-10-07 18:02:11 +02:00
|
|
|
if git.Repo().is_dirty():
|
|
|
|
extra_header += ['WARNING: Local changes to git repository detected.',
|
2021-10-08 09:17:56 +02:00
|
|
|
' The build will not be reproducible (!)']
|
2021-10-08 16:35:32 +02:00
|
|
|
num_packages = 0
|
|
|
|
num_classes = 0
|
2021-10-06 23:10:06 +02:00
|
|
|
for file in input_root.rglob('*.pysty'):
|
2021-10-08 16:35:32 +02:00
|
|
|
num_packages += 1
|
2021-10-07 18:02:11 +02:00
|
|
|
formatter = PackageFormatter(package_name=file.with_suffix('').name, extra_header=extra_header)
|
2021-10-06 23:21:01 +02:00
|
|
|
print('[PyTeX] Writing file {}'.format(formatter.file_name))
|
2021-10-08 16:35:32 +02:00
|
|
|
formatter.make_default_macros()
|
|
|
|
formatter.format_file(file, Path('./').resolve() / build_dir / str(file.parent.relative_to(input_root)))
|
|
|
|
for file in input_root.rglob('*.pycls'):
|
|
|
|
num_classes += 1
|
|
|
|
formatter = ClassFormatter(class_name=file.with_suffix('').name, extra_header=extra_header)
|
|
|
|
print('[PyTeX] Writing class file {}'.format(formatter.file_name))
|
|
|
|
formatter.make_default_macros()
|
|
|
|
formatter.format_file(file, Path('./').resolve() / build_dir / str(file.parent.relative_to(input_root)))
|
|
|
|
print(f'[PyTeX] Successfully built {num_packages} packages and {num_classes} classes in {build_dir}/')
|
2021-10-06 23:10:06 +02:00
|
|
|
|
2021-10-08 09:17:56 +02:00
|
|
|
|
2021-10-06 23:10:06 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
build('build')
|