Skip to content

Commit 1e4c3b8

Browse files
committed
feat: remove the python2 pilot starter
1 parent af37100 commit 1e4c3b8

File tree

6 files changed

+21
-59
lines changed

6 files changed

+21
-59
lines changed

.github/workflows/pilotWrapper.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ jobs:
1111
fail-fast: False
1212
matrix:
1313
python:
14-
- 2.7.5
15-
- 2.7.13
1614
- 3.6.8
1715
- 3.11.4
1816
pilot_branch:

docs/source/UserGuide/GettingStarted/InstallingClient/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Installing DIRAC client
1111
The DIRAC client installation procedure consists of few steps.
1212
You can do these steps as any user without the need to be root.
1313

14-
Python3 DIRAC installations rely on the environment provided by `DIRACOS2 <https://github.com/DIRACGrid/DIRACOS2>`_.
14+
DIRAC installations rely on the environment provided by `DIRACOS2 <https://github.com/DIRACGrid/DIRACOS2>`_.
1515
So, you first install DIRACOS2 and only then install DIRAC in it::
1616

1717
$ curl -LO https://github.com/DIRACGrid/DIRACOS2/releases/latest/download/DIRACOS-Linux-$(uname -m).sh

src/DIRAC/Resources/Computing/SSHComputingElement.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def __executeHostCommand(self, command, options, ssh=None, host=None):
488488
options = quote(options)
489489

490490
cmd = (
491-
"bash --login -c 'python3 %s/execute_batch %s || python %s/execute_batch %s || python2 %s/execute_batch %s'"
491+
"bash --login -c 'python3 %s/execute_batch %s || python %s/execute_batch %s'"
492492
% (self.sharedArea, options, self.sharedArea, options, self.sharedArea, options)
493493
)
494494

src/DIRAC/WorkloadManagementSystem/Utilities/PilotWrapper.py

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
py='python'
3333
elif command -v python3 &> /dev/null; then
3434
py='python3'
35-
elif command -v python2 &> /dev/null; then
36-
py='python2'
3735
fi
3836
/usr/bin/env $py << EOF
3937
@@ -63,14 +61,8 @@
6361
import shlex
6462
from uuid import uuid1
6563
66-
try:
67-
# For Python 3.0 and later
68-
from urllib.request import urlopen, HTTPError, URLError
69-
from urllib.parse import urlencode
70-
except ImportError:
71-
# Fall back to Python 2's urllib2
72-
from urllib2 import urlopen, HTTPError, URLError
73-
from urllib import urlencode
64+
from urllib.request import urlopen, HTTPError, URLError
65+
from urllib.parse import urlencode
7466
7567
try:
7668
from cStringIO import StringIO
@@ -93,10 +85,7 @@ def formatTime(self, record, datefmt=None):
9385
# formatter = logging.Formatter(fmt='%%(asctime)s UTC %%(levelname)-8s %%(message)s', datefmt='%%Y-%%m-%%d %%H:%%M:%%S')
9486
formatter = MicrosecondFormatter('%%(asctime)s %%(levelname)-8s [%%(name)s] %%(message)s')
9587
logging.Formatter.converter = time.gmtime
96-
try:
97-
screen_handler = logging.StreamHandler(stream=sys.stdout)
98-
except TypeError: # python2.6
99-
screen_handler = logging.StreamHandler(strm=sys.stdout)
88+
screen_handler = logging.StreamHandler(stream=sys.stdout)
10089
screen_handler.setFormatter(formatter)
10190
10291
# add a string buffer handler
@@ -276,28 +265,15 @@ def pilotWrapperScript(
276265
# Getting the json, tar, and checksum file
277266
try:
278267
279-
# urllib is different between python 2 and 3
280-
if sys.version_info < (3,):
281-
from urllib2 import urlopen as url_library_urlopen
282-
from urllib2 import URLError as url_library_URLError
283-
else:
284-
from urllib.request import urlopen as url_library_urlopen
285-
from urllib.error import URLError as url_library_URLError
268+
from urllib.request import urlopen
269+
from urllib.error import URLError
286270
287271
for fileName in ['checksums.sha512', 'pilot.json', 'pilot.tar']:
288-
# needs to distinguish whether urlopen method contains the 'context' param
289-
# in theory, it should be available from python 2.7.9
290-
# in practice, some prior versions may be composed of recent urllib version containing the param
291-
if 'context' in url_library_urlopen.__code__.co_varnames:
292-
import ssl
293-
context = ssl._create_unverified_context()
294-
remoteFile = url_library_urlopen(os.path.join(loc, fileName),
295-
timeout=10,
296-
context=context)
297-
298-
else:
299-
remoteFile = url_library_urlopen(os.path.join(loc, fileName),
300-
timeout=10)
272+
import ssl
273+
context = ssl._create_unverified_context()
274+
remoteFile = urlopen(os.path.join(loc, fileName),
275+
timeout=10,
276+
context=context)
301277
302278
localFile = open(fileName, 'wb')
303279
localFile.write(remoteFile.read())
@@ -320,7 +296,7 @@ def pilotWrapperScript(
320296
raise
321297
# if we get here we break out of the loop of locations
322298
break
323-
except (url_library_URLError, Exception) as e:
299+
except (URLError, Exception) as e:
324300
print('%%s unreacheable (this is normal!)' %% loc, file=sys.stderr)
325301
logger.error('%%s unreacheable (this is normal!)' %% loc)
326302
logger.exception(e)

tests/CI/run_pilot.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ cp /ca/certs/pilot_proxy /tmp/x509up_u$UID
3131

3232
eval "${PILOT_DOWNLOAD_COMMAND}"
3333

34-
echo "${PILOT_JSON}" > pilot.json
35-
jq < pilot.json
34+
echo "${PILOT_JSON}" >pilot.json
35+
jq <pilot.json
3636

37-
if command -v python &> /dev/null; then
37+
if command -v python &>/dev/null; then
3838
py='python'
39-
elif command -v python3 &> /dev/null; then
39+
elif command -v python3 &>/dev/null; then
4040
py='python3'
41-
elif command -v python2 &> /dev/null; then
42-
py='python2'
4341
fi
4442

4543
# shellcheck disable=SC2086

tests/Integration/WorkloadManagementSystem/Test_GenerateAndExecutePilotWrapper.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
# - starts it
77
#
88
# It should be executed for different versions of python, e.g.:
9-
# - 2.7.x (x < 9)
10-
# - 2.7.x (x >= 9)
119
# - 3.6.x
1210
# - 3.11.x
1311
#
@@ -25,20 +23,12 @@
2523

2624
# 1) gets the (DIRAC-free) PilotWrapper.py
2725

28-
# urllib is different between python 2 and 3
29-
if sys.version_info < (3,):
30-
from urllib2 import urlopen as url_library_urlopen # pylint: disable=import-error
31-
else:
32-
from urllib.request import urlopen as url_library_urlopen # pylint: disable=import-error,no-name-in-module
26+
from urllib.request import urlopen # pylint: disable=import-error,no-name-in-module
3327

28+
import ssl # pylint: disable=import-error
3429

35-
if sys.version_info >= (2, 7, 9):
36-
import ssl # pylint: disable=import-error
37-
38-
context = ssl._create_unverified_context()
39-
rf = url_library_urlopen(sys.argv[1], context=context)
40-
else:
41-
rf = url_library_urlopen(sys.argv[1])
30+
context = ssl._create_unverified_context()
31+
rf = urlopen(sys.argv[1], context=context)
4232
locc = sys.argv[2]
4333

4434
with open("PilotWrapper.py", "wb") as pj:

0 commit comments

Comments
 (0)