diff --git a/bin/frappy-cli b/bin/frappy-cli index 3e58120..f6081e9 100755 --- a/bin/frappy-cli +++ b/bin/frappy-cli @@ -24,10 +24,10 @@ import sys import argparse -from os import path +from pathlib import Path # Add import path for inplace usage -sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..'))) +sys.path.insert(0, str(Path(__file__).absolute().parents[1])) from frappy.client.interactive import init, run, clientenv, interact @@ -36,7 +36,7 @@ def parseArgv(argv): parser = argparse.ArgumentParser() parser.add_argument('-i', '--include', help='file to execute after connecting to the clients', metavar='file', - type=str, action='append', default=[]) + type=Path, action='append', default=[]) parser.add_argument('-o', '--only-execute', help='Do not go into interactive mode after executing files. \ Has no effect without --include.', action='store_true') diff --git a/bin/frappy-gui b/bin/frappy-gui index 77eb652..eafb54d 100755 --- a/bin/frappy-gui +++ b/bin/frappy-gui @@ -26,10 +26,10 @@ from __future__ import print_function import sys import argparse -from os import path +from pathlib import Path # Add import path for inplace usage -sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..'))) +sys.path.insert(0, str(Path(__file__).absolute().parents[1])) import logging from mlzlog import ColoredConsoleHandler diff --git a/bin/frappy-play b/bin/frappy-play index 21260f6..4f1767e 100755 --- a/bin/frappy-play +++ b/bin/frappy-play @@ -22,10 +22,10 @@ # ***************************************************************************** import sys -from os import path +from pathlib import Path # Add import path for inplace usage -sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..'))) +sys.path.insert(0, str(Path(__file__).absolute().parents[1])) from frappy.client.interactive import Console from frappy.playground import play, USAGE diff --git a/bin/frappy-server b/bin/frappy-server index d1c5cf9..d5307d0 100755 --- a/bin/frappy-server +++ b/bin/frappy-server @@ -24,10 +24,10 @@ import argparse import sys -from os import path +from pathlib import Path # Add import path for inplace usage -sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..'))) +sys.path.insert(0, str(Path(__file__).absolute().parents[1])) from frappy.lib import generalConfig from frappy.logging import logger diff --git a/bin/sim-server b/bin/sim-server index 5d045cf..217d6ca 100755 --- a/bin/sim-server +++ b/bin/sim-server @@ -34,13 +34,13 @@ Use cases, mainly for test purposes: import sys import argparse -from os import path +from pathlib import Path import asyncore import socket import time # Add import path for inplace usage -sys.path.insert(0, path.abspath(path.join(path.dirname(__file__), '..'))) +sys.path.insert(0, str(Path(__file__).absolute().parents[1])) from frappy.lib import get_class, formatException, mkthread diff --git a/frappy/client/interactive.py b/frappy/client/interactive.py index bec330b..0ae14d0 100644 --- a/frappy/client/interactive.py +++ b/frappy/client/interactive.py @@ -352,7 +352,7 @@ def watch(*args, **kwds): def close_node(online, state): if online and state != 'shutdown': - return + return None close_event.set() return UnregisterCallback @@ -450,7 +450,7 @@ def run(filepath): "__file__": filepath, "__name__": "__main__", }) - with open(filepath, 'rb') as file: + with filepath.open('rb') as file: # pylint: disable=exec-used exec(compile(file.read(), filepath, 'exec'), clientenv.namespace, None) diff --git a/frappy/gui/util.py b/frappy/gui/util.py index 529533d..f4928e4 100644 --- a/frappy/gui/util.py +++ b/frappy/gui/util.py @@ -21,15 +21,15 @@ # ***************************************************************************** -from os import path +from pathlib import Path from frappy.gui.qt import QColor, uic -uipath = path.dirname(__file__) +uipath = Path(__file__).parent def loadUi(widget, uiname, subdir='ui'): - uic.loadUi(path.join(uipath, subdir, uiname), widget) + uic.loadUi(uipath / subdir / uiname, widget) def is_light_theme(palette): diff --git a/frappy/version.py b/frappy/version.py index 45c27ec..4448dd4 100644 --- a/frappy/version.py +++ b/frappy/version.py @@ -21,14 +21,13 @@ # # ***************************************************************************** -import os.path +from pathlib import Path from subprocess import PIPE, Popen __all__ = ['get_version'] -RELEASE_VERSION_FILE = os.path.join(os.path.dirname(__file__), - 'RELEASE-VERSION') -GIT_REPO = os.path.join(os.path.dirname(__file__), '..', '.git') +RELEASE_VERSION_FILE = Path(__file__).parent / 'RELEASE-VERSION' +GIT_REPO = (Path(__file__).parents[1] / '.git').resolve() def translate_version(ver): @@ -49,14 +48,14 @@ def get_git_version(abbrev=4): def read_release_version(): try: - with open(RELEASE_VERSION_FILE, encoding='utf-8') as f: + with RELEASE_VERSION_FILE.open(encoding='utf-8') as f: return f.readline().strip() except Exception: return None def write_release_version(version): - with open(RELEASE_VERSION_FILE, 'w', encoding='utf-8') as f: + with RELEASE_VERSION_FILE.open('w', encoding='utf-8') as f: f.write(f'{version}\n') diff --git a/setup.py b/setup.py index a9ff09f..46007f7 100755 --- a/setup.py +++ b/setup.py @@ -23,19 +23,20 @@ # ***************************************************************************** -from glob import glob -from os import listdir, path +from pathlib import Path from setuptools import find_packages, setup import frappy.version # cfg-editor is currently not functional -scripts = [script for script in glob(path.join('bin', 'frappy-*')) - if not script.endswith('cfg-editor')] +scripts = [str(script) for script in Path('bin').glob('frappy-*') + if not str(script).endswith('cfg-editor')] -uidir = path.join(path.dirname(__file__), 'frappy', 'gui', 'ui') -uis = [path.join('gui', 'ui', entry) for entry in listdir(uidir)] + +frappydir = Path(__file__).parent / 'frappy' +uidir = frappydir / 'gui' / 'ui' +uis = [str(f.relative_to(frappydir)) for f in uidir.iterdir()] setup( name='frappy-core', @@ -57,7 +58,7 @@ setup( ('/lib/systemd/system-generators', ['etc/frappy-generator']), ('/lib/systemd/system', ['etc/frappy@.service', 'etc/frappy.target', - ]), + ]), ('/var/log/frappy', []), ], scripts=scripts,