From 1b93cb0c5ec57c4041dc53c9e2e608da41423e8b Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Mon, 11 Nov 2024 17:10:10 +0000 Subject: [PATCH] Remove support for Windows If anyone wants to bring back support for Windows, they should start nu adding github pipelines for testing it. --- README.md | 2 +- pyproject.toml | 4 +++- src/tendo/singleton.py | 46 ++++++++++--------------------------- src/tendo/tee.py | 10 +++----- src/tendo/tests/test_tee.py | 7 +++--- 5 files changed, 23 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index a980e59..d65e4da 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,12 @@ not provided by Python. - [transparent Unicode support for text file operations (BOM detection)](https://tendo.readthedocs.io/#module-tendo.singleton) -- enable you to use symlinks under windows - python tee implementation - [improved execfile](https://tendo.readthedocs.io/#module-tendo.execfile2) ## Requirements and Compatibility +- POSIX-compatible operating system, including Linux and macOS - python 3.10 or newer - tox for running tests diff --git a/pyproject.toml b/pyproject.toml index c1974ad..6c94201 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,9 @@ classifiers = [ "Intended Audience :: Information Technology", "Intended Audience :: System Administrators", "License :: OSI Approved :: Python Software Foundation License", - "Operating System :: OS Independent", + "Operating System :: MacOS", + "Operating System :: POSIX :: Linux", + "Operating System :: POSIX", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", diff --git a/src/tendo/singleton.py b/src/tendo/singleton.py index ea9bfae..6ffaadb 100755 --- a/src/tendo/singleton.py +++ b/src/tendo/singleton.py @@ -1,13 +1,11 @@ #! /usr/bin/env python +import fcntl import logging import os import sys import tempfile -if sys.platform != "win32": - import fcntl - class SingleInstanceException(BaseException): pass @@ -46,28 +44,13 @@ def __init__(self, flavor_id="", lockfile=""): logger.debug(f"SingleInstance lockfile: {self.lockfile}") def __enter__(self): - if sys.platform == "win32": - try: - # file already exists, we try to remove (in case previous - # execution was interrupted) - if os.path.exists(self.lockfile): - os.unlink(self.lockfile) - self.fd = os.open(self.lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR) - except OSError: - type, e, tb = sys.exc_info() - if e.errno == 13: - logger.error("Another instance is already running, quitting.") - raise SingleInstanceException - print(e.errno) - raise - else: # non Windows - self.fp = open(self.lockfile, "w") - self.fp.flush() - try: - fcntl.lockf(self.fp, fcntl.LOCK_EX | fcntl.LOCK_NB) - except OSError: - logger.warning("Another instance is already running, quitting.") - raise SingleInstanceException + self.fp = open(self.lockfile, "w") + self.fp.flush() + try: + fcntl.lockf(self.fp, fcntl.LOCK_EX | fcntl.LOCK_NB) + except OSError: + logger.warning("Another instance is already running, quitting.") + raise SingleInstanceException self.initialized = True return self @@ -77,15 +60,10 @@ def __exit__(self, exc_type, exc_value, exc_tb): if exc_value is not None: logger.warning("Error: %s" % exc_value, exc_info=True) try: - if sys.platform == "win32": - if hasattr(self, "fd"): - os.close(self.fd) - os.unlink(self.lockfile) - else: - fcntl.lockf(self.fp, fcntl.LOCK_UN) - # os.close(self.fp) - if os.path.isfile(self.lockfile): - os.unlink(self.lockfile) + fcntl.lockf(self.fp, fcntl.LOCK_UN) + # os.close(self.fp) + if os.path.isfile(self.lockfile): + os.unlink(self.lockfile) except Exception as e: if logger: logger.warning(e) diff --git a/src/tendo/tee.py b/src/tendo/tee.py index a05801f..0b8e303 100755 --- a/src/tendo/tee.py +++ b/src/tendo/tee.py @@ -30,10 +30,6 @@ def quote_command(cmd): This is required in order to prevent getting "The input line is too long" error message. """ - if not (os.name == "nt" or os.name == "dos"): - # the escaping is required only on Windows platforms, in fact it will - # break cmd line on others - return cmd if '"' in cmd[1:-1]: cmd = '"' + cmd + '"' return cmd @@ -247,13 +243,13 @@ def test_1(self): os.name = save def test_2(self): - self.assertEqual(system(["python", "-V"]), 0) + self.assertEqual(system([sys.executable, "-V"]), 0) def test_3(self): - self.assertEqual(system2(["python", "-V"])[0], 0) + self.assertEqual(system2([sys.executable, "-V"])[0], 0) def test_4(self): - self.assertEqual(system(["python", "-c", "print('c c')"]), 0) + self.assertEqual(system([sys.executable, "-c", "print('c c')"]), 0) if __name__ == "__main__": diff --git a/src/tendo/tests/test_tee.py b/src/tendo/tests/test_tee.py index 211ed6b..597012d 100644 --- a/src/tendo/tests/test_tee.py +++ b/src/tendo/tests/test_tee.py @@ -1,4 +1,5 @@ import os +import sys from tendo.tee import quote_command, system, system2 @@ -36,12 +37,12 @@ def test_1(): def test_2(): - assert system(["python", "-V"]) == 0 + assert system([sys.executable, "-V"]) == 0 def test_3(): - assert system2(["python", "-V"])[0] == 0 + assert system2([sys.executable, "-V"])[0] == 0 def test_4(): - assert system(["python", "-c", "print('c c')"]) == 0 + assert system([sys.executable, "-c", "print()"]) == 0