optimize imports and reformat files

This commit is contained in:
Maximilian Keßler 2022-02-07 18:36:30 +01:00
parent 3dfb889728
commit 94b5f28567
24 changed files with 53 additions and 62 deletions

View file

@ -1,5 +1,6 @@
from pathlib import Path, PurePath
from typing import Optional, Dict
from .constants import *
from ...format.config import Config

View file

@ -1,10 +1,10 @@
from typing import Optional
from pathlib import Path
from typing import Optional
from PyTeX.build.build import BuildDirConfig
from PyTeX.build.enums import PyTeXRootDirType
from ...logger import logger
from .pytex_config import PyTeXConfig
from ...logger import logger
class PyTeXBuilder:
@ -64,5 +64,3 @@ class PyTeXBuilder:
def _build(self):
logger.info("Starting build")

View file

@ -2,8 +2,8 @@ from typing import Optional, Dict
from PyTeX.build.build import BuildDirConfig
from PyTeX.format.formatting_config import FormattingConfig
from ...format.config import Config
from .constants import *
from ...format.config import Config
class PyTeXConfig(Config):
@ -96,4 +96,3 @@ class PyTeXConfig(Config):
return FormattingConfig()
else:
return self._default_formatting_config

View file

@ -1 +1 @@
from .enums import *
from .enums import *

View file

@ -7,6 +7,7 @@ class RelativePath:
"""
Represents a path that knows of its corresponding root directory
"""
def __init__(
self,
root_dir: Path,

View file

@ -1,8 +1,6 @@
from enum import Enum
class PyTeXFileType(Enum):
PyTeXSourceFile = 'PyTeXSourceFile'
TeXSourceFile = 'TeXSourceFile'

View file

@ -1,9 +1,9 @@
from typing import Optional, List, Dict, Tuple, Union
from pathlib import Path
from .enums import PyTeXFileType
from PyTeX.format.formatterif import FormatterIF
from typing import Optional, List, Dict, Tuple, Union
from PyTeX.build.paths import RelativePath
from ...format.enums import TeXType
from PyTeX.format.formatterif import FormatterIF
from .enums import PyTeXFileType
class PyTeXSourceFile:

View file

@ -1,6 +1,7 @@
import git
from typing import Union, Optional, List
from pathlib import Path
from typing import Union, Optional, List
import git
def get_latest_commit(repo):
@ -11,7 +12,7 @@ def get_latest_commit(repo):
def is_recent(file: Path, repo: git.Repo, compare: Optional[Union[git.Commit, List[git.Commit]]] = None) -> Optional[
bool]:
bool]:
"""
:param file: file to check
:param repo: repo that the file belongs to

View file

@ -13,10 +13,10 @@ class FileVersionInfo:
self._source_repository_version: Optional[GitVersionInfo] = \
GitVersionInfo(dictionary[JSON_REPOSITORY]) if JSON_REPOSITORY in dictionary.keys() \
else None
else None
self._pytex_repository_version: Optional[GitVersionInfo] = \
GitVersionInfo(dictionary[JSON_PYTEX]) if JSON_PYTEX in dictionary.keys() \
else None
else None
@property
def md5_checksum(self) -> str:

View file

@ -1,3 +1,2 @@
class PyTeXException(Exception):
pass

View file

@ -85,7 +85,6 @@ class Config:
def recursive_merge_dictionaries(dict1: Dict, dict2: Dict) -> Dict:
aux1 = {
k: v for k, v in dict1.items() if type(v) == dict
}
@ -95,4 +94,4 @@ def recursive_merge_dictionaries(dict1: Dict, dict2: Dict) -> Dict:
merged = {
k: recursive_merge_dictionaries(v, aux2[k]) for k, v in aux1.items() if k in aux2.keys()
}
return dict1 | dict2 | merged
return dict1 | dict2 | merged

View file

@ -31,4 +31,4 @@ YAML_TEX_TYPE = 'type'
YAML_TEXT = 'text'
YAML_REPO = 'repo'
YAML_PYTEX = 'pytex'
YAML_DOCSTRIP = 'docstrip'
YAML_DOCSTRIP = 'docstrip'

View file

@ -1,8 +1,9 @@
import csv
from pathlib import Path
from typing import List, Dict, Tuple, Optional
import csv
from .pytex_formatter import PyTeXFormatter
from .constants import *
from .pytex_formatter import PyTeXFormatter
from ..logger import logger
@ -58,7 +59,7 @@ class DictFormatter(PyTeXFormatter):
dict_name=self._dict_name,
language=language
)
lines += ['\n']*2
lines += ['\n'] * 2
for key in self.translations[language].keys():
if self.translations[language][key].strip() != '':
lines += r'\providetranslation{{{key}}}{{{translation}}}'.format(

View file

@ -1,5 +1,5 @@
from typing import List, Optional, Dict, Tuple
from pathlib import Path
from typing import List, Optional, Dict, Tuple
from .config import Config
@ -9,6 +9,7 @@ class FormatterIF:
A formatter is bound to a specific input file with some
building configuration.
"""
def __init__(
self,
input_file: Optional[Path] = None,

View file

@ -1,11 +1,11 @@
from typing import List, Optional, Dict, Union
from .config import Config
from .constants import *
from .enums import NamingScheme
from .enums import TeXType, TeXFlavour
from .generic_text import GenericText
from .git_version_info import GitVersionInfo
from .constants import *
from .enums import TeXType, TeXFlavour
class VersionInfo:

View file

@ -1,5 +1,6 @@
from pathlib import Path
from typing import Union, List, Optional
from ..logger import logger

View file

@ -15,10 +15,10 @@ class GitVersionInfo:
self._commit_hash: str = dictionary[JSON_COMMIT_HASH]
self._branch: Optional[str] = \
dictionary[JSON_BRANCH] if JSON_BRANCH in dictionary.keys() \
else None
else None
self._version: Optional[str] = \
dictionary[JSON_VERSION] if JSON_VERSION in dictionary.keys() \
else None
else None
@property
def is_dirty(self) -> bool:
@ -34,4 +34,4 @@ class GitVersionInfo:
@property
def branch(self) -> Optional[str]:
return self._branch
return self._branch

View file

@ -1,6 +1,7 @@
from typing import List, Union
from enum import Enum
import re
from enum import Enum
from typing import List, Union
from .constants import *

View file

@ -1,11 +1,12 @@
import re
from pathlib import Path
from typing import Optional, List
from .formatting_config import FormattingConfig
from typing import Optional
from .constants import *
from .enums import TeXType, TeXFlavour
from .formatterif import FormatterIF
from .formatting_config import FormattingConfig
from .generic_text import GenericText
import re
from .constants import *
from ..logger import logger
@ -119,8 +120,8 @@ class PyTeXFormatter(FormatterIF):
def make_header(self, **kwargs) -> str:
return '\n'.join(
[
'%'*80,
self.header.format(**kwargs), # TODO: add standard keywords here
'%'*80
'%' * 80,
self.header.format(**kwargs), # TODO: add standard keywords here
'%' * 80
]
)

View file

@ -1,7 +1,8 @@
from typing import List, TextIO, Optional, Tuple, Dict
from pathlib import Path
from .pytex_formatter import PyTeXFormatter
from typing import List, TextIO, Optional, Tuple, Dict
from .macros import Macro
from .pytex_formatter import PyTeXFormatter
class LineStream:
@ -38,7 +39,7 @@ class LineStream:
self._cached_lines[pos] = line
def reserve_lines(self, num_lines):
for i in range(0, num_lines - len(self._cached_lines) -1):
for i in range(0, num_lines - len(self._cached_lines) - 1):
self._cached_lines.append(
self._handle.readline()
)

View file

@ -1,4 +1,3 @@
import os
import logging
formatter = logging.Formatter("[{name}] [{levelname}] {message}", style="{")

View file

@ -1,7 +1,7 @@
from typing import Tuple, Union, List, Any, Optional
from typing import Tuple, Union, List, Any
from PyTeX.format.enums import NamingScheme
from PyTeX.format.generic_text import GenericText
from PyTeX.format.git_version_info import GitVersionInfo
def generate_properties(props):
@ -60,6 +60,7 @@ if __name__ == "__main__":
)
print(out2)
def generate_properties(attributes: List[Union[str, Tuple[str, Any]]]):
attributes = [
x if isinstance(x, Tuple) else (x, None) for x in attributes
@ -78,4 +79,3 @@ def generate_properties(attributes: List[Union[str, Tuple[str, Any]]]):
return cls
return decorator

View file

@ -1,7 +1,8 @@
import os
from pathlib import Path, PurePath, PurePosixPath, PureWindowsPath
from PyTeX.build.build import PyTeXBuilder
from PyTeX.build.enums.enums import PyTeXRootDirType
import os
class PyTeXPurePath:

17
main.py
View file

@ -1,13 +1,10 @@
from pathlib import Path
from PyTeX.build.build import PyTeXBuilder, BuildDirConfig
from PyTeX.build.build import PyTeXBuilder
from PyTeX.build.build.build_dir_spec import BuildDirConfig
from PyTeX.build.enums import *
from PyTeX.build.paths import RelativePath
from PyTeX.build.build.pytex_config import PyTeXConfig
from PyTeX.build.paths import RelativePath
from PyTeX.format.formatting_config import FormattingConfig
from PyTeX.format.generic_text import GenericText
spec = BuildDirConfig(
source_root=Path('src'),
@ -21,7 +18,6 @@ builder = PyTeXBuilder(
build_dir_spec=spec
)
p: RelativePath = RelativePath(Path('src'), 'src/hello/bla')
rel = p.relative_path
@ -34,7 +30,6 @@ p2 = RelativePath(Path('doc'), 'build/doc/mkessler/hello/bla')
p3 = p / p2
p4 = p.with_name('myname')
d1 = {
@ -49,18 +44,12 @@ d2 = {
d3 = d1 | d2
config: FormattingConfig = FormattingConfig()
dump = config.to_json()
conf_path = Path('/home/maximilian/git/LatexPackages/.pytexrc')
pytex_config = PyTeXConfig.from_yaml(conf_path)
pass