Skip to content

Commit

Permalink
refactor: apply formatting to all the code
Browse files Browse the repository at this point in the history
  • Loading branch information
senyai committed Sep 13, 2024
1 parent 82ab97d commit b1b6e2c
Show file tree
Hide file tree
Showing 44 changed files with 2,182 additions and 1,215 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
with:
python-version: '3.10'
cache: 'pip'
- uses: psf/black@stable
- name: wheel
run: |
pip install build
Expand Down
167 changes: 81 additions & 86 deletions build-cx.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,55 @@
import os
from cx_Freeze import setup, Executable

os.environ['TCL_LIBRARY'] = os.path.join(sys.exec_prefix, 'tcl', 'tcl8.6')
os.environ['TK_LIBRARY'] = os.path.join(sys.exec_prefix, 'tcl', 'tk8.6')
os.environ["TCL_LIBRARY"] = os.path.join(sys.exec_prefix, "tcl", "tcl8.6")
os.environ["TK_LIBRARY"] = os.path.join(sys.exec_prefix, "tcl", "tk8.6")

# "import" __version__
for line in open("gmc/__init__.py"):
if line.startswith("__version__"):
exec(line)
break
else:
raise ValueError('no version')
raise ValueError("no version")

shortcut_table = [
("DesktopShortcut", # Shortcut
"DesktopFolder", # Directory_
"GMC", # Name
"TARGETDIR", # Component_
"[TARGETDIR]run_gmc.exe", # Target
None, # Arguments
None, # Description
None, # Hotkey
None, # Icon
None, # IconIndex
None, # ShowCmd
'TARGETDIR' # WkDir
(
"DesktopShortcut", # Shortcut
"DesktopFolder", # Directory_
"GMC", # Name
"TARGETDIR", # Component_
"[TARGETDIR]run_gmc.exe", # Target
None, # Arguments
None, # Description
None, # Hotkey
None, # Icon
None, # IconIndex
None, # ShowCmd
"TARGETDIR", # WkDir
),
(
"StartupShortcut", # Shortcut
"StartupFolder", # Directory_
"GMC", # Name
"TARGETDIR", # Component_
"[TARGETDIR]run_gmc.exe", # Target
None, # Arguments
None, # Description
None, # Hotkey
None, # Icon
None, # IconIndex
None, # ShowCmd
"TARGETDIR", # WkDir
),
("StartupShortcut", # Shortcut
"StartupFolder", # Directory_
"GMC", # Name
"TARGETDIR", # Component_
"[TARGETDIR]run_gmc.exe", # Target
None, # Arguments
None, # Description
None, # Hotkey
None, # Icon
None, # IconIndex
None, # ShowCmd
'TARGETDIR' # WkDir
)
]

options = {
'build_exe': {
'packages': [
'PyQt5.sip',
'numpy',
'PIL',
'cv2',
"build_exe": {
"packages": [
"PyQt5.sip",
"numpy",
"PIL",
"cv2",
],
"excludes": [
"tkinter",
Expand Down Expand Up @@ -85,51 +87,47 @@
"html",
"http",
],
'includes': [
'atexit',

'gmc.markup_objects',
'gmc.markup_objects.graph',
'gmc.markup_objects.line',
'gmc.markup_objects.moveable_diamond',
'gmc.markup_objects.point',
'gmc.markup_objects.polygon',
'gmc.markup_objects.quadrangle',
'gmc.markup_objects.rect',
'gmc.markup_objects.tags',

'gmc.file_widgets',
'gmc.file_widgets.multiple_sources_one_destination',
'gmc.file_widgets.one_source_one_destination',

'gmc.utils',
'gmc.utils.dicts',
'gmc.utils.image',
'gmc.utils.json',
'gmc.utils.read_properties',

'gmc.views',
'gmc.views.filesystem_view',
'gmc.views.filesystem_widget',
'gmc.views.image_view',
'gmc.views.image_widget',
'gmc.views.properties_view',

'gmc.schemas',
'gmc.schemas.tagged_objects',
"includes": [
"atexit",
"gmc.markup_objects",
"gmc.markup_objects.graph",
"gmc.markup_objects.line",
"gmc.markup_objects.moveable_diamond",
"gmc.markup_objects.point",
"gmc.markup_objects.polygon",
"gmc.markup_objects.quadrangle",
"gmc.markup_objects.rect",
"gmc.markup_objects.tags",
"gmc.file_widgets",
"gmc.file_widgets.multiple_sources_one_destination",
"gmc.file_widgets.one_source_one_destination",
"gmc.utils",
"gmc.utils.dicts",
"gmc.utils.image",
"gmc.utils.json",
"gmc.utils.read_properties",
"gmc.views",
"gmc.views.filesystem_view",
"gmc.views.filesystem_widget",
"gmc.views.image_view",
"gmc.views.image_widget",
"gmc.views.properties_view",
"gmc.schemas",
"gmc.schemas.tagged_objects",
# 'gmc.schemas.map_markup',
# 'gmc.schemas.number_plates_video',
# 'gmc.schemas.feature_matching',
'gmc.schemas.fields',
"gmc.schemas.fields",
# 'gmc.schemas.ballfish',

],
'include_files': [
('gmc/schemas/tagged_objects/__init__.py',
'lib/gmc/schemas/tagged_objects/__init__.py'
"include_files": [
(
"gmc/schemas/tagged_objects/__init__.py",
"lib/gmc/schemas/tagged_objects/__init__.py",
),
('gmc/schemas/tagged_objects/markup_interpolation.py',
'lib/gmc/schemas/tagged_objects/markup_interpolation.py'
(
"gmc/schemas/tagged_objects/markup_interpolation.py",
"lib/gmc/schemas/tagged_objects/markup_interpolation.py",
),
# ('api_for_python.dll',
# 'lib/gmc/schemas/number_plates/api_for_python.dll'
Expand All @@ -148,25 +146,22 @@
# ),
],
},
'bdist_msi': {
'data': {
'Shortcut': shortcut_table
}
}
"bdist_msi": {"data": {"Shortcut": shortcut_table}},
}

here = os.path.dirname(__file__)
executables = [
Executable(
'run_gmc.py',
"run_gmc.py",
base=None,
icon=os.path.join(here, 'gmc/resources/gmc.ico'),
icon=os.path.join(here, "gmc/resources/gmc.ico"),
)
]

setup(name='GMC',
version=__version__,
description='General Markup Creator',
options=options,
executables=executables
)
setup(
name="GMC",
version=__version__,
description="General Markup Creator",
options=options,
executables=executables,
)
31 changes: 19 additions & 12 deletions gmc/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ class GMCArguments(TypedDict):

def _sigint(signum: int, _: None) -> None:
from time import time

now = time()
if now - getattr(_sigint, 'time', 0) < 3:
if now - getattr(_sigint, "time", 0) < 3:
sys.exit(signum)
print(" Ctrl+C now to force exit ")
setattr(_sigint, 'time', now)
setattr(_sigint, "time", now)


def application(args: GMCArguments):
Expand All @@ -36,6 +37,7 @@ def application(args: GMCArguments):
try:
xrange
from PyQt5.QtWidgets import QMessageBox

QMessageBox.critical(None, "GMC", "Python 3 is required")
return
except NameError:
Expand All @@ -44,12 +46,14 @@ def application(args: GMCArguments):
try:
from .main_window import MainWindow
from . import __version__

main_window = MainWindow(__version__, app, args)
signal.signal(signal.SIGINT, _sigint)
except Exception:
import traceback

traceback.print_exc(file=sys.stdout)
print('press <Enter> to exit')
print("press <Enter> to exit")
input()
return

Expand All @@ -59,26 +63,29 @@ def application(args: GMCArguments):

def parse_args(external: Sequence[str]) -> GMCArguments:
from .schemas import iter_schemas

parser = argparse.ArgumentParser("GMC runner")

all_schemas = ", ".join([info[0] for info in iter_schemas(external)])
parser.add_argument('--schema',
parser.add_argument(
"--schema",
help=f"schema, e.g. tagged_objects (default: previously used schema,\n"
f"Available: {all_schemas})")
parser.add_argument('-s', '--src_dir',
help="root of images dir")
parser.add_argument('-d', '--dst_dir',
help="root of markup dir")
parser.add_argument('--external-schemas',
f"Available: {all_schemas})",
)
parser.add_argument("-s", "--src_dir", help="root of images dir")
parser.add_argument("-d", "--dst_dir", help="root of markup dir")
parser.add_argument(
"--external-schemas",
nargs="*",
default=[],
help="list of files/directories to treat like a schema")
help="list of files/directories to treat like a schema",
)
args = parser.parse_args()
args.external_schemas.extend(external)
return cast(GMCArguments, vars(args))


def main(external: Sequence[str]=()):
def main(external: Sequence[str] = ()):
app = application(parse_args(external))
if app:
exit(app[0].exec_())
Loading

0 comments on commit b1b6e2c

Please sign in to comment.