Skip to content

Commit

Permalink
Revert "Merge pull request #124 from magnusuMET/linting"
Browse files Browse the repository at this point in the history
This reverts commit 5afa6a3, reversing
changes made to 3ac043d.
  • Loading branch information
magnusuMET committed Aug 3, 2023
1 parent 5afa6a3 commit 61de1a3
Show file tree
Hide file tree
Showing 49 changed files with 2,078 additions and 2,807 deletions.
5 changes: 4 additions & 1 deletion install_usermodule_r8.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ EOF
install_snap() {
MODULE_VERSION="$1"
BASE_MODULE_VERSION="$2"

source /modules/rhel8/conda/install/etc/profile.d/conda.sh

BASE_MODULE_PREFIX=/modules/rhel8/user-apps/fou-modules/SnapPy/"$BASE_MODULE_VERSION"/

source /modules/rhel8/conda/install/etc/profile.d/conda.sh "$BASE_MODULE_PREFIX"
conda activate "$BASE_MODULE_PREFIX"

MODULE_PREFIX=/modules/rhel8/user-apps/fou-modules/SnapPy/"$MODULE_VERSION"/
mkdir --parent -- "$MODULE_PREFIX/bin"
Expand Down
44 changes: 19 additions & 25 deletions utils/SnapPy/METNO/Alvin.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# SNAP: Servere Nuclear Accident Programme
# Copyright (C) 1992-2017 Norwegian Meteorological Institute
#
# This file is part of SNAP. SNAP is free software: you can
# redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the
#
# This file is part of SNAP. SNAP is free software: you can
# redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""
'''
Created on Apr 28, 2017
@author: heikok
"""
'''
import os
from subprocess import TimeoutExpired
from time import sleep
Expand All @@ -31,24 +31,22 @@


class Alvin(HPC):
"""
'''
Implementation of a HPC machine for alvin.nsc.liu.se
"""
'''


def __init__(self):
"""
'''
Constructor
"""
connection = SSHConnection(
username="metno_op", machine="alvin.nsc.liu.se", port=22
)
'''
connection = SSHConnection(username="metno_op", machine="alvin.nsc.liu.se", port=22)
queue = SLURMQueue()
super().__init__(connection, queue)


class TestFrost(unittest.TestCase):
"""tests for alvin, only working when having an existing forecast account on alvin"""

'''tests for alvin, only working when having an existing forecast account on alvin'''
def setUp(self):
unittest.TestCase.setUp(self)
self.hpc = HPC.by_name("alvin")
Expand All @@ -58,14 +56,15 @@ def setUp(self):
def tearDown(self):
unittest.TestCase.tearDown(self)
for f in self.testFiles:
if os.path.exists(f):
if (os.path.exists(f)):
os.unlink(f)

def test_connect(self):
(out, error, retval) = self.hpc.syscall("echo", ["5"])
self.assertEqual(retval, 0, "command succeeded")
self.assertEqual(int(out), 5, "command output correct")


def test_timeout(self):
with self.assertRaises(TimeoutExpired):
self.hpc.syscall("sleep", ["5"], timeout=1)
Expand All @@ -75,8 +74,7 @@ def test_full(self):
self.hpc.syscall("rm", ["-r", self.rdir])
self.hpc.syscall("mkdir", ["-p", self.rdir])
with open(self.testFiles[0], "w") as fh:
fh.write(
"""#! /bin/bash
fh.write('''#! /bin/bash
#SBATCH -A met
#SBATCH --nodes=1 --ntasks-per-node=1 --time=01:00:00
Expand All @@ -86,10 +84,7 @@ def test_full(self):
sleep 8
echo "finished" > {status}
""".format(
status=status_file, rdir=self.rdir
)
)
'''.format(status=status_file, rdir=self.rdir))
self.hpc.put_files([self.testFiles[0]], self.rdir)
qjob = self.hpc.submit_job(os.path.join(self.rdir, self.testFiles[0]), [])
self.assertIsNotNone(qjob, "job submitted")
Expand All @@ -114,6 +109,5 @@ def test_full(self):

self.hpc.syscall("rm", ["-r", self.rdir])


if __name__ == "__main__":
unittest.main()
57 changes: 29 additions & 28 deletions utils/SnapPy/METNO/DirectConnection.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# SNAP: Servere Nuclear Accident Programme
# Copyright (C) 1992-2017 Norwegian Meteorological Institute
#
# This file is part of SNAP. SNAP is free software: you can
# redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the
#
# This file is part of SNAP. SNAP is free software: you can
# redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""
'''
Created on Aug 08, 2017
@author: heikok
"""
'''

import os
import shutil
Expand All @@ -31,10 +31,11 @@


class DirectConnection(Connection):
"""no connection, working directly on that machine"""
'''no connection, working directly on that machine
'''
charset = typed_property("charset", str)
"""charset of stdout of the machine, usually utf-8"""
'''charset of stdout of the machine, usually utf-8'''

def __init__(self):
super().__init__()
Expand All @@ -55,28 +56,25 @@ def get_files(self, files, local_path=None, timeout=None):

def syscall(self, program, args, timeout=None):
if sys.version_info > (3, 5, 0):
proc = subprocess.run(
[program] + args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
timeout=timeout,
)
return (
proc.stdout.decode(self.charset),
proc.stderr.decode(self.charset),
proc.returncode,
)
proc = subprocess.run([program]+ args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, timeout=timeout)
return (proc.stdout.decode(self.charset),
proc.stderr.decode(self.charset),
proc.returncode)
else:
try:
output = subprocess.check_output([program] + args, timeout=timeout)
return (output.decode(self.charset), "", 0)
return (output.decode(self.charset),
'',
0)
except subprocess.CalledProcessError as cpe:
return (cpe.output.decode(self.charset), "", cpe.returncode)
return (cpe.output.decode(self.charset),
'',
cpe.returncode)


class TestDirectConnection(unittest.TestCase):
"""Test for DirectConnection"""

class TestDirectConnection(unittest.TestCase):
'''Test for DirectConnection'''
def setUp(self):
unittest.TestCase.setUp(self)
self.dir1 = os.path.join(os.path.dirname(__file__), "testdir1")
Expand All @@ -86,17 +84,19 @@ def setUp(self):
if not os.path.exists(self.dir2):
os.mkdir(self.dir2)

self.files = ["file1", "file2"]
self.files = ['file1', 'file2']
for file in self.files:
infile = os.path.join(self.dir1, file)
if not os.path.exists(infile):
with open(infile, "w") as ifh:
with open(infile, 'w') as ifh:
ifh.write("file: {name}".format(name=infile))
outfile = os.path.join(self.dir2, file)
if os.path.exists(outfile):
os.unlink(outfile)
self.conn = DirectConnection()



def tearDown(self):
unittest.TestCase.tearDown(self)
for path in (self.dir1, self.dir2):
Expand All @@ -120,7 +120,8 @@ def test_get_files(self):
files_o = [os.path.join(self.dir2, x) for x in self.files]
self.conn.get_files(files_i, self.dir2, 5)
for file in files_o:
self.assertTrue(os.path.exists(file), "file {} exists".format(file))
self.assertTrue(os.path.exists(file),
"file {} exists".format(file))
os.unlink(file)

def test_put_files(self):
Expand Down
50 changes: 22 additions & 28 deletions utils/SnapPy/METNO/Frost.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# SNAP: Servere Nuclear Accident Programme
# Copyright (C) 1992-2017 Norwegian Meteorological Institute
#
# This file is part of SNAP. SNAP is free software: you can
# redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the
#
# This file is part of SNAP. SNAP is free software: you can
# redistribute it and/or modify it under the terms of the
# GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
"""
'''
Created on Nov 7, 2016
@author: heikok
"""
'''
import os
from subprocess import TimeoutExpired
from time import sleep
Expand All @@ -31,24 +31,22 @@


class Frost(HPC):
"""
'''
Implementation of a HPC machine for frost.nsc.liu.se
"""
'''


def __init__(self):
"""
'''
Constructor
"""
connection = SSHConnection(
username="metno_op", machine="frost.nsc.liu.se", port=22
)
'''
connection = SSHConnection(username="metno_op", machine="frost.nsc.liu.se", port=22)
queue = SLURMQueue()
super().__init__(connection, queue)


class TestFrost(unittest.TestCase):
"""tests for frost, only working when having an existing forecast account on frost"""

'''tests for frost, only working when having an existing forecast account on frost'''
def setUp(self):
unittest.TestCase.setUp(self)
self.hpc = HPC.by_name("frost")
Expand All @@ -59,14 +57,15 @@ def setUp(self):
def tearDown(self):
unittest.TestCase.tearDown(self)
for f in self.testFiles:
if os.path.exists(f):
if (os.path.exists(f)):
os.unlink(f)

def test_connect(self):
(out, error, retval) = self.hpc.syscall("echo", ["5"])
self.assertEqual(retval, 0, "command succeeded")
self.assertEqual(int(out), 5, "command output correct")


def test_timeout(self):
with self.assertRaises(TimeoutExpired):
self.hpc.syscall("sleep", ["5"], timeout=1)
Expand All @@ -75,16 +74,15 @@ def test_full(self):
status_file = os.path.join(self.rdir, "status")
self.hpc.syscall("rm", ["-r", self.rdir])
self.hpc.syscall("mkdir", ["-p", self.rdir])

for f in self.strangeFiles:
with open(f, "w") as fh:
with open(f, 'w') as fh:
fh.write(f)
self.hpc.put_files([f], self.rdir)
self.hpc.syscall("ls", [f])

with open(self.testFiles[0], "w") as fh:
fh.write(
"""#! /bin/bash
fh.write('''#! /bin/bash
#SBATCH -A met
#SBATCH --nodes=1 --ntasks-per-node=1 --time=01:00:00
Expand All @@ -94,10 +92,7 @@ def test_full(self):
sleep 8
echo "finished" > {status}
""".format(
status=status_file, rdir=self.rdir
)
)
'''.format(status=status_file, rdir=self.rdir))
self.hpc.put_files([self.testFiles[0]], self.rdir)
qjob = self.hpc.submit_job(os.path.join(self.rdir, self.testFiles[0]), [])
self.assertIsNotNone(qjob, "job submitted")
Expand All @@ -122,6 +117,5 @@ def test_full(self):

self.hpc.syscall("rm", ["-r", self.rdir])


if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit 61de1a3

Please sign in to comment.