From f8f4fc4fae6ecd429f9221abaae780530f701553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Mon, 30 Dec 2019 20:40:20 +0100 Subject: [PATCH] daemon cleaned up --- .codeclimate.yml | 8 +++---- .travis.yml | 22 +++++++++---------- docs/conf.py | 2 +- docs/configuration/schema.rst | 8 +++---- satella/coding/concurrent/thread.py | 3 +-- satella/posix/__init__.py | 6 ++--- satella/posix/daemon.py | 1 - setup.cfg | 12 +++++----- setup.py | 1 + tests/test_coding/test_concurrent.py | 8 +++---- tests/test_coding/test_fun_static.py | 3 --- tests/test_coding/test_locked_dataset.py | 2 +- tests/test_coding/test_monitor.py | 3 +-- tests/test_coding/test_rethrow.py | 5 ++++- tests/test_coding/test_structures.py | 2 +- .../test_sources/test_envvars.py | 2 +- .../test_configuration/test_sources/utils.py | 2 +- .../test_dump_frames_on.py | 7 +++--- .../test_dump_to_file.py | 2 +- tests/test_instrumentation/test_metrics.py | 5 ++--- tests/test_json.py | 4 ++-- tests/test_posix/test_suicide.py | 2 +- 22 files changed, 52 insertions(+), 58 deletions(-) diff --git a/.codeclimate.yml b/.codeclimate.yml index f1423473..fbc1ad6f 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -14,9 +14,9 @@ engines: radon: enabled: true exclude_paths: -- examples/** -- tests/** -- docs/** + - examples/** + - tests/** + - docs/** ratings: paths: - - satella/** + - satella/** diff --git a/.travis.yml b/.travis.yml index c2b7c8e8..10d38d2f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,17 +1,17 @@ language: python python: - - "3.5" - - "3.6" - - "3.7-dev" - - "pypy3.5" + - "3.5" + - "3.6" + - "3.7-dev" + - "pypy3.5" cache: pip install: - - pip install -r requirements.txt - - pip install pyyaml toml - - pip install --force-reinstall "coverage>=4.0,<4.4" codeclimate-test-reporter # for codeclimate-test-reporter + - pip install -r requirements.txt + - pip install pyyaml toml + - pip install --force-reinstall "coverage>=4.0,<4.4" codeclimate-test-reporter # for codeclimate-test-reporter script: - - bash tests/test_posix/test_hang_until_sig.sh - - python setup.py nosetests + - bash tests/test_posix/test_hang_until_sig.sh + - python setup.py nosetests after_success: - - codeclimate-test-reporter - - bash build.sh + - codeclimate-test-reporter + - bash build.sh diff --git a/docs/conf.py b/docs/conf.py index 1cf4c7e4..11f33543 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,8 +18,8 @@ # import os import sys -sys.path.insert(0, os.path.abspath('..')) +sys.path.insert(0, os.path.abspath('..')) # -- General configuration ------------------------------------------------ diff --git a/docs/configuration/schema.rst b/docs/configuration/schema.rst index 30ca9306..201924bd 100644 --- a/docs/configuration/schema.rst +++ b/docs/configuration/schema.rst @@ -80,7 +80,7 @@ Lists you define as following { "type": "list", "of": { - .. descriptor type that this list has to have .. + ".. descriptor type that this list has to have .." } } @@ -91,9 +91,9 @@ Unions you define the following { "type": "union", "of": [ - .. descriptor type 1 .. - .. descriptor type 2 .. - ] + ".. descriptor type 1 ..", + ".. descriptor type 2 .." + ] } Dicts are more simple. Each key contains the key that should be present in the dict, and value is it's descriptor diff --git a/satella/coding/concurrent/thread.py b/satella/coding/concurrent/thread.py index 8c34fce6..11637555 100644 --- a/satella/coding/concurrent/thread.py +++ b/satella/coding/concurrent/thread.py @@ -1,8 +1,7 @@ import ctypes import logging -import threading import platform - +import threading logger = logging.getLogger(__name__) diff --git a/satella/posix/__init__.py b/satella/posix/__init__.py index 88c5ed05..e12466b6 100644 --- a/satella/posix/__init__.py +++ b/satella/posix/__init__.py @@ -3,12 +3,12 @@ POSIX things """ import os +import typing as tp from .daemon import daemonize from .pidlock import AcquirePIDLock from .signals import hang_until_sig - __all__ = [ 'daemonize', 'AcquirePIDLock', @@ -18,7 +18,7 @@ __all__ = [ ] -def is_running_as_root(): +def is_running_as_root() -> bool: """ Is this process running as root? @@ -29,7 +29,7 @@ def is_running_as_root(): return os.geteuid() == 0 -def suicide(kill_entire_pg: bool = True): +def suicide(kill_entire_pg: bool = True) -> tp.NoReturn: """ Kill self. diff --git a/satella/posix/daemon.py b/satella/posix/daemon.py index 69d81a02..9cd23d1a 100644 --- a/satella/posix/daemon.py +++ b/satella/posix/daemon.py @@ -19,7 +19,6 @@ logger = logging.getLogger(__name__) DEVNULL = '/dev/null' - __all__ = ['daemonize'] diff --git a/setup.cfg b/setup.cfg index dc321ce6..bbd44019 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,7 +11,7 @@ description = Utilities for writing servers in Python url = https://github.com/piotrmaslanka/satella project-urls = Documentation = https://satella.readthedocs.io/ -classifier = +classifier = Programming Language :: Python Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 @@ -25,12 +25,12 @@ classifier = Topic :: Software Development :: Libraries [pycodestyle] -max-line-length=80 +max-line-length = 80 [bdist_wheel] -universal=1 +universal = 1 [nosetests] -verbosity=3 -with-coverage=1 -detailed-errors=1 +verbosity = 3 +with-coverage = 1 +detailed-errors = 1 diff --git a/setup.py b/setup.py index ca783931..594a2324 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ # coding=UTF-8 from setuptools import setup, find_packages + from satella import __version__ setup(keywords=['ha', 'high availability', 'scalable', 'scalability', 'server'], diff --git a/tests/test_coding/test_concurrent.py b/tests/test_coding/test_concurrent.py index bf85713d..d3b967cf 100644 --- a/tests/test_coding/test_concurrent.py +++ b/tests/test_coding/test_concurrent.py @@ -1,8 +1,9 @@ # coding=UTF-8 from __future__ import print_function, absolute_import, division -import unittest -import time + import platform +import time +import unittest from satella.coding.concurrent import TerminableThread, CallableGroup @@ -20,7 +21,6 @@ class TestCallableGroup(unittest.TestCase): @unittest.skipIf(platform.python_implementation() == 'PyPy', 'force=True doesn''t work on PyPy') def test_terminable_thread_force(self): - class MyTerminableThread(TerminableThread): def run(self): a = 0 @@ -47,7 +47,6 @@ class TestCallableGroup(unittest.TestCase): self.assertIsInstance(cg()[0], NameError) def test_callable_group(self): - a = { 'a': False, 'b': False @@ -63,4 +62,3 @@ class TestCallableGroup(unittest.TestCase): cg() self.assertTrue(all(a.values())) - diff --git a/tests/test_coding/test_fun_static.py b/tests/test_coding/test_fun_static.py index c3bd9e7d..fe95595b 100644 --- a/tests/test_coding/test_fun_static.py +++ b/tests/test_coding/test_fun_static.py @@ -1,7 +1,4 @@ import unittest -from threading import Thread -from time import sleep -from queue import Queue from satella.coding import static_var diff --git a/tests/test_coding/test_locked_dataset.py b/tests/test_coding/test_locked_dataset.py index 1bb1c4d6..d4e64e4e 100644 --- a/tests/test_coding/test_locked_dataset.py +++ b/tests/test_coding/test_locked_dataset.py @@ -26,4 +26,4 @@ class TestLockedDataset(unittest.TestCase): with a: self.assertEquals(a.counter, 1) - self.assertRaises(ResourceNotLocked, lambda: a.counter) \ No newline at end of file + self.assertRaises(ResourceNotLocked, lambda: a.counter) diff --git a/tests/test_coding/test_monitor.py b/tests/test_coding/test_monitor.py index ea8dbe18..b27934a4 100644 --- a/tests/test_coding/test_monitor.py +++ b/tests/test_coding/test_monitor.py @@ -1,9 +1,8 @@ import unittest +from queue import Queue from threading import Thread from time import sleep -from queue import Queue - from satella.coding import Monitor diff --git a/tests/test_coding/test_rethrow.py b/tests/test_coding/test_rethrow.py index 6784e060..d7753be6 100644 --- a/tests/test_coding/test_rethrow.py +++ b/tests/test_coding/test_rethrow.py @@ -1,6 +1,8 @@ # coding=UTF-8 from __future__ import print_function, absolute_import, division + import unittest + from satella.coding import rethrow_as, silence_excs @@ -43,6 +45,7 @@ class TestStuff(unittest.TestCase): def test_issue_10(self): class WTFException1(Exception): pass + class WTFException2(Exception): pass @rethrow_as((NameError, WTFException1), @@ -55,7 +58,7 @@ class TestStuff(unittest.TestCase): def test_issue_14a(self): - @rethrow_as(*(((NameError, ValueError), TypeError), )) + @rethrow_as(*(((NameError, ValueError), TypeError),)) def ro(p): raise p() diff --git a/tests/test_coding/test_structures.py b/tests/test_coding/test_structures.py index 70369268..969072cd 100644 --- a/tests/test_coding/test_structures.py +++ b/tests/test_coding/test_structures.py @@ -6,9 +6,9 @@ import unittest import mock +from satella.coding.concurrent import CallableGroup from satella.coding.structures import TimeBasedHeap, Heap, typednamedtuple, \ OmniHashableMixin, DictObject, apply_dict_object -from satella.coding.concurrent import CallableGroup class TestCallableGroup(unittest.TestCase): diff --git a/tests/test_configuration/test_sources/test_envvars.py b/tests/test_configuration/test_sources/test_envvars.py index d6b6b98f..66a22444 100644 --- a/tests/test_configuration/test_sources/test_envvars.py +++ b/tests/test_configuration/test_sources/test_envvars.py @@ -24,4 +24,4 @@ class TestEnvVarsSource(SourceTestCase): EnvironmentSource('test', 'test'), on_fail=MergingSource.SILENT ) - self.assertEquals(ds.provide(), {}) \ No newline at end of file + self.assertEquals(ds.provide(), {}) diff --git a/tests/test_configuration/test_sources/utils.py b/tests/test_configuration/test_sources/utils.py index 83a36f57..f6b130ec 100644 --- a/tests/test_configuration/test_sources/utils.py +++ b/tests/test_configuration/test_sources/utils.py @@ -1,7 +1,7 @@ import functools import os -import unittest import typing as tp +import unittest from satella.configuration.sources import BaseSource from satella.exceptions import ConfigurationError diff --git a/tests/test_exception_handling/test_dump_frames_on.py b/tests/test_exception_handling/test_dump_frames_on.py index 6e8a1531..921338a9 100644 --- a/tests/test_exception_handling/test_dump_frames_on.py +++ b/tests/test_exception_handling/test_dump_frames_on.py @@ -1,10 +1,9 @@ import logging -import typing as tp -import unittest -import os -import signal import sys +import unittest + from satella.instrumentation.dump_frames_on import dump_frames_on + logger = logging.getLogger(__name__) diff --git a/tests/test_exception_handling/test_dump_to_file.py b/tests/test_exception_handling/test_dump_to_file.py index 728953a6..604211e3 100644 --- a/tests/test_exception_handling/test_dump_to_file.py +++ b/tests/test_exception_handling/test_dump_to_file.py @@ -23,7 +23,7 @@ class TestDumpToFile(ExceptionHandlingTestCase): def test_dump_to_file(self): try: def makeexc(): - print(hello) # raises NameError + print(hello) # raises NameError self.make_exception(makeexc) diff --git a/tests/test_instrumentation/test_metrics.py b/tests/test_instrumentation/test_metrics.py index f62011f5..b9bb067a 100644 --- a/tests/test_instrumentation/test_metrics.py +++ b/tests/test_instrumentation/test_metrics.py @@ -1,6 +1,6 @@ -import unittest import time -import typing as tp +import unittest + from satella.instrumentation.metrics import getMetric, DEBUG, RUNTIME, INHERIT @@ -83,4 +83,3 @@ class TestMetric(unittest.TestCase): self.assertEquals(metric.to_json(), [2, 2]) time.sleep(1.2) self.assertEquals(metric.to_json(), [0, 2]) - diff --git a/tests/test_json.py b/tests/test_json.py index 19f47820..e5dd90c1 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -1,12 +1,12 @@ -import unittest import typing as tp +import unittest + from satella.json import JSONAble, json_encode class TestJson(unittest.TestCase): def test_jsonable_objects(self): - class MyClass(JSONAble): def to_json(self) -> tp.Union[list, dict, str, int, float, None]: return [] diff --git a/tests/test_posix/test_suicide.py b/tests/test_posix/test_suicide.py index a7354ca3..580dfee9 100644 --- a/tests/test_posix/test_suicide.py +++ b/tests/test_posix/test_suicide.py @@ -2,10 +2,10 @@ from __future__ import print_function, absolute_import, division import os +import sys import unittest from satella.posix import suicide -import sys class TestSuicide(unittest.TestCase): -- GitLab