optimize imports and reformat files
This commit is contained in:
parent
3dfb889728
commit
94b5f28567
24 changed files with 53 additions and 62 deletions
|
@ -1,5 +1,6 @@
|
||||||
from pathlib import Path, PurePath
|
from pathlib import Path, PurePath
|
||||||
from typing import Optional, Dict
|
from typing import Optional, Dict
|
||||||
|
|
||||||
from .constants import *
|
from .constants import *
|
||||||
from ...format.config import Config
|
from ...format.config import Config
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
from typing import Optional
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from PyTeX.build.build import BuildDirConfig
|
from PyTeX.build.build import BuildDirConfig
|
||||||
from PyTeX.build.enums import PyTeXRootDirType
|
from PyTeX.build.enums import PyTeXRootDirType
|
||||||
from ...logger import logger
|
|
||||||
from .pytex_config import PyTeXConfig
|
from .pytex_config import PyTeXConfig
|
||||||
|
from ...logger import logger
|
||||||
|
|
||||||
|
|
||||||
class PyTeXBuilder:
|
class PyTeXBuilder:
|
||||||
|
@ -64,5 +64,3 @@ class PyTeXBuilder:
|
||||||
|
|
||||||
def _build(self):
|
def _build(self):
|
||||||
logger.info("Starting build")
|
logger.info("Starting build")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ from typing import Optional, Dict
|
||||||
|
|
||||||
from PyTeX.build.build import BuildDirConfig
|
from PyTeX.build.build import BuildDirConfig
|
||||||
from PyTeX.format.formatting_config import FormattingConfig
|
from PyTeX.format.formatting_config import FormattingConfig
|
||||||
from ...format.config import Config
|
|
||||||
from .constants import *
|
from .constants import *
|
||||||
|
from ...format.config import Config
|
||||||
|
|
||||||
|
|
||||||
class PyTeXConfig(Config):
|
class PyTeXConfig(Config):
|
||||||
|
@ -96,4 +96,3 @@ class PyTeXConfig(Config):
|
||||||
return FormattingConfig()
|
return FormattingConfig()
|
||||||
else:
|
else:
|
||||||
return self._default_formatting_config
|
return self._default_formatting_config
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ class RelativePath:
|
||||||
"""
|
"""
|
||||||
Represents a path that knows of its corresponding root directory
|
Represents a path that knows of its corresponding root directory
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
root_dir: Path,
|
root_dir: Path,
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PyTeXFileType(Enum):
|
class PyTeXFileType(Enum):
|
||||||
PyTeXSourceFile = 'PyTeXSourceFile'
|
PyTeXSourceFile = 'PyTeXSourceFile'
|
||||||
TeXSourceFile = 'TeXSourceFile'
|
TeXSourceFile = 'TeXSourceFile'
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from typing import Optional, List, Dict, Tuple, Union
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from .enums import PyTeXFileType
|
from typing import Optional, List, Dict, Tuple, Union
|
||||||
from PyTeX.format.formatterif import FormatterIF
|
|
||||||
from PyTeX.build.paths import RelativePath
|
from PyTeX.build.paths import RelativePath
|
||||||
from ...format.enums import TeXType
|
from PyTeX.format.formatterif import FormatterIF
|
||||||
|
from .enums import PyTeXFileType
|
||||||
|
|
||||||
|
|
||||||
class PyTeXSourceFile:
|
class PyTeXSourceFile:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import git
|
|
||||||
from typing import Union, Optional, List
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Union, Optional, List
|
||||||
|
|
||||||
|
import git
|
||||||
|
|
||||||
|
|
||||||
def get_latest_commit(repo):
|
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[
|
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 file: file to check
|
||||||
:param repo: repo that the file belongs to
|
:param repo: repo that the file belongs to
|
||||||
|
|
|
@ -13,10 +13,10 @@ class FileVersionInfo:
|
||||||
|
|
||||||
self._source_repository_version: Optional[GitVersionInfo] = \
|
self._source_repository_version: Optional[GitVersionInfo] = \
|
||||||
GitVersionInfo(dictionary[JSON_REPOSITORY]) if JSON_REPOSITORY in dictionary.keys() \
|
GitVersionInfo(dictionary[JSON_REPOSITORY]) if JSON_REPOSITORY in dictionary.keys() \
|
||||||
else None
|
else None
|
||||||
self._pytex_repository_version: Optional[GitVersionInfo] = \
|
self._pytex_repository_version: Optional[GitVersionInfo] = \
|
||||||
GitVersionInfo(dictionary[JSON_PYTEX]) if JSON_PYTEX in dictionary.keys() \
|
GitVersionInfo(dictionary[JSON_PYTEX]) if JSON_PYTEX in dictionary.keys() \
|
||||||
else None
|
else None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def md5_checksum(self) -> str:
|
def md5_checksum(self) -> str:
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
|
|
||||||
class PyTeXException(Exception):
|
class PyTeXException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -85,7 +85,6 @@ class Config:
|
||||||
|
|
||||||
|
|
||||||
def recursive_merge_dictionaries(dict1: Dict, dict2: Dict) -> Dict:
|
def recursive_merge_dictionaries(dict1: Dict, dict2: Dict) -> Dict:
|
||||||
|
|
||||||
aux1 = {
|
aux1 = {
|
||||||
k: v for k, v in dict1.items() if type(v) == dict
|
k: v for k, v in dict1.items() if type(v) == dict
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
import csv
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Dict, Tuple, Optional
|
from typing import List, Dict, Tuple, Optional
|
||||||
import csv
|
|
||||||
from .pytex_formatter import PyTeXFormatter
|
|
||||||
from .constants import *
|
from .constants import *
|
||||||
|
from .pytex_formatter import PyTeXFormatter
|
||||||
from ..logger import logger
|
from ..logger import logger
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ class DictFormatter(PyTeXFormatter):
|
||||||
dict_name=self._dict_name,
|
dict_name=self._dict_name,
|
||||||
language=language
|
language=language
|
||||||
)
|
)
|
||||||
lines += ['\n']*2
|
lines += ['\n'] * 2
|
||||||
for key in self.translations[language].keys():
|
for key in self.translations[language].keys():
|
||||||
if self.translations[language][key].strip() != '':
|
if self.translations[language][key].strip() != '':
|
||||||
lines += r'\providetranslation{{{key}}}{{{translation}}}'.format(
|
lines += r'\providetranslation{{{key}}}{{{translation}}}'.format(
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from typing import List, Optional, Dict, Tuple
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import List, Optional, Dict, Tuple
|
||||||
|
|
||||||
from .config import Config
|
from .config import Config
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ class FormatterIF:
|
||||||
A formatter is bound to a specific input file with some
|
A formatter is bound to a specific input file with some
|
||||||
building configuration.
|
building configuration.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
input_file: Optional[Path] = None,
|
input_file: Optional[Path] = None,
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
from typing import List, Optional, Dict, Union
|
from typing import List, Optional, Dict, Union
|
||||||
|
|
||||||
from .config import Config
|
from .config import Config
|
||||||
|
from .constants import *
|
||||||
from .enums import NamingScheme
|
from .enums import NamingScheme
|
||||||
|
from .enums import TeXType, TeXFlavour
|
||||||
from .generic_text import GenericText
|
from .generic_text import GenericText
|
||||||
from .git_version_info import GitVersionInfo
|
from .git_version_info import GitVersionInfo
|
||||||
from .constants import *
|
|
||||||
from .enums import TeXType, TeXFlavour
|
|
||||||
|
|
||||||
|
|
||||||
class VersionInfo:
|
class VersionInfo:
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Union, List, Optional
|
from typing import Union, List, Optional
|
||||||
|
|
||||||
from ..logger import logger
|
from ..logger import logger
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,10 @@ class GitVersionInfo:
|
||||||
self._commit_hash: str = dictionary[JSON_COMMIT_HASH]
|
self._commit_hash: str = dictionary[JSON_COMMIT_HASH]
|
||||||
self._branch: Optional[str] = \
|
self._branch: Optional[str] = \
|
||||||
dictionary[JSON_BRANCH] if JSON_BRANCH in dictionary.keys() \
|
dictionary[JSON_BRANCH] if JSON_BRANCH in dictionary.keys() \
|
||||||
else None
|
else None
|
||||||
self._version: Optional[str] = \
|
self._version: Optional[str] = \
|
||||||
dictionary[JSON_VERSION] if JSON_VERSION in dictionary.keys() \
|
dictionary[JSON_VERSION] if JSON_VERSION in dictionary.keys() \
|
||||||
else None
|
else None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_dirty(self) -> bool:
|
def is_dirty(self) -> bool:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from typing import List, Union
|
|
||||||
from enum import Enum
|
|
||||||
import re
|
import re
|
||||||
|
from enum import Enum
|
||||||
|
from typing import List, Union
|
||||||
|
|
||||||
from .constants import *
|
from .constants import *
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, List
|
from typing import Optional
|
||||||
from .formatting_config import FormattingConfig
|
|
||||||
|
from .constants import *
|
||||||
from .enums import TeXType, TeXFlavour
|
from .enums import TeXType, TeXFlavour
|
||||||
from .formatterif import FormatterIF
|
from .formatterif import FormatterIF
|
||||||
|
from .formatting_config import FormattingConfig
|
||||||
from .generic_text import GenericText
|
from .generic_text import GenericText
|
||||||
import re
|
|
||||||
from .constants import *
|
|
||||||
from ..logger import logger
|
from ..logger import logger
|
||||||
|
|
||||||
|
|
||||||
|
@ -119,8 +120,8 @@ class PyTeXFormatter(FormatterIF):
|
||||||
def make_header(self, **kwargs) -> str:
|
def make_header(self, **kwargs) -> str:
|
||||||
return '\n'.join(
|
return '\n'.join(
|
||||||
[
|
[
|
||||||
'%'*80,
|
'%' * 80,
|
||||||
self.header.format(**kwargs), # TODO: add standard keywords here
|
self.header.format(**kwargs), # TODO: add standard keywords here
|
||||||
'%'*80
|
'%' * 80
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
from typing import List, TextIO, Optional, Tuple, Dict
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from .pytex_formatter import PyTeXFormatter
|
from typing import List, TextIO, Optional, Tuple, Dict
|
||||||
|
|
||||||
from .macros import Macro
|
from .macros import Macro
|
||||||
|
from .pytex_formatter import PyTeXFormatter
|
||||||
|
|
||||||
|
|
||||||
class LineStream:
|
class LineStream:
|
||||||
|
@ -38,7 +39,7 @@ class LineStream:
|
||||||
self._cached_lines[pos] = line
|
self._cached_lines[pos] = line
|
||||||
|
|
||||||
def reserve_lines(self, num_lines):
|
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._cached_lines.append(
|
||||||
self._handle.readline()
|
self._handle.readline()
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import os
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
formatter = logging.Formatter("[{name}] [{levelname}] {message}", style="{")
|
formatter = logging.Formatter("[{name}] [{levelname}] {message}", style="{")
|
||||||
|
|
|
@ -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.enums import NamingScheme
|
||||||
from PyTeX.format.generic_text import GenericText
|
from PyTeX.format.generic_text import GenericText
|
||||||
from PyTeX.format.git_version_info import GitVersionInfo
|
|
||||||
|
|
||||||
|
|
||||||
def generate_properties(props):
|
def generate_properties(props):
|
||||||
|
@ -60,6 +60,7 @@ if __name__ == "__main__":
|
||||||
)
|
)
|
||||||
print(out2)
|
print(out2)
|
||||||
|
|
||||||
|
|
||||||
def generate_properties(attributes: List[Union[str, Tuple[str, Any]]]):
|
def generate_properties(attributes: List[Union[str, Tuple[str, Any]]]):
|
||||||
attributes = [
|
attributes = [
|
||||||
x if isinstance(x, Tuple) else (x, None) for x in 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 cls
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
|
import os
|
||||||
from pathlib import Path, PurePath, PurePosixPath, PureWindowsPath
|
from pathlib import Path, PurePath, PurePosixPath, PureWindowsPath
|
||||||
|
|
||||||
from PyTeX.build.build import PyTeXBuilder
|
from PyTeX.build.build import PyTeXBuilder
|
||||||
from PyTeX.build.enums.enums import PyTeXRootDirType
|
from PyTeX.build.enums.enums import PyTeXRootDirType
|
||||||
import os
|
|
||||||
|
|
||||||
|
|
||||||
class PyTeXPurePath:
|
class PyTeXPurePath:
|
||||||
|
|
17
main.py
17
main.py
|
@ -1,13 +1,10 @@
|
||||||
from pathlib import Path
|
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.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.build.pytex_config import PyTeXConfig
|
||||||
|
from PyTeX.build.paths import RelativePath
|
||||||
from PyTeX.format.formatting_config import FormattingConfig
|
from PyTeX.format.formatting_config import FormattingConfig
|
||||||
from PyTeX.format.generic_text import GenericText
|
|
||||||
|
|
||||||
spec = BuildDirConfig(
|
spec = BuildDirConfig(
|
||||||
source_root=Path('src'),
|
source_root=Path('src'),
|
||||||
|
@ -21,7 +18,6 @@ builder = PyTeXBuilder(
|
||||||
build_dir_spec=spec
|
build_dir_spec=spec
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
p: RelativePath = RelativePath(Path('src'), 'src/hello/bla')
|
p: RelativePath = RelativePath(Path('src'), 'src/hello/bla')
|
||||||
|
|
||||||
rel = p.relative_path
|
rel = p.relative_path
|
||||||
|
@ -34,7 +30,6 @@ p2 = RelativePath(Path('doc'), 'build/doc/mkessler/hello/bla')
|
||||||
|
|
||||||
p3 = p / p2
|
p3 = p / p2
|
||||||
|
|
||||||
|
|
||||||
p4 = p.with_name('myname')
|
p4 = p.with_name('myname')
|
||||||
|
|
||||||
d1 = {
|
d1 = {
|
||||||
|
@ -49,18 +44,12 @@ d2 = {
|
||||||
|
|
||||||
d3 = d1 | d2
|
d3 = d1 | d2
|
||||||
|
|
||||||
|
|
||||||
config: FormattingConfig = FormattingConfig()
|
config: FormattingConfig = FormattingConfig()
|
||||||
|
|
||||||
|
|
||||||
dump = config.to_json()
|
dump = config.to_json()
|
||||||
|
|
||||||
|
|
||||||
conf_path = Path('/home/maximilian/git/LatexPackages/.pytexrc')
|
conf_path = Path('/home/maximilian/git/LatexPackages/.pytexrc')
|
||||||
|
|
||||||
pytex_config = PyTeXConfig.from_yaml(conf_path)
|
pytex_config = PyTeXConfig.from_yaml(conf_path)
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue