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 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

View file

@ -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")

View file

@ -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

View file

@ -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,

View file

@ -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'

View file

@ -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:

View file

@ -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):

View file

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

View file

@ -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
} }

View file

@ -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

View file

@ -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,

View file

@ -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:

View file

@ -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

View file

@ -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 *

View file

@ -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

View file

@ -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:

View file

@ -1,4 +1,3 @@
import os
import logging import logging
formatter = logging.Formatter("[{name}] [{levelname}] {message}", style="{") 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.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

View file

@ -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
View file

@ -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