Skip to content

Commit 5034531

Browse files
Remove python2 support (#64)
* Set minimum supported python to 3.6 * Remove all version checking for version <3.6 * Add autoformatting to VSCode on save action
1 parent d83ecbf commit 5034531

File tree

10 files changed

+33
-87
lines changed

10 files changed

+33
-87
lines changed

.github/workflows/code.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@ jobs:
2727
fail-fast: false
2828
matrix:
2929
os: [ubuntu-latest, windows-latest, macos-latest]
30-
python: [cp27, cp36, cp37, cp38, cp39]
31-
32-
exclude:
33-
# No cothread or asyncio for windows python 2.7 so doesn't work
34-
- os: windows-latest
35-
python: cp27
30+
python: [cp36, cp37, cp38, cp39]
3631

3732
include:
3833
# Put coverage in the project directory for mac

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
"python.testing.unittestEnabled": false,
88
"python.testing.pytestEnabled": true,
99
"python.languageServer": "Pylance",
10+
"files.trimTrailingWhitespace": true,
11+
"files.trimFinalNewlines": true,
1012
}

CHANGELOG.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0
99
Unreleased_
1010
-----------
1111

12-
Nothing yet
12+
Changed:
13+
14+
- `Remove python2 support <../../pull/64>`
1315

1416
3.2.1_ - 2021-11-25
1517
-------------------
@@ -20,7 +22,7 @@ Changed:
2022

2123
Added:
2224

23-
- Provide logging for exceptions raised in callbacks
25+
- Provide logging for exceptions raised in callbacks
2426

2527
Fixed:
2628

setup.cfg

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ long_description_content_type = text/x-rst
1010
classifiers =
1111
Development Status :: 5 - Production/Stable
1212
License :: OSI Approved :: Apache Software License
13-
Programming Language :: Python :: 2.7
13+
Programming Language :: Python :: 3.6
1414
Programming Language :: Python :: 3.7
1515
Programming Language :: Python :: 3.8
1616
Programming Language :: Python :: 3.9
1717

1818
[options]
1919
packages = softioc
20-
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*
20+
python_requires = >=3.6
2121

2222
[options.entry_points]
2323
# Include a command line script
@@ -39,11 +39,11 @@ useful =
3939
aioca >=1.3
4040
# Dev and docs dependencies
4141
dev =
42-
pytest-cov
42+
pytest-cov
4343
pytest-flake8
44-
sphinx-rtd-theme-github-versions; python_version > "3.0"
45-
pytest-asyncio; python_version > "3.0"
46-
aioca >=1.3 ; python_version > "3.0"
44+
sphinx-rtd-theme-github-versions
45+
pytest-asyncio
46+
aioca >=1.3
4747
cothread; sys_platform != "win32"
4848
p4p
4949

@@ -57,8 +57,8 @@ extend-ignore =
5757
[tool:pytest]
5858
# Run pytest with all our checkers, and don't spam us with massive tracebacks on error
5959
# Don't do flake8 here as we need to separate it out for CI
60-
addopts =
61-
--tb=native -vv --doctest-modules --ignore=iocStats --ignore=epicscorelibs --ignore=docs
60+
addopts =
61+
--tb=native -vv --doctest-modules --ignore=iocStats --ignore=epicscorelibs --ignore=docs
6262
--cov=softioc --cov-report term --cov-report xml:cov.xml
6363

6464
[coverage:run]

softioc/device_core.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ class DSET(DSET_BASE):
124124
setattr(dset, method_name, callback)
125125

126126
# Hang onto the values we publish to EPICS to ensure that they persist!
127-
# We also need to ensure that the device name persits.
127+
# We also need to ensure that the device name persists.
128128
cls.__dset = dset
129-
if sys.version_info >= (3,):
130-
cls._device_name_ = cls._device_name_.encode()
129+
cls._device_name_ = cls._device_name_.encode()
131130
imports.registryDeviceSupportAdd(cls._device_name_, byref(cls.__dset))
132131

133132

softioc/extension.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313
#include <asTrapWrite.h>
1414
#include <asDbLib.h>
1515

16-
/* In Python3 this function has been renamed. */
17-
#if PY_MAJOR_VERSION >= 3
18-
#define PyInt_FromLong(value) PyLong_FromLong(value)
19-
#endif
20-
2116
/* Reference stealing version of PyDict_SetItemString */
2217
static void set_dict_item_steal(
2318
PyObject *dict, const char *name, PyObject *py_value)
@@ -28,7 +23,7 @@ static void set_dict_item_steal(
2823

2924
/* Helper for function below. */
3025
#define ADD_ENUM(dict, name) \
31-
set_dict_item_steal(dict, #name, PyInt_FromLong(name))
26+
set_dict_item_steal(dict, #name, PyLong_FromLong(name))
3227

3328
/* Alas, EPICS has changed the numerical assignments of the DBF_ enums between
3429
* versions, so to avoid unpleasant surprises, we compute thes values here in C
@@ -226,27 +221,16 @@ static struct PyMethodDef softioc_methods[] = {
226221
{NULL, NULL, 0, NULL} /* Sentinel */
227222
};
228223

229-
#if PY_MAJOR_VERSION >= 3
224+
230225
static struct PyModuleDef softioc_module = {
231226
PyModuleDef_HEAD_INIT,
232227
"softioc._extension",
233228
NULL,
234229
-1,
235230
softioc_methods,
236231
};
237-
#endif
238-
239-
#if PY_MAJOR_VERSION >= 3
240-
# define PyMOD(NAME) PyObject* PyInit_##NAME (void)
241-
#else
242-
# define PyMOD(NAME) void init##NAME (void)
243-
#endif
244232

245-
PyMOD(_extension)
233+
PyObject *PyInit__extension(void)
246234
{
247-
#if PY_MAJOR_VERSION >= 3
248235
return PyModule_Create(&softioc_module);
249-
#else
250-
Py_InitModule("softioc._extension", softioc_methods);
251-
#endif
252236
}

softioc/fields.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,6 @@
6666
}
6767

6868

69-
if sys.version_info >= (3,):
70-
def decode(string):
71-
return string.decode()
72-
def encode(string):
73-
return string.encode()
74-
else:
75-
def decode(string):
76-
return string
77-
def encode(string):
78-
return string
79-
80-
8169
class RecordFactory(object):
8270
def __init__(self, record_type, fields):
8371
'''Uses the EPICS static database to discover the offset in the record
@@ -110,9 +98,9 @@ def __getattr__(self, field):
11098
if field == 'TIME':
11199
return self.__get_time(address)
112100
elif field_type == DBF_STRING:
113-
return decode(string_at(cast(address, c_char_p)))
101+
return string_at(cast(address, c_char_p)).decode()
114102
elif field_type in [DBF_INLINK, DBF_OUTLINK]:
115-
return decode(cast(address, POINTER(c_char_p))[0])
103+
return cast(address, POINTER(c_char_p))[0].decode()
116104
else:
117105
ctypes_type = DbfCodeToCtypes[field_type]
118106
return cast(address, POINTER(ctypes_type))[0]
@@ -124,7 +112,7 @@ def __setattr__(self, field, value):
124112
if field == 'TIME':
125113
self.__set_time(address, value)
126114
elif field_type == DBF_STRING:
127-
value = encode(str(value))
115+
value = str(value).encode()
128116
buffer = create_string_buffer(value)
129117
if size > len(value) + 1:
130118
size = len(value) + 1

softioc/imports.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,15 @@ def expect_true(status, function, args):
3434
assert status, 'Expected True'
3535

3636

37-
if sys.version_info < (3,):
38-
# Python 2
39-
auto_encode = c_char_p
40-
def auto_decode(result, func, args):
41-
return result
42-
43-
else:
44-
# Python 3
45-
46-
# Encode all strings to c_char_p
47-
class auto_encode(c_char_p):
48-
encoded = []
49-
@classmethod
50-
def from_param(cls, value):
51-
if value is None:
52-
return value
53-
else:
54-
return value.encode()
55-
56-
def auto_decode(result, func, args):
57-
return result.decode()
37+
38+
# Encode all strings to c_char_p
39+
class auto_encode(c_char_p):
40+
@classmethod
41+
def from_param(cls, value):
42+
if value is None:
43+
return value
44+
else:
45+
return value.encode()
5846

5947

6048
# int registryDeviceSupportAdd(

softioc/softioc.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,14 +310,8 @@ def interactive_ioc(context = {}, call_exit = True):
310310
exports = dict((key, globals()[key]) for key in command_names)
311311
import code
312312

313-
if sys.version_info < (3, 6):
314-
interact_args = {}
315-
else:
316-
# This suppresses irritating exit message introduced by Python3. Alas,
317-
# this option is only available in Python 3.6!
318-
interact_args = dict(exitmsg = '')
319313
try:
320-
code.interact(local = dict(exports, **context), **interact_args)
314+
code.interact(local = dict(exports, **context), exitmsg = '')
321315
except SystemExit as e:
322316
if call_exit:
323317
safeEpicsExit(e.code)

tests/conftest.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77

88
import pytest
99

10-
if sys.version_info < (3,):
11-
# Python2 has no asyncio, so ignore these tests
12-
collect_ignore = [
13-
"test_asyncio.py", "sim_asyncio_ioc.py", "sim_asyncio_ioc_override.py"
14-
]
15-
1610
class SubprocessIOC:
1711
def __init__(self, ioc_py):
1812
self.pv_prefix = "".join(

0 commit comments

Comments
 (0)