From 68a8c60ef89a75631ee80c58b1a39e73941c0867 Mon Sep 17 00:00:00 2001 From: bsrdjan Date: Wed, 10 May 2023 13:08:14 +0300 Subject: [PATCH] refactor: imports sort order --- examples/clientIDoc.py | 11 ++---- examples/clientPrintDescription.py | 12 ++---- examples/clientStfcStructure.py | 16 +++----- examples/config.py | 8 +--- examples/server/bgrfc_client.py | 1 + examples/server/bgrfc_server.py | 4 +- examples/server/bgrfc_unit_state.py | 1 + examples/server/error.py | 4 +- examples/server/server_app_thread.py | 3 +- examples/server/server_errors.py | 6 ++- examples/server/tlog.py | 2 +- examples/serverFunctionDescription.py | 5 +-- examples/serverStfcConnection.py | 5 +-- examples/timeout/timeout_call.py | 1 + examples/timeout/timeout_connection.py | 1 + src/pyrfc/__init__.py | 43 ++++++++++----------- src/pyrfc/_cyrfc.pyx | 9 +++-- src/pyrfc/_exception.py | 1 + tests/config.py | 3 +- tests/function_description_utils.py | 5 +-- tests/server/server.py | 6 +-- tests/stfc-mrfc/test_function_group_mrfc.py | 2 +- tests/stfc-mrfc/test_function_group_stfc.py | 2 +- tests/test_client_config.py | 6 +-- tests/test_connection.py | 22 ++++------- tests/test_datatypes.py | 12 +++--- tests/test_errors.py | 9 +---- tests/test_errors_abap.py | 9 +---- tests/test_package.py | 6 ++- tests/test_rfcsdk.py | 2 +- tests/test_server.py | 19 +++------ tests/test_throughput.py | 4 +- tests/test_timeout.py | 6 +-- tests/test_wsrfc.py | 6 +-- 34 files changed, 101 insertions(+), 151 deletions(-) diff --git a/examples/clientIDoc.py b/examples/clientIDoc.py index e9d51ae..225f97a 100644 --- a/examples/clientIDoc.py +++ b/examples/clientIDoc.py @@ -2,16 +2,11 @@ # # SPDX-License-Identifier: Apache-2.0 -import pyrfc +from configparser import ConfigParser from os import path -from pyrfc import ( - ABAPApplicationError, - ABAPRuntimeError, - LogonError, - CommunicationError, -) -from configparser import ConfigParser +import pyrfc +from pyrfc import ABAPApplicationError, ABAPRuntimeError, CommunicationError, LogonError def initial_screen(): diff --git a/examples/clientPrintDescription.py b/examples/clientPrintDescription.py index 524d4c4..9085127 100644 --- a/examples/clientPrintDescription.py +++ b/examples/clientPrintDescription.py @@ -2,17 +2,11 @@ # # SPDX-License-Identifier: Apache-2.0 -from os import path -from configparser import ConfigParser import sys +from configparser import ConfigParser +from os import path -from pyrfc import ( - Connection, - ABAPApplicationError, - ABAPRuntimeError, - LogonError, - CommunicationError, -) +from pyrfc import ABAPApplicationError, ABAPRuntimeError, CommunicationError, Connection, LogonError def parameter_key_function(parameter): diff --git a/examples/clientStfcStructure.py b/examples/clientStfcStructure.py index f205113..95747d4 100644 --- a/examples/clientStfcStructure.py +++ b/examples/clientStfcStructure.py @@ -2,18 +2,12 @@ # # SPDX-License-Identifier: Apache-2.0 -from os import ( - path, -) -from pyrfc import Connection -from pprint import ( - pprint, -) -from configparser import ( - ConfigParser, -) - import datetime +from configparser import ConfigParser +from os import path +from pprint import pprint + +from pyrfc import Connection imp = { "RFCINT1": 0x7F, # INT1: Integer value (1 byte) diff --git a/examples/config.py b/examples/config.py index 26e16f8..36da4e9 100755 --- a/examples/config.py +++ b/examples/config.py @@ -2,12 +2,8 @@ # # SPDX-License-Identifier: Apache-2.0 -from os import ( - path, -) -from configparser import ( - ConfigParser, -) +from configparser import ConfigParser +from os import path cp = ConfigParser() cp.read( diff --git a/examples/server/bgrfc_client.py b/examples/server/bgrfc_client.py index 3de90e4..107d078 100644 --- a/examples/server/bgrfc_client.py +++ b/examples/server/bgrfc_client.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 import sys + from pyrfc import Connection client = Connection(dest=sys.argv[1]) diff --git a/examples/server/bgrfc_server.py b/examples/server/bgrfc_server.py index 8c76e1a..9ff8cab 100644 --- a/examples/server/bgrfc_server.py +++ b/examples/server/bgrfc_server.py @@ -3,11 +3,11 @@ # SPDX-License-Identifier: Apache-2.0 import sys -from backends import BACKEND -from pyrfc import Server, RCStatus, UnitState, UnitCallType +from backends import BACKEND from tlog import TLog +from pyrfc import RCStatus, Server, UnitCallType, UnitState backend_dest = sys.argv[1] diff --git a/examples/server/bgrfc_unit_state.py b/examples/server/bgrfc_unit_state.py index b6a8fa8..200bae9 100644 --- a/examples/server/bgrfc_unit_state.py +++ b/examples/server/bgrfc_unit_state.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 import sys + from pyrfc import Connection with Connection(dest=sys.argv[1]) as client: diff --git a/examples/server/error.py b/examples/server/error.py index 200da7a..3964209 100644 --- a/examples/server/error.py +++ b/examples/server/error.py @@ -1,6 +1,4 @@ -from pyrfc import ( - ABAPRuntimeError, -) +from pyrfc import ABAPRuntimeError errorInfo = { "code": 4, diff --git a/examples/server/server_app_thread.py b/examples/server/server_app_thread.py index fcd072a..9a5bfa4 100644 --- a/examples/server/server_app_thread.py +++ b/examples/server/server_app_thread.py @@ -2,9 +2,10 @@ # # SPDX-License-Identifier: Apache-2.0 -from pyrfc import Server from threading import Thread +from pyrfc import Server + def my_stfc_connection(request_context=None, REQUTEXT=""): """Server function my_stfc_connection with the signature of ABAP function module STFC_CONNECTION.""" diff --git a/examples/server/server_errors.py b/examples/server/server_errors.py index efaca14..b3122f3 100644 --- a/examples/server/server_errors.py +++ b/examples/server/server_errors.py @@ -2,9 +2,11 @@ # # SPDX-License-Identifier: Apache-2.0 -from backends import BACKEND import sys -from pyrfc import Server, ExternalRuntimeError + +from backends import BACKEND + +from pyrfc import ExternalRuntimeError, Server backend_dest = sys.argv[1] diff --git a/examples/server/tlog.py b/examples/server/tlog.py index a713cc4..3422ff8 100644 --- a/examples/server/tlog.py +++ b/examples/server/tlog.py @@ -6,8 +6,8 @@ import uuid from contextlib import suppress from datetime import datetime -from pyrfc import UnitState +from pyrfc import UnitState # default dbpath DBPATH = "./examples/server/tlog.log" diff --git a/examples/serverFunctionDescription.py b/examples/serverFunctionDescription.py index 2c77497..8de7682 100644 --- a/examples/serverFunctionDescription.py +++ b/examples/serverFunctionDescription.py @@ -2,10 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 -from pyrfc import ( - FunctionDescription, - TypeDescription, -) +from pyrfc import FunctionDescription, TypeDescription animals = TypeDescription( "ANIMALS", diff --git a/examples/serverStfcConnection.py b/examples/serverStfcConnection.py index 99af038..1c107e0 100644 --- a/examples/serverStfcConnection.py +++ b/examples/serverStfcConnection.py @@ -4,10 +4,7 @@ import os -from pyrfc import ( - Server, - set_ini_file_directory, -) +from pyrfc import Server, set_ini_file_directory def my_stfc_connection( diff --git a/examples/timeout/timeout_call.py b/examples/timeout/timeout_call.py index f0bc723..8a8c82d 100644 --- a/examples/timeout/timeout_call.py +++ b/examples/timeout/timeout_call.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 import sys + from pyrfc import Connection, RFCError client = Connection(dest=sys.argv[1], config={"timeout": 20}) diff --git a/examples/timeout/timeout_connection.py b/examples/timeout/timeout_connection.py index 4c56e5e..f0a3a4f 100644 --- a/examples/timeout/timeout_connection.py +++ b/examples/timeout/timeout_connection.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 import sys + from pyrfc import Connection, RFCError client = Connection(dest=sys.argv[1], config={"timeout": 5}) diff --git a/src/pyrfc/__init__.py b/src/pyrfc/__init__.py index e57aa26..7437179 100755 --- a/src/pyrfc/__init__.py +++ b/src/pyrfc/__init__.py @@ -4,10 +4,9 @@ """pyrfc package.""" -from contextlib import suppress import importlib.metadata import os - +from contextlib import suppress __version__ = importlib.metadata.version("pyrfc") __version_info__ = tuple(__version__.split(".")) @@ -17,40 +16,40 @@ with suppress(Exception): os.add_dll_directory(os.path.join(os.environ["SAPNWRFC_HOME"], "lib")) -from pyrfc._exception import ( # noqa F401 - RFCError, - RFCLibError, - CommunicationError, - LogonError, +from pyrfc._exception import CommunicationError # noqa F401 +from pyrfc._exception import ( ABAPApplicationError, ABAPRuntimeError, - ExternalAuthorizationError, ExternalApplicationError, + ExternalAuthorizationError, ExternalRuntimeError, + LogonError, + RFCError, + RFCLibError, ) try: - from pyrfc._cyrfc import ( # noqa F401 - get_nwrfclib_version, - reload_ini_file, - set_ini_file_directory, - set_cryptolib_path, - set_locale_radix, - language_iso_to_sap, - language_sap_to_iso, - cancel_connection, + from pyrfc._cyrfc import RCStatus # noqa F401 + from pyrfc._cyrfc import ( Connection, ConnectionParameters, Decimal, - Throughput, - TypeDescription, FunctionDescription, + RfcFieldType, + RfcParameterDirection, Server, + Throughput, + TypeDescription, UnitCallType, UnitState, - RCStatus, - RfcParameterDirection, - RfcFieldType, + cancel_connection, + get_nwrfclib_version, + language_iso_to_sap, + language_sap_to_iso, + reload_ini_file, + set_cryptolib_path, + set_ini_file_directory, + set_locale_radix, ) except Exception as ex: # PyRFC module could not be loaded diff --git a/src/pyrfc/_cyrfc.pyx b/src/pyrfc/_cyrfc.pyx index 8869c41..457f877 100755 --- a/src/pyrfc/_cyrfc.pyx +++ b/src/pyrfc/_cyrfc.pyx @@ -4,23 +4,24 @@ """ The _pyrfc C-extension module """ -from libc.stdlib cimport malloc, free from libc.stdint cimport uintptr_t +from libc.stdlib cimport free, malloc + +import socket from collections.abc import Iterable -from datetime import date, time, datetime +from datetime import date, datetime, time from decimal import Decimal from enum import Enum, auto from locale import localeconv from os.path import isfile, join from sys import exc_info, platform -import socket from threading import Thread, Timer from pyrfc.csapnwrfc cimport * + from pyrfc._exception import * from pyrfc._utils import enum_names, enum_values - ################################################################################ # Configuration options ################################################################################ diff --git a/src/pyrfc/_exception.py b/src/pyrfc/_exception.py index a93fd22..04e7312 100755 --- a/src/pyrfc/_exception.py +++ b/src/pyrfc/_exception.py @@ -5,6 +5,7 @@ """:mod:`pyrfc`-specific exception classes.""" from enum import Enum, auto + from pyrfc._utils import enum_values diff --git a/tests/config.py b/tests/config.py index 8b456ae..3788880 100755 --- a/tests/config.py +++ b/tests/config.py @@ -3,8 +3,9 @@ # SPDX-License-Identifier: Apache-2.0 import datetime -from configparser import ConfigParser import platform +from configparser import ConfigParser + from pyrfc import set_ini_file_directory COPA = ConfigParser() diff --git a/tests/function_description_utils.py b/tests/function_description_utils.py index f7f6cd7..5ae8b3c 100644 --- a/tests/function_description_utils.py +++ b/tests/function_description_utils.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: Apache-2.0 import sys + from pyrfc import Connection parameter_keys = [ @@ -90,9 +91,7 @@ def main(func_name): # from data.func_desc_BAPISDORDER_GETDETAILEDLIST import FUNC_DESC_BAPISDORDER_GETDETAILEDLIST # from data.func_desc_BS01_SALESORDER_GETDETAIL import FUNC_DESC_BS01_SALESORDER_GETDETAIL - from data.func_desc_STFC_STRUCTURE import ( # noqa: E402 WPS131 - FUNC_DESC_STFC_STRUCTURE, - ) + from data.func_desc_STFC_STRUCTURE import FUNC_DESC_STFC_STRUCTURE # noqa: E402 WPS131 with Connection(dest="MME") as client: func_desc = client.get_function_description(func_name) diff --git a/tests/server/server.py b/tests/server/server.py index 1675d49..f892106 100644 --- a/tests/server/server.py +++ b/tests/server/server.py @@ -3,10 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 import os -from pyrfc import ( - Server, - set_ini_file_directory, -) + +from pyrfc import Server, set_ini_file_directory # server function diff --git a/tests/stfc-mrfc/test_function_group_mrfc.py b/tests/stfc-mrfc/test_function_group_mrfc.py index 9963551..613d4e1 100755 --- a/tests/stfc-mrfc/test_function_group_mrfc.py +++ b/tests/stfc-mrfc/test_function_group_mrfc.py @@ -8,8 +8,8 @@ # Some of them are used as well. import unittest -from pyrfc import Connection +from pyrfc import Connection from tests.config import PARAMS as params diff --git a/tests/stfc-mrfc/test_function_group_stfc.py b/tests/stfc-mrfc/test_function_group_stfc.py index 659d96e..90a408a 100755 --- a/tests/stfc-mrfc/test_function_group_stfc.py +++ b/tests/stfc-mrfc/test_function_group_stfc.py @@ -4,8 +4,8 @@ import datetime import unittest -from pyrfc import Connection +from pyrfc import Connection from tests.config import PARAMS as params diff --git a/tests/test_client_config.py b/tests/test_client_config.py index b65b92a..3268e54 100755 --- a/tests/test_client_config.py +++ b/tests/test_client_config.py @@ -2,13 +2,13 @@ # # SPDX-License-Identifier: Apache-2.0 -from tests.config import CONFIG_SECTIONS as config_sections - import datetime -from pyrfc import Connection, RFCError import pytest +from pyrfc import Connection, RFCError +from tests.config import CONFIG_SECTIONS as config_sections + class TestConnection: def test_config_rstrip_false(self): diff --git a/tests/test_connection.py b/tests/test_connection.py index 80ef1e0..42a281b 100755 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -2,31 +2,23 @@ # # SPDX-License-Identifier: Apache-2.0 -from tests.config import ( - PARAMS as params, - PARAMSDEST as paramsdest, - CONFIG_SECTIONS as config_sections, - UNICODETEST, - latest_python_version, -) - import datetime import socket import sys from contextlib import suppress +from tests.config import CONFIG_SECTIONS as config_sections +from tests.config import PARAMS as params +from tests.config import PARAMSDEST as paramsdest +from tests.config import UNICODETEST, latest_python_version + with suppress(ModuleNotFoundError): import tomllib -from pyrfc import ( - Connection, - RFCError, - ExternalRuntimeError, - __version__, -) - import pytest +from pyrfc import Connection, ExternalRuntimeError, RFCError, __version__ + class TestConnection: def setup_method(self): diff --git a/tests/test_datatypes.py b/tests/test_datatypes.py index ccc3dbe..fe9ff19 100755 --- a/tests/test_datatypes.py +++ b/tests/test_datatypes.py @@ -2,25 +2,23 @@ # # SPDX-License-Identifier: Apache-2.0 -from tests.abap_system import connection_info - import sys from decimal import Decimal -from locale import setlocale, localeconv, LC_ALL -from pyrfc import Connection, set_locale_radix, ExternalRuntimeError +from locale import LC_ALL, localeconv, setlocale import pytest - +from pyrfc import Connection, ExternalRuntimeError, set_locale_radix +from tests.abap_system import connection_info from tests.config import ( + BYTEARRAY_TEST, + BYTES_TEST, CONNECTION_INFO, RFC_MATH, ABAP_to_python_date, ABAP_to_python_time, python_to_ABAP_date, python_to_ABAP_time, - BYTEARRAY_TEST, - BYTES_TEST, ) setlocale(LC_ALL) diff --git a/tests/test_errors.py b/tests/test_errors.py index f1dbe5d..f9aeb3b 100755 --- a/tests/test_errors.py +++ b/tests/test_errors.py @@ -3,13 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 import pytest -from pyrfc import ( - Connection, - RFCError, - LogonError, - ABAPApplicationError, - ExternalRuntimeError, -) + +from pyrfc import ABAPApplicationError, Connection, ExternalRuntimeError, LogonError, RFCError from tests.config import PARAMS as params diff --git a/tests/test_errors_abap.py b/tests/test_errors_abap.py index 9326438..114bd95 100755 --- a/tests/test_errors_abap.py +++ b/tests/test_errors_abap.py @@ -3,15 +3,8 @@ # SPDX-License-Identifier: Apache-2.0 import pytest -from pyrfc import ( - Connection, - RFCError, - ABAPRuntimeError, - ABAPApplicationError, - # CommunicationError, - # ExternalRuntimeError, -) +from pyrfc import ABAPApplicationError, ABAPRuntimeError, Connection, RFCError from tests.config import PARAMS as params diff --git a/tests/test_package.py b/tests/test_package.py index da471ca..64b5e74 100644 --- a/tests/test_package.py +++ b/tests/test_package.py @@ -2,13 +2,15 @@ # # SPDX-License-Identifier: Apache-2.0 -from tests.config import latest_python_version import sys +from contextlib import suppress from os import listdir from os.path import isfile, join -from contextlib import suppress + import pytest +from tests.config import latest_python_version + with suppress(ModuleNotFoundError): import tomllib diff --git a/tests/test_rfcsdk.py b/tests/test_rfcsdk.py index 9451b7d..9ee584d 100755 --- a/tests/test_rfcsdk.py +++ b/tests/test_rfcsdk.py @@ -2,8 +2,8 @@ # # SPDX-License-Identifier: Apache-2.0 +from pyrfc import language_iso_to_sap, language_sap_to_iso, reload_ini_file from tests.config import LANGUAGES -from pyrfc import reload_ini_file, language_iso_to_sap, language_sap_to_iso class TestRfcSDK: diff --git a/tests/test_server.py b/tests/test_server.py index b12f3c9..083bae3 100755 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -4,23 +4,16 @@ import os import sys + import pytest -from pyrfc import ( - Connection, - Server, - set_ini_file_directory, - ABAPApplicationError, -) + +from pyrfc import ABAPApplicationError, Connection, Server, set_ini_file_directory sys.path.append(os.path.dirname(__file__)) -from function_description_utils import compare_function_description # noqa: E402 +from data.func_desc_BAPISDORDER_GETDETAILEDLIST import FUNC_DESC_BAPISDORDER_GETDETAILEDLIST # noqa: E402 +from data.func_desc_BS01_SALESORDER_GETDETAIL import FUNC_DESC_BS01_SALESORDER_GETDETAIL # noqa: E402 from data.func_desc_STFC_STRUCTURE import FUNC_DESC_STFC_STRUCTURE # noqa: E402 -from data.func_desc_BAPISDORDER_GETDETAILEDLIST import ( # noqa: E402 - FUNC_DESC_BAPISDORDER_GETDETAILEDLIST, -) -from data.func_desc_BS01_SALESORDER_GETDETAIL import ( # noqa: E402 - FUNC_DESC_BS01_SALESORDER_GETDETAIL, -) +from function_description_utils import compare_function_description # noqa: E402 def my_stfc_connection(request_context=None, REQUTEXT=""): diff --git a/tests/test_throughput.py b/tests/test_throughput.py index 58d9d57..2ffa9f5 100644 --- a/tests/test_throughput.py +++ b/tests/test_throughput.py @@ -2,11 +2,11 @@ # # SPDX-License-Identifier: Apache-2.0 +import pytest + from pyrfc import Connection, Throughput from tests.config import PARAMS as params -import pytest - def equal_no_time(t1, t2): counters = [ diff --git a/tests/test_timeout.py b/tests/test_timeout.py index d014709..afd35ad 100755 --- a/tests/test_timeout.py +++ b/tests/test_timeout.py @@ -2,11 +2,11 @@ # # SPDX-License-Identifier: Apache-2.0 -from tests.config import CONNECTION_INFO -from pyrfc import Connection, RFCError - import pytest +from pyrfc import Connection, RFCError +from tests.config import CONNECTION_INFO + client = Connection(**CONNECTION_INFO) diff --git a/tests/test_wsrfc.py b/tests/test_wsrfc.py index bc8d136..a1ee4e9 100755 --- a/tests/test_wsrfc.py +++ b/tests/test_wsrfc.py @@ -2,11 +2,11 @@ # # SPDX-License-Identifier: Apache-2.0 -from tests.config import CryptoLibPath # ClientPSEPath, -from pyrfc import Connection, set_cryptolib_path, ExternalRuntimeError - import pytest +from pyrfc import Connection, ExternalRuntimeError, set_cryptolib_path +from tests.config import CryptoLibPath # ClientPSEPath, + class TestWsrfc: @pytest.mark.skip(reason="no automatic test")