Skip to content
Snippets Groups Projects
Commit 9643723a authored by Andreas Bolin's avatar Andreas Bolin
Browse files

typos in compiler and better version

parent dafadf21
No related branches found
No related tags found
No related merge requests found
Pipeline #74915 passed
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
Graphical user interface for B-ASIC scheduler. Graphical user interface for B-ASIC scheduler.
""" """
__author__ = 'Andreas Bolin'
# __all__ = ['main_window', 'graphics_graph', 'component_item', 'graphics_axes', 'graphics_timeline_item']
from b_asic.scheduler_gui._version import *
from b_asic.scheduler_gui.graphics_axes_item import * from b_asic.scheduler_gui.graphics_axes_item import *
from b_asic.scheduler_gui.graphics_component_item import * from b_asic.scheduler_gui.graphics_component_item import *
from b_asic.scheduler_gui.graphics_graph_event import * from b_asic.scheduler_gui.graphics_graph_event import *
...@@ -11,7 +15,3 @@ from b_asic.scheduler_gui.graphics_signal import * ...@@ -11,7 +15,3 @@ from b_asic.scheduler_gui.graphics_signal import *
from b_asic.scheduler_gui.graphics_timeline_item import * from b_asic.scheduler_gui.graphics_timeline_item import *
from b_asic.scheduler_gui.logger import * from b_asic.scheduler_gui.logger import *
from b_asic.scheduler_gui.main_window import * from b_asic.scheduler_gui.main_window import *
# __all__ = ['main_window', 'graphics_graph', 'component_item', 'graphics_axes', 'graphics_timeline_item']
__version__ = "0.1"
__author__ = "Andreas Bolin"
__version_info__ = ('0', '1')
__version__ = '.'.join(__version_info__)
...@@ -7,13 +7,13 @@ If no arguments is given, the compiler search for and compiles all form (.ui) ...@@ -7,13 +7,13 @@ If no arguments is given, the compiler search for and compiles all form (.ui)
files. files.
""" """
from qtpy import uic, API from qtpy import uic
import sys import sys
import os import os
import shutil import shutil
import subprocess import subprocess
import argparse import argparse
import b_asic.scheduler_gui from b_asic.scheduler_gui._version import __version__
import b_asic.scheduler_gui.logger as logger import b_asic.scheduler_gui.logger as logger
log = logger.getLogger() log = logger.getLogger()
...@@ -21,7 +21,7 @@ sys.excepthook = logger.handle_exceptions ...@@ -21,7 +21,7 @@ sys.excepthook = logger.handle_exceptions
def _check_filenames(*filenames: str) -> None: def _check_filenames(*filenames: str) -> None:
"""Check if the filename(s) exist and if not, raise 'FileNotFoundError' """Check if the filename(s) exist, otherwise raise FileNotFoundError
exception.""" exception."""
for filename in filenames: for filename in filenames:
if not os.path.exists(filename): if not os.path.exists(filename):
...@@ -29,7 +29,8 @@ def _check_filenames(*filenames: str) -> None: ...@@ -29,7 +29,8 @@ def _check_filenames(*filenames: str) -> None:
def _check_qt_version() -> None: def _check_qt_version() -> None:
"""Checks if PySide2 or PyQt5 is installed, raises AssertionError otherwise.""" """Check if PySide2 or PyQt5 is installed, otherwise raise AssertionError
exception."""
assert uic.PYSIDE2 or uic.PYQT5, 'PySide2 or PyQt5 need to be installed' assert uic.PYSIDE2 or uic.PYQT5, 'PySide2 or PyQt5 need to be installed'
...@@ -45,16 +46,14 @@ def replace_qt_bindings(filename: str) -> None: ...@@ -45,16 +46,14 @@ def replace_qt_bindings(filename: str) -> None:
def compile_rc(*filenames: str) -> None: def compile_rc(*filenames: str) -> None:
"""Compile resource file(s) given by 'filenames'. If no arguments are given, """Compile resource file(s) given by 'filenames'. If no arguments are given,
the compiler will search for '*.qrc' files in 'icons\' folder and compile the compiler will search for resource (.qrc) files and compile accordingly."""
accordingly."""
_check_qt_version() _check_qt_version()
def compile(filename: str = None) -> None: def compile(filename: str = None) -> None:
outfile = f'{os.path.splitext(filename)[0]}_rc.py' outfile = f'{os.path.splitext(filename)[0]}_rc.py'
os_ = sys.platform
rcc = shutil.which('pyside2-rcc') rcc = shutil.which('pyside2-rcc')
args = f'-g python -o {outfile} {filename}' args = f'-g python -o {outfile} {filename}'
if rcc is None: if rcc is None:
rcc = shutil.which('rcc') rcc = shutil.which('rcc')
if rcc is None: if rcc is None:
...@@ -62,6 +61,7 @@ def compile_rc(*filenames: str) -> None: ...@@ -62,6 +61,7 @@ def compile_rc(*filenames: str) -> None:
args = f'-o {outfile} {filename}' args = f'-o {outfile} {filename}'
assert rcc, "PySide2 compiler failed, can't find rcc" assert rcc, "PySide2 compiler failed, can't find rcc"
os_ = sys.platform
if os_.startswith("linux"): # Linux if os_.startswith("linux"): # Linux
cmd = f'{rcc} {args}' cmd = f'{rcc} {args}'
subprocess.call(cmd.split()) subprocess.call(cmd.split())
...@@ -84,7 +84,7 @@ def compile_rc(*filenames: str) -> None: ...@@ -84,7 +84,7 @@ def compile_rc(*filenames: str) -> None:
if not filenames: if not filenames:
rc_files = [os.path.join(root, name) rc_files = [os.path.join(root, name)
for root, dirs, files in os.walk('.') for root, _, files in os.walk('.')
for name in files for name in files
if name.endswith(('.qrc'))] if name.endswith(('.qrc'))]
...@@ -98,21 +98,20 @@ def compile_rc(*filenames: str) -> None: ...@@ -98,21 +98,20 @@ def compile_rc(*filenames: str) -> None:
def compile_ui(*filenames: str) -> None: def compile_ui(*filenames: str) -> None:
"""Compile form file(s) given by 'filenames'. If no arguments are given, """Compile form file(s) given by 'filenames'. If no arguments are given, the
the compiler will search for '*.ui' files and compile accordingly.""" compiler will search for form (.ui) files and compile accordingly."""
_check_qt_version() _check_qt_version()
def compile(filename: str) -> None: def compile(filename: str) -> None:
dir, file = os.path.split(filename) dir, file = os.path.split(filename)
file, _ = os.path.splitext(file) file = os.path.splitext(file)[0]
dir = dir if dir else '.' dir = dir if dir else '.'
outfile = f'{dir}/ui_{file}.py' outfile = f'{dir}/ui_{file}.py'
if uic.PYSIDE2: if uic.PYSIDE2:
os_ = sys.platform
uic_ = shutil.which('pyside2-uic') uic_ = shutil.which('pyside2-uic')
args = f'-g python -o {outfile} {filename}' args = f'-g python -o {outfile} {filename}'
if uic_ is None: if uic_ is None:
uic_ = shutil.which('uic') uic_ = shutil.which('uic')
if uic_ is None: if uic_ is None:
...@@ -120,6 +119,7 @@ def compile_ui(*filenames: str) -> None: ...@@ -120,6 +119,7 @@ def compile_ui(*filenames: str) -> None:
args = f'-o {outfile} {filename}' args = f'-o {outfile} {filename}'
assert uic_, "PySide2 compiler failed, can't find uic" assert uic_, "PySide2 compiler failed, can't find uic"
os_ = sys.platform
if os_.startswith("linux"): # Linux if os_.startswith("linux"): # Linux
cmd = f'{uic_} {args}' cmd = f'{uic_} {args}'
subprocess.call(cmd.split()) subprocess.call(cmd.split())
...@@ -147,7 +147,7 @@ def compile_ui(*filenames: str) -> None: ...@@ -147,7 +147,7 @@ def compile_ui(*filenames: str) -> None:
if not filenames: if not filenames:
ui_files = [os.path.join(root, name) ui_files = [os.path.join(root, name)
for root, dirs, files in os.walk('.') for root, _, files in os.walk('.')
for name in files for name in files
if name.endswith(('.ui'))] if name.endswith(('.ui'))]
for filename in ui_files: for filename in ui_files:
...@@ -159,22 +159,19 @@ def compile_ui(*filenames: str) -> None: ...@@ -159,22 +159,19 @@ def compile_ui(*filenames: str) -> None:
def compile_all(): def compile_all():
"""The compiler will search for '*.qrc* resource files in 'icons\' folder """The compiler will search for resource (.qrc) files and form (.ui) files
and for '*.ui' form files and compile accordingly.""" and compile accordingly."""
compile_rc() compile_rc()
compile_ui() compile_ui()
if __name__ == '__main__': if __name__ == '__main__':
ver = b_asic.scheduler_gui.__version__ parser = argparse.ArgumentParser(description=f'{__doc__}',
descr = __doc__
parser = argparse.ArgumentParser(description=f'{descr}',
formatter_class=argparse.RawTextHelpFormatter) formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('-v', '--version', parser.add_argument('-v', '--version',
action='version', action='version',
version=f'%(prog)s v{ver}') version=f'%(prog)s v{__version__}')
if sys.version_info >= (3, 8): if sys.version_info >= (3, 8):
parser.add_argument('--ui', parser.add_argument('--ui',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment