Skip to content

Commit b8f2cd3

Browse files
authored
Remove support for Windows (#106)
1 parent 6a3a7a6 commit b8f2cd3

File tree

5 files changed

+23
-46
lines changed

5 files changed

+23
-46
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
not provided by Python.
99

1010
- [transparent Unicode support for text file operations (BOM detection)](https://tendo.readthedocs.io/#module-tendo.singleton)
11-
- enable you to use symlinks under windows
1211
- python tee implementation
1312
- [improved execfile](https://tendo.readthedocs.io/#module-tendo.execfile2)
1413

1514
## Requirements and Compatibility
1615

16+
- POSIX-compatible operating system, including Linux and macOS
1717
- python 3.10 or newer
1818
- tox for running tests
1919

pyproject.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ classifiers = [
2222
"Intended Audience :: Information Technology",
2323
"Intended Audience :: System Administrators",
2424
"License :: OSI Approved :: Python Software Foundation License",
25-
"Operating System :: OS Independent",
25+
"Operating System :: MacOS",
26+
"Operating System :: POSIX :: Linux",
27+
"Operating System :: POSIX",
2628
"Programming Language :: Python :: 3",
2729
"Programming Language :: Python :: 3.10",
2830
"Programming Language :: Python :: 3.11",

src/tendo/singleton.py

+12-34
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#! /usr/bin/env python
22

3+
import fcntl
34
import logging
45
import os
56
import sys
67
import tempfile
78

8-
if sys.platform != "win32":
9-
import fcntl
10-
119

1210
class SingleInstanceException(BaseException):
1311
pass
@@ -46,28 +44,13 @@ def __init__(self, flavor_id="", lockfile=""):
4644
logger.debug(f"SingleInstance lockfile: {self.lockfile}")
4745

4846
def __enter__(self):
49-
if sys.platform == "win32":
50-
try:
51-
# file already exists, we try to remove (in case previous
52-
# execution was interrupted)
53-
if os.path.exists(self.lockfile):
54-
os.unlink(self.lockfile)
55-
self.fd = os.open(self.lockfile, os.O_CREAT | os.O_EXCL | os.O_RDWR)
56-
except OSError:
57-
type, e, tb = sys.exc_info()
58-
if e.errno == 13:
59-
logger.error("Another instance is already running, quitting.")
60-
raise SingleInstanceException
61-
print(e.errno)
62-
raise
63-
else: # non Windows
64-
self.fp = open(self.lockfile, "w")
65-
self.fp.flush()
66-
try:
67-
fcntl.lockf(self.fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
68-
except OSError:
69-
logger.warning("Another instance is already running, quitting.")
70-
raise SingleInstanceException
47+
self.fp = open(self.lockfile, "w")
48+
self.fp.flush()
49+
try:
50+
fcntl.lockf(self.fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
51+
except OSError:
52+
logger.warning("Another instance is already running, quitting.")
53+
raise SingleInstanceException
7154
self.initialized = True
7255
return self
7356

@@ -77,15 +60,10 @@ def __exit__(self, exc_type, exc_value, exc_tb):
7760
if exc_value is not None:
7861
logger.warning("Error: %s" % exc_value, exc_info=True)
7962
try:
80-
if sys.platform == "win32":
81-
if hasattr(self, "fd"):
82-
os.close(self.fd)
83-
os.unlink(self.lockfile)
84-
else:
85-
fcntl.lockf(self.fp, fcntl.LOCK_UN)
86-
# os.close(self.fp)
87-
if os.path.isfile(self.lockfile):
88-
os.unlink(self.lockfile)
63+
fcntl.lockf(self.fp, fcntl.LOCK_UN)
64+
# os.close(self.fp)
65+
if os.path.isfile(self.lockfile):
66+
os.unlink(self.lockfile)
8967
except Exception as e:
9068
if logger:
9169
logger.warning(e)

src/tendo/tee.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ def quote_command(cmd):
3030
3131
This is required in order to prevent getting "The input line is too long" error message.
3232
"""
33-
if not (os.name == "nt" or os.name == "dos"):
34-
# the escaping is required only on Windows platforms, in fact it will
35-
# break cmd line on others
36-
return cmd
3733
if '"' in cmd[1:-1]:
3834
cmd = '"' + cmd + '"'
3935
return cmd
@@ -247,13 +243,13 @@ def test_1(self):
247243
os.name = save
248244

249245
def test_2(self):
250-
self.assertEqual(system(["python", "-V"]), 0)
246+
self.assertEqual(system([sys.executable, "-V"]), 0)
251247

252248
def test_3(self):
253-
self.assertEqual(system2(["python", "-V"])[0], 0)
249+
self.assertEqual(system2([sys.executable, "-V"])[0], 0)
254250

255251
def test_4(self):
256-
self.assertEqual(system(["python", "-c", "print('c c')"]), 0)
252+
self.assertEqual(system([sys.executable, "-c", "print('c c')"]), 0)
257253

258254

259255
if __name__ == "__main__":

src/tendo/tests/test_tee.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import sys
23

34
from tendo.tee import quote_command, system, system2
45

@@ -36,12 +37,12 @@ def test_1():
3637

3738

3839
def test_2():
39-
assert system(["python", "-V"]) == 0
40+
assert system([sys.executable, "-V"]) == 0
4041

4142

4243
def test_3():
43-
assert system2(["python", "-V"])[0] == 0
44+
assert system2([sys.executable, "-V"])[0] == 0
4445

4546

4647
def test_4():
47-
assert system(["python", "-c", "print('c c')"]) == 0
48+
assert system([sys.executable, "-c", "print()"]) == 0

0 commit comments

Comments
 (0)