refactor building files into subfolder
This commit is contained in:
parent
b4a4161026
commit
4a9f1f3b25
11 changed files with 101 additions and 73 deletions
2
PyTeX
2
PyTeX
|
@ -1 +1 @@
|
||||||
Subproject commit a1bb182eec81012fac4897c048c628edbff6b4a3
|
Subproject commit 05f53a917113648a81ab96f353800d64dd9e6ec9
|
65
build.py
65
build.py
|
@ -1,61 +1,8 @@
|
||||||
from pathlib import *
|
from build_scripts.build import build
|
||||||
from datetime import *
|
from pathlib import Path
|
||||||
import git
|
|
||||||
import PyTeX
|
|
||||||
from git_version import git_describe, get_latest_commit
|
|
||||||
|
|
||||||
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()
|
|
||||||
repo_description = git_describe(get_latest_commit(repo))
|
|
||||||
pytex_repo = repo.submodule('PyTeX').module()
|
|
||||||
pytex_repo_description = git_describe(get_latest_commit(pytex_repo))
|
|
||||||
return list(map(lambda line: line.format(
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
def build(build_dir: str):
|
|
||||||
input_root = Path('./src').resolve()
|
|
||||||
output = input_root / build_dir
|
|
||||||
print('[PyTeX] Getting git repository information...')
|
|
||||||
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())
|
|
||||||
if git.Repo().is_dirty(untracked_files=True):
|
|
||||||
extra_header += ['WARNING: Local changes to git repository detected.',
|
|
||||||
' The build will not be reproducible (!)']
|
|
||||||
num_packages = 0
|
|
||||||
num_classes = 0
|
|
||||||
for file in input_root.rglob('*.pysty'):
|
|
||||||
num_packages += 1
|
|
||||||
formatter = PyTeX.PackageFormatter(
|
|
||||||
package_name=file.with_suffix('').name,
|
|
||||||
extra_header=extra_header)
|
|
||||||
print('[PyTeX] Writing file {}'.format(formatter.file_name))
|
|
||||||
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 = PyTeX.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}/')
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
build('build')
|
build(
|
||||||
|
src_dir=Path('./src').resolve(),
|
||||||
|
build_dir=Path('./build').resolve()
|
||||||
|
)
|
||||||
|
|
0
build_scripts/__init__.py
Normal file
0
build_scripts/__init__.py
Normal file
5
build_scripts/build/__init__.py
Normal file
5
build_scripts/build/__init__.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from .build import build
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'build'
|
||||||
|
]
|
38
build_scripts/build/build.py
Normal file
38
build_scripts/build/build.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
from pathlib import Path
|
||||||
|
import git
|
||||||
|
|
||||||
|
import PyTeX
|
||||||
|
|
||||||
|
from build_scripts.git_hook.git_version import get_latest_commit
|
||||||
|
|
||||||
|
from .build_information import build_information
|
||||||
|
|
||||||
|
|
||||||
|
def build(src_dir: Path, build_dir: Path):
|
||||||
|
print('[PyTeX] Getting git repository information...')
|
||||||
|
extra_header, repo_description = build_information()
|
||||||
|
print('[PyTeX] Building version {version} of LatexPackages'.format(version=repo_description))
|
||||||
|
print('[PyTeX] Latest commit message: ' + get_latest_commit(git.Repo()).message.strip())
|
||||||
|
if git.Repo().is_dirty(untracked_files=True):
|
||||||
|
extra_header += ['WARNING: Local changes to git repository detected.',
|
||||||
|
' The build will not be reproducible (!)']
|
||||||
|
num_packages = 0
|
||||||
|
num_classes = 0
|
||||||
|
|
||||||
|
for file in src_dir.rglob('*.pysty'):
|
||||||
|
num_packages += 1
|
||||||
|
formatter = PyTeX.PackageFormatter(
|
||||||
|
package_name=file.with_suffix('').name,
|
||||||
|
extra_header=extra_header)
|
||||||
|
print('[PyTeX] Writing file {}'.format(formatter.file_name))
|
||||||
|
formatter.make_default_macros()
|
||||||
|
formatter.format_file(file, build_dir / str(file.parent.relative_to(src_dir)))
|
||||||
|
for file in src_dir.rglob('*.pycls'):
|
||||||
|
num_classes += 1
|
||||||
|
formatter = PyTeX.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, build_dir / str(file.parent.relative_to(src_dir)))
|
||||||
|
print(f'[PyTeX] Successfully built {num_packages} packages and {num_classes} classes in {build_dir}/')
|
20
build_scripts/build/build_information.py
Normal file
20
build_scripts/build/build_information.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import git
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
from build_scripts.git_hook import git_describe, get_latest_commit
|
||||||
|
|
||||||
|
from .config import BUILD_DETAILS
|
||||||
|
|
||||||
|
|
||||||
|
def build_information():
|
||||||
|
repo = git.Repo()
|
||||||
|
repo_description = git_describe(get_latest_commit(repo))
|
||||||
|
pytex_repo = repo.submodule('PyTeX').module()
|
||||||
|
pytex_repo_description = git_describe(get_latest_commit(pytex_repo))
|
||||||
|
return list(map(lambda line: line.format(
|
||||||
|
build_time=datetime.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
|
6
build_scripts/build/config.py
Normal file
6
build_scripts/build/config.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
BUILD_DETAILS = [
|
||||||
|
"Build details:",
|
||||||
|
" Build time: {build_time}",
|
||||||
|
" PyTeX version: {pytex_version} (commit {pytex_commit_hash})",
|
||||||
|
" LatexPackages version: {packages_version} (commit {packages_commit_hash})"
|
||||||
|
]
|
7
build_scripts/git_hook/__init__.py
Normal file
7
build_scripts/git_hook/__init__.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
from .git_version import git_describe, get_history, get_latest_commit
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'git_describe',
|
||||||
|
'get_history',
|
||||||
|
'get_latest_commit'
|
||||||
|
]
|
|
@ -1,6 +1,5 @@
|
||||||
import git
|
import git
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
def get_latest_commit(repo):
|
def get_latest_commit(repo):
|
||||||
|
@ -10,18 +9,6 @@ def get_latest_commit(repo):
|
||||||
return repo.head.ref.commit
|
return repo.head.ref.commit
|
||||||
|
|
||||||
|
|
||||||
def get_deploy_message():
|
|
||||||
repo = git.Repo()
|
|
||||||
old_msg = get_latest_commit(repo).message
|
|
||||||
return "{old_msg}\n" \
|
|
||||||
"\n" \
|
|
||||||
"Build branch {branch} ({hexsha}) from {repo_name}" \
|
|
||||||
.format(old_msg=old_msg,
|
|
||||||
branch=os.environ['TRAVIS_BRANCH'],
|
|
||||||
hexsha=get_latest_commit(repo).hexsha[0:7],
|
|
||||||
repo_name='kesslermaximilian/LatexPackages')
|
|
||||||
|
|
||||||
|
|
||||||
def get_history(commit: git.objects.commit.Commit, priority=0, depth=0) -> Dict:
|
def get_history(commit: git.objects.commit.Commit, priority=0, depth=0) -> Dict:
|
||||||
commit_history = {commit.hexsha: {
|
commit_history = {commit.hexsha: {
|
||||||
'priority': priority,
|
'priority': priority,
|
5
build_scripts/travis/__init__.py
Normal file
5
build_scripts/travis/__init__.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from .deploy_message import get_deploy_message
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'get_deploy_message'
|
||||||
|
]
|
13
build_scripts/travis/deploy_message.py
Normal file
13
build_scripts/travis/deploy_message.py
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import os
|
||||||
|
from build_scripts.git_hook import get_latest_commit
|
||||||
|
|
||||||
|
|
||||||
|
def get_deploy_message(repo):
|
||||||
|
old_msg = get_latest_commit(repo).message
|
||||||
|
return "{old_msg}\n" \
|
||||||
|
"\n" \
|
||||||
|
"Build branch {branch} ({hexsha}) from {repo_name}" \
|
||||||
|
.format(old_msg=old_msg,
|
||||||
|
branch=os.environ['TRAVIS_BRANCH'],
|
||||||
|
hexsha=get_latest_commit(repo).hexsha[0:7],
|
||||||
|
repo_name='kesslermaximilian/LatexPackages')
|
Loading…
Reference in a new issue