integrate some more options. forward arguments to file formatter
This commit is contained in:
parent
cf3edf33c4
commit
7b277ad8b6
3 changed files with 38 additions and 17 deletions
|
@ -14,21 +14,34 @@ def pytex_msg(msg: str):
|
|||
|
||||
|
||||
class TexFileToFormat:
|
||||
def __init__(self, src_path: Path, build_dir: Path, latex_name: str, build_info: BuildInfo):
|
||||
def __init__(
|
||||
self,
|
||||
src_path: Path,
|
||||
build_dir: Path,
|
||||
latex_name: str,
|
||||
build_info: BuildInfo,
|
||||
allow_dirty: bool = False,
|
||||
overwrite_existing_files: bool = False,
|
||||
build_all: bool = False):
|
||||
self.src_path = src_path
|
||||
self.build_path = build_dir
|
||||
self.tex_name = latex_name # Still an identifier on how to name the package when being formatted
|
||||
self.build_info = build_info
|
||||
self.allow_dirty = allow_dirty
|
||||
self.overwrite_existing_files: overwrite_existing_files
|
||||
self.build_all = build_all
|
||||
|
||||
def format(self):
|
||||
if '.pysty' in self.src_path.name:
|
||||
formatter = PyTeX.PackageFormatter(
|
||||
package_name=self.src_path.with_suffix('').name,
|
||||
extra_header=self.build_info.header)
|
||||
else:
|
||||
elif '.pycls' in self.src_path.name:
|
||||
formatter = PyTeX.ClassFormatter(
|
||||
class_name=self.src_path.with_suffix('').name,
|
||||
extra_header=self.build_info.header)
|
||||
else:
|
||||
exit(1)
|
||||
pytex_msg('Writing file {}'.format(formatter.file_name))
|
||||
formatter.make_default_macros()
|
||||
formatter.format_file(self.src_path, self.build_path)
|
||||
|
@ -57,7 +70,7 @@ def build(
|
|||
include_license: bool = False, # header
|
||||
include_git_version: bool = False, # header
|
||||
include_pytex_info_text: bool = False, # header
|
||||
use_git: bool = False, # versioning
|
||||
use_git: bool = False, # versioning (not implemented yet)
|
||||
allow_dirty: bool = False, # versioning
|
||||
overwrite_existing_files: bool = False, # output control
|
||||
build_all: bool = False, # output control / versioning
|
||||
|
@ -104,20 +117,23 @@ def build(
|
|||
src_path=file,
|
||||
build_dir=output_dir / file.parent.relative_to(input_dir),
|
||||
latex_name=latex_name,
|
||||
build_info=current_build_info
|
||||
build_info=current_build_info,
|
||||
allow_dirty=allow_dirty,
|
||||
overwrite_existing_files=overwrite_existing_files,
|
||||
build_all=build_all
|
||||
))
|
||||
|
||||
info_dict = {
|
||||
'build_time': '',
|
||||
'LatexPackages': {
|
||||
'source files': {
|
||||
'version': current_build_info.packages_version,
|
||||
'commit': current_build_info.packages_hash,
|
||||
'dirty': False # TODO
|
||||
'dirty': current_build_info.package_repo.is_dirty(untracked_files=True)
|
||||
},
|
||||
'PyTeX': {
|
||||
'pytex': {
|
||||
'version': current_build_info.pytex_version,
|
||||
'commit': current_build_info.pytex_hash,
|
||||
'dirty': False # TODO
|
||||
'dirty': current_build_info.pytex_repo.is_dirty(untracked_files=True)
|
||||
},
|
||||
'tex_sources': [
|
||||
|
||||
|
@ -127,6 +143,8 @@ def build(
|
|||
for source in sources_to_build:
|
||||
info = source.format()
|
||||
info_dict['tex_sources'].append(info)
|
||||
with open(output_dir / 'build_info.json', 'w') as f:
|
||||
json.dump(info_dict, f, indent=4)
|
||||
|
||||
if write_build_information:
|
||||
with open(output_dir / 'build_info.json', 'w') as f:
|
||||
json.dump(info_dict, f, indent=4)
|
||||
pytex_msg('Build done')
|
||||
|
|
|
@ -76,6 +76,14 @@ class BuildInfo:
|
|||
def packages_hash(self):
|
||||
return self._packages_repo_commit.hexsha
|
||||
|
||||
@property
|
||||
def package_repo(self):
|
||||
return self._packages_repo
|
||||
|
||||
@property
|
||||
def pytex_repo(self):
|
||||
return self._pytex_repo
|
||||
|
||||
def get_repo_commits(self):
|
||||
if self._packages_repo:
|
||||
self._packages_repo_commit = get_latest_commit(self._packages_repo)
|
||||
|
|
|
@ -5,21 +5,16 @@ from typing import Union, Optional, List
|
|||
|
||||
|
||||
def is_recent(file, repo, compare: Optional[Union[git.Commit, List[git.Commit]]] = None) -> Optional[bool]:
|
||||
modified_files = [item.a_path for item in repo.index.diff(None)]
|
||||
if file in modified_files:
|
||||
return True
|
||||
|
||||
newly_committed_files = []
|
||||
if type(compare) == git.Commit:
|
||||
newly_committed_files = [item.a_path for item in repo.index.diff(compare)]
|
||||
elif type is None:
|
||||
newly_committed_files = [item.a_path for item in repo.index.diff(None)]
|
||||
elif type(compare) == list:
|
||||
for commit in compare:
|
||||
for item in repo.index.diff(commit):
|
||||
newly_committed_files.append(item.a_path)
|
||||
elif type is None:
|
||||
for parent in get_latest_commit(repo).parents:
|
||||
for item in repo.index.diff(parent):
|
||||
newly_committed_files.append(item.a_path)
|
||||
else:
|
||||
print("Invalid argument type for compare")
|
||||
return None
|
||||
|
|
Loading…
Reference in a new issue