From 74a29f7ce353650ca78b64fb6aa2292e337644db Mon Sep 17 00:00:00 2001 From: "emdee@spm.plastiras.org" Date: Fri, 2 Feb 2024 03:14:37 +0000 Subject: [PATCH] updates --- Makefile | 19 ++++++---- pyproject.toml | 50 +++++++++++++++++++------- setup.cfg | 22 +++++------- setup.py | 2 +- src/__init__.py | 5 +++ src/tox_wrapper/__init__.py | 2 ++ src/tox_wrapper/tests/tests_wrapper.py | 18 +++++----- src/tox_wrapper/toxygen_echo.py | 8 ++++- 8 files changed, 82 insertions(+), 44 deletions(-) create mode 100644 src/__init__.py diff --git a/Makefile b/Makefile index 1b8ab7c..6ad138c 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,28 @@ -PYTHON=python3 +PREFIX=/usr/local +PYTHON=python3.sh +PIP=pip3.sh prepare:: bash .pylint.sh check:: - PYTHONPATH=$${PWD} pyanalyze \ - tox_wrapper/tox.py tox_wrapper/tests/tests_wrapper.py \ + PYTHONPATH=$${PWD}/src pyanalyze \ + src/tox_wrapper/tox.py src/tox_wrapper/tests/tests_wrapper.py \ > .pyanal.out 2>&1 install:: - $(PYTHON) setup.py install + $(PIP) install --target $PREFIX/lib/python3.11/site-packages --upgrade . + +rsync:: + bash .rsync.sh help:: - $(PYTHON) tox_wrapper/tests/tests_wrapper.py --help + PYTHONPATH=$${PWD}/src \ + $(PYTHON) src/tox_wrapper/tests/tests_wrapper.py --help test:: - $(PYTHON) tox_wrapper/tests/tests_wrapper.py + PYTHONPATH=$${PWD}/src \ + $(PYTHON) src/tox_wrapper/tests/tests_wrapper.py clean:: rm -f .[a-z]* *~ */*~ */*/*~ diff --git a/pyproject.toml b/pyproject.toml index 057e3d9..d78a793 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,22 +1,46 @@ -[tool.poetry] +[project] name = "tox_wrapper" -version = "1.0.0" description = "A Python3 ctypes wrapping of c-toxcore into Python." -authors = ["Ingvar"] +authors = [{ name = "Ingvar", email = "Ingvar@gitgub.com" } ] +requires-python = ">=3.6" +keywords = ["tox", "python3", "ctypes"] +classifiers = [ + "License :: OSI Approved", + "Operating System :: POSIX :: BSD :: FreeBSD", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: Implementation :: CPython", + ] +dynamic = ["version", "readme", ] # cannot be dynamic ['license'] + +[project.scripts] +tox_wrapper_tests = "tox_wrapper.tests.tests_wrapper:main" +toxygen_echo = "tox_wrapper.toxygen_echo:main" + + +# ... +[tool.setuptools.dynamic] +version = {attr = "tox_wrapper.__version__"} +readme = {file = ["README.md"]} + +[project.license] +file = "LICENSE.md" + +[project.urls] repository = "https://git.plastiras.org/emdee/toxygen_wrapper" -keywords = ["tox","python3","ctypes"] -license = "GPL3" - -[tool.poetry.dependencies] -python = ">=3.6;<3.12" - -# Stuff needed for development, but not for install&usage -# [tool.poetry.dev-dependencies] [build-system] requires = ["setuptools >= 61.0"] build-backend = "setuptools.build_meta" -[tool.setuptools.packages.find] -where = "src" +[tool.setuptools] +packages = ["tox_wrapper", "tox_wrapper.tests"] +#[tool.setuptools.packages.find] +#where = "src" diff --git a/setup.cfg b/setup.cfg index 8144980..81c44d1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,9 +1,7 @@ [metadata] classifiers = License :: OSI Approved - License :: OSI Approved :: BSD 1-clause Intended Audience :: Web Developers - Operating System :: Microsoft :: Windows Operating System :: POSIX :: BSD :: FreeBSD Operating System :: POSIX :: Linux Programming Language :: Python :: 3 :: Only @@ -15,28 +13,26 @@ classifiers = Programming Language :: Python :: 3.11 Programming Language :: Python :: Implementation :: CPython Framework :: AsyncIO -description='Tox ctypes wrapping into Python', -long_description='Tox ctypes wrapping of c-toxcore into Python3', -url='https://git.plastiras.org/emdee/toxygen_wrapper/', -keywords='ctypes Tox messenger', -author='Ingvar', - +description='Tox ctypes wrapping into Python' +long_description='Tox ctypes wrapping of c-toxcore into Python3' +url='https://git.plastiras.org/emdee/toxygen_wrapper/' +keywords='ctypes Tox messenger' + [options] zip_safe = false -python_requires = ~=3.6 +#python_requires = >=3.6 include_package_data = false -install_requires = - ctypes package_dir= =src -packages=find: +packages = ["tox_wrapper", "tox_wrapper.tests"] + [options.packages.find] where=src [options.entry_points] console_scripts = - tox_wrapper_tests = tox_wrapper.tests_wrapper:main + tox_wrapper_tests = tox_wrapper.tests.tests_wrapper:main [easy_install] zip_ok = false diff --git a/setup.py b/setup.py index 24616a2..43d00e8 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ setup(name='tox_wrapper', maintainer='', license='GPL3', packages=['tox_wrapper'], - install_requires=[], + install_requires=['ctypes'], include_package_data=True, # dont run directly if you need a proxy # run python3 tox_wrapper/tests/tests_wrapper.py --help diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..2b8d997 --- /dev/null +++ b/src/__init__.py @@ -0,0 +1,5 @@ +# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*- +# You need a libs directory beside this directory +# and you need to link your libtoxcore.so and libtoxav.so +# and libtoxencryptsave.so into ../libs/ +# Link all 3 to libtoxcore.so if you have only libtoxcore.so diff --git a/src/tox_wrapper/__init__.py b/src/tox_wrapper/__init__.py index 2b8d997..c03bf1f 100644 --- a/src/tox_wrapper/__init__.py +++ b/src/tox_wrapper/__init__.py @@ -3,3 +3,5 @@ # and you need to link your libtoxcore.so and libtoxav.so # and libtoxencryptsave.so into ../libs/ # Link all 3 to libtoxcore.so if you have only libtoxcore.so + +__version__ = "1.0.0" diff --git a/src/tox_wrapper/tests/tests_wrapper.py b/src/tox_wrapper/tests/tests_wrapper.py index 3677f7f..7981dd2 100644 --- a/src/tox_wrapper/tests/tests_wrapper.py +++ b/src/tox_wrapper/tests/tests_wrapper.py @@ -53,7 +53,7 @@ try: except ImportError: pycurl = None -from pyannotate_runtime import collect_types +# from pyannotate_runtime import collect_types try: import coloredlogs @@ -112,7 +112,7 @@ else: ADDR_SIZE = 38 * 2 CLIENT_ID_SIZE = 32 * 2 -THRESHOLD = 35 # >25 +THRESHOLD = 60 # >25 iN = 6 global oTOX_OPTIONS @@ -264,9 +264,6 @@ def prepare(self): alice.callback_self_connection_status(alices_on_self_connection_status) # only bob logs trace_enabled - if oTOX_OARGS.trace_enabled: - LOG.warning(f"oTOX_OARGS.trace_enabled={oTOX_OARGS.trace_enabled}") - oTOX_OARGS.trace_enabled = False if oTOX_OARGS.trace_enabled: LOG.info(f"toxcore trace_enabled") ts.vAddLoggerCallback(opts) @@ -570,7 +567,7 @@ class ToxSuite(unittest.TestCase): self.loop(100) i += 1 else: - LOG.warning(f"wait_otox_attrs i >= {THRESHOLD} results={[getattr(obj, attr) for attr in attrs]}") + LOG.warning(f"wait_otox_attrs i >= {THRESHOLD} attrs={attrs} results={[getattr(obj, attr) for attr in attrs]}") return all([getattr(obj, attr) for attr in attrs]) @@ -693,7 +690,7 @@ class ToxSuite(unittest.TestCase): assert inum >= 0, f"bob_add_alice_as_friend !>= 0 {inum}" self.alice.callback_friend_request(alices_on_friend_request) if not self.wait_otox_attrs(self.bob, [sSlot]): - LOG_WARN(f"bob_add_alice_as_friend NO {sSlot}") + LOG_WARN(f"bob_add_alice_as_friend NO setting {sSlot}") # return False self.baid = self.bob.friend_by_public_key(self.alice._address) assert self.baid >= 0, self.baid @@ -1106,6 +1103,7 @@ class ToxSuite(unittest.TestCase): LOG.warning(f"bootstrap_local NOT CONNECTED iStatus={iStatus}") return False + @unittest.skipIf(os.geteuid() != 0, 'must be root') def test_bootstrap_iNmapInfo(self) -> None: # works # if os.environ['USER'] != 'root': # return @@ -1295,6 +1293,9 @@ class ToxSuite(unittest.TestCase): self.alice.friend_delete(self.abid) assert len(self.alice.self_get_friend_list()) == 0 + def test_loop_until_connected(self) -> None: # works + assert self.loop_until_connected() + def test_bob_add_alice_as_friend_and_status(self) -> None: """ t:friend_delete @@ -1313,9 +1314,6 @@ class ToxSuite(unittest.TestCase): if hasattr(self, 'abid') and self.abid >= 0: self.alice.friend_delete(self.abid) - def test_loop_until_connected(self) -> None: # works - assert self.loop_until_connected() - def test_bob_assert_connection_status(self) -> None: # works if self.bob.self_get_connection_status() == TOX_CONNECTION['NONE']: AssertionError("ERROR: NOT CONNECTED " \ diff --git a/src/tox_wrapper/toxygen_echo.py b/src/tox_wrapper/toxygen_echo.py index 4f43939..e35b887 100644 --- a/src/tox_wrapper/toxygen_echo.py +++ b/src/tox_wrapper/toxygen_echo.py @@ -447,4 +447,10 @@ def main(lArgs=None) -> int: return iMain(oArgs) if __name__ == '__main__': - sys.exit(main(sys.argv[1:])) + try: + i = main(sys.argv[1:]) + except KeyboardInterrupt as e: + i = 0 + except Exception as e: + i = 1 + sys.exit(i)