From 428692ea3ae8643092d4e3289291587ec123b29f Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Thu, 10 Jul 2025 05:14:06 +0200 Subject: [PATCH] Streamline Python file headers somewhat - Add coding statement - Import all modules in one line where possible - Order: __future__, typing, plain imports, from imports, janware modules Signed-off-by: Jan Lindemann --- tools/python/jwutils/Cmd.py | 9 ++++----- tools/python/jwutils/Cmds.py | 15 ++++----------- tools/python/jwutils/Config.py | 7 ++----- tools/python/jwutils/CppState.py | 2 ++ tools/python/jwutils/Object.py | 3 +++ tools/python/jwutils/Process.py | 2 ++ tools/python/jwutils/RedirectStdIO.py | 8 ++++---- tools/python/jwutils/Signals.py | 4 +++- tools/python/jwutils/StopWatch.py | 1 + tools/python/jwutils/algo/ShuntingYard.py | 3 ++- tools/python/jwutils/asyncio/Process.py | 2 ++ tools/python/jwutils/asyncio/Signals.py | 3 +++ tools/python/jwutils/asyncio/__init__.py | 2 ++ tools/python/jwutils/db/rows.py | 3 +-- tools/python/jwutils/db/schema/Column.py | 3 +-- tools/python/jwutils/db/schema/DataType.py | 4 ++-- tools/python/jwutils/log.py | 3 +++ tools/python/jwutils/misc.py | 10 +++------- tools/python/jwutils/multi_key_dict.py | 2 ++ tools/python/jwutils/stree/StringTree.py | 2 ++ tools/python/jwutils/stree/serdes.py | 2 ++ 21 files changed, 50 insertions(+), 40 deletions(-) diff --git a/tools/python/jwutils/Cmd.py b/tools/python/jwutils/Cmd.py index a05181d..c5f879e 100644 --- a/tools/python/jwutils/Cmd.py +++ b/tools/python/jwutils/Cmd.py @@ -1,17 +1,16 @@ +# -*- coding: utf-8 -*- + from __future__ import annotations from typing import List, Type, Union, TypeVar -import abc -import argparse -from abc import ABC +import inspect, sys, re, abc, argparse from argparse import ArgumentParser, _SubParsersAction -import inspect, sys, re from jwutils import log # full blown example of one level of nested subcommands # git -C project remote -v show -n myremote -class Cmd(ABC): # export +class Cmd(abc.ABC): # export @abc.abstractmethod async def run(self, args): diff --git a/tools/python/jwutils/Cmds.py b/tools/python/jwutils/Cmds.py index 4db9604..97e91e1 100644 --- a/tools/python/jwutils/Cmds.py +++ b/tools/python/jwutils/Cmds.py @@ -1,15 +1,8 @@ -import os -import sys -import argparse -import importlib -import inspect -import re -import pickle -import asyncio -from argparse import ArgumentParser -from typing import Optional +# -*- coding: utf-8 -*- -import cProfile +from typing import Optional +import os, sys, argparse, importlib, inspect, re, pickle, asyncio, cProfile +from argparse import ArgumentParser import jwutils from jwutils.log import * diff --git a/tools/python/jwutils/Config.py b/tools/python/jwutils/Config.py index e8f456d..24788dc 100644 --- a/tools/python/jwutils/Config.py +++ b/tools/python/jwutils/Config.py @@ -1,11 +1,8 @@ # -*- coding: utf-8 -*- -import os -import re -import glob -import sys -from pathlib import Path, PosixPath from typing import Optional, Dict, cast +import os, re, glob, sys +from pathlib import Path, PosixPath from jwutils import stree from .stree.StringTree import StringTree diff --git a/tools/python/jwutils/CppState.py b/tools/python/jwutils/CppState.py index f6a74fe..d6cb5fe 100644 --- a/tools/python/jwutils/CppState.py +++ b/tools/python/jwutils/CppState.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + class CppState: # export def __init__(self): diff --git a/tools/python/jwutils/Object.py b/tools/python/jwutils/Object.py index 8b47386..f5ea5ab 100644 --- a/tools/python/jwutils/Object.py +++ b/tools/python/jwutils/Object.py @@ -1,4 +1,7 @@ +# -*- coding: utf-8 -*- + from __future__ import print_function + import jwutils.log class Object(object): # export diff --git a/tools/python/jwutils/Process.py b/tools/python/jwutils/Process.py index c224c3d..a20a856 100644 --- a/tools/python/jwutils/Process.py +++ b/tools/python/jwutils/Process.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from __future__ import annotations from abc import ABC, abstractmethod from enum import Enum, Flag, auto diff --git a/tools/python/jwutils/RedirectStdIO.py b/tools/python/jwutils/RedirectStdIO.py index 48bd7d3..0d6bd00 100644 --- a/tools/python/jwutils/RedirectStdIO.py +++ b/tools/python/jwutils/RedirectStdIO.py @@ -1,8 +1,8 @@ +# -*- coding: utf-8 -*- + from __future__ import print_function -import os -import io -import sys -import traceback + +import os, io, sys, traceback from fcntl import fcntl, F_GETFL, F_SETFL class RedirectStdIO: # export diff --git a/tools/python/jwutils/Signals.py b/tools/python/jwutils/Signals.py index af178e8..1179753 100644 --- a/tools/python/jwutils/Signals.py +++ b/tools/python/jwutils/Signals.py @@ -1,5 +1,7 @@ -from abc import ABC, abstractmethod +# -*- coding: utf-8 -*- + from typing import Dict, Callable +from abc import ABC, abstractmethod _handled_signals: Dict[int, Callable] = {} diff --git a/tools/python/jwutils/StopWatch.py b/tools/python/jwutils/StopWatch.py index c987124..4e7472b 100644 --- a/tools/python/jwutils/StopWatch.py +++ b/tools/python/jwutils/StopWatch.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from datetime import datetime + from .log import * class StopWatch: # export diff --git a/tools/python/jwutils/algo/ShuntingYard.py b/tools/python/jwutils/algo/ShuntingYard.py index f2c23d9..61ebf24 100644 --- a/tools/python/jwutils/algo/ShuntingYard.py +++ b/tools/python/jwutils/algo/ShuntingYard.py @@ -1,5 +1,6 @@ -import re, shlex +# -*- coding: utf-8 -*- +import re, shlex from collections import namedtuple from ..log import * diff --git a/tools/python/jwutils/asyncio/Process.py b/tools/python/jwutils/asyncio/Process.py index d654da8..3a63713 100644 --- a/tools/python/jwutils/asyncio/Process.py +++ b/tools/python/jwutils/asyncio/Process.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from abc import abstractmethod from ..Process import Process as ProcessBase diff --git a/tools/python/jwutils/asyncio/Signals.py b/tools/python/jwutils/asyncio/Signals.py index b6b43ac..7096d0a 100644 --- a/tools/python/jwutils/asyncio/Signals.py +++ b/tools/python/jwutils/asyncio/Signals.py @@ -1,4 +1,7 @@ +# -*- coding: utf-8 -*- + import asyncio + from ..Signals import Signals as SignalsBase class Signals(SignalsBase): diff --git a/tools/python/jwutils/asyncio/__init__.py b/tools/python/jwutils/asyncio/__init__.py index fcdc905..e94d4d7 100644 --- a/tools/python/jwutils/asyncio/__init__.py +++ b/tools/python/jwutils/asyncio/__init__.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + # >> -------------------------- generated by python-tools.sh >> from jwutils.asyncio.Process import Process # << -------------------------- generated by python-tools.sh << diff --git a/tools/python/jwutils/db/rows.py b/tools/python/jwutils/db/rows.py index 271dae6..682c2a4 100644 --- a/tools/python/jwutils/db/rows.py +++ b/tools/python/jwutils/db/rows.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- -import io -import os, re, textwrap, json, csv +import io, os, re, textwrap, json, csv from tabulate import tabulate # type: ignore from jwutils.log import * diff --git a/tools/python/jwutils/db/schema/Column.py b/tools/python/jwutils/db/schema/Column.py index 18064e9..a8fce9b 100644 --- a/tools/python/jwutils/db/schema/Column.py +++ b/tools/python/jwutils/db/schema/Column.py @@ -4,9 +4,8 @@ from typing import Optional, Any import abc -from ...log import * - from .DataType import DataType +from ...log import * class Column(abc.ABC): # export diff --git a/tools/python/jwutils/db/schema/DataType.py b/tools/python/jwutils/db/schema/DataType.py index 6118267..ecda420 100644 --- a/tools/python/jwutils/db/schema/DataType.py +++ b/tools/python/jwutils/db/schema/DataType.py @@ -1,11 +1,11 @@ # -*- coding: utf-8 -*- from typing import Optional - -from ...log import * from enum import Enum, auto from datetime import datetime +from ...log import * + class Id(Enum): Integer = auto() SmallInteger = auto() diff --git a/tools/python/jwutils/log.py b/tools/python/jwutils/log.py index f7ad37a..cf7e600 100644 --- a/tools/python/jwutils/log.py +++ b/tools/python/jwutils/log.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from __future__ import print_function from typing import List, Tuple, Optional, Any @@ -6,6 +8,7 @@ import sys, re, io, syslog, inspect from os.path import basename from datetime import datetime + from . import misc # --- python 2 / 3 compatibility stuff diff --git a/tools/python/jwutils/misc.py b/tools/python/jwutils/misc.py index ca11e4a..27d938e 100644 --- a/tools/python/jwutils/misc.py +++ b/tools/python/jwutils/misc.py @@ -1,10 +1,6 @@ -import os, errno -import atexit -import tempfile -import filecmp -import inspect -import importlib -import re +# -*- coding: utf-8 -*- + +import os, errno, atexit, tempfile, filecmp, inspect, importlib, re from typing import Set, Iterable diff --git a/tools/python/jwutils/multi_key_dict.py b/tools/python/jwutils/multi_key_dict.py index 18d1eef..333e72e 100644 --- a/tools/python/jwutils/multi_key_dict.py +++ b/tools/python/jwutils/multi_key_dict.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + ''' Created on 26 May 2013 diff --git a/tools/python/jwutils/stree/StringTree.py b/tools/python/jwutils/stree/StringTree.py index d6f8a31..eea13ad 100644 --- a/tools/python/jwutils/stree/StringTree.py +++ b/tools/python/jwutils/stree/StringTree.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from __future__ import annotations from typing import Any, List, Optional, Union diff --git a/tools/python/jwutils/stree/serdes.py b/tools/python/jwutils/stree/serdes.py index 426c15d..6c69084 100644 --- a/tools/python/jwutils/stree/serdes.py +++ b/tools/python/jwutils/stree/serdes.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + import os from jwutils.stree.StringTree import *