Skip to content

Commit

Permalink
Merge pull request #2496 from GEOS-ESM/feature/mathomp4/fix-up-python…
Browse files Browse the repository at this point in the history
…-init

Restore MAPL Python2 import behavior
  • Loading branch information
mathomp4 authored Dec 20, 2023
2 parents 85d64fb + 3ea6cce commit ed7ba4e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Update `components.yaml`
- ESMA_env v4.24.0 (Baselibs 7.17.0)
- Update CI to use circleci-tools v2
- Changed the Python MAPL `__init__.py` file to restore behavior from pre-Python3 transition where we did `from foo import *`. Also fix up other Python2 code to Python3.

### Fixed

Expand Down
28 changes: 14 additions & 14 deletions Python/MAPL/Date.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def copy(self):
def __iter__(self):
return self

def next(self):
def __next__(self):
#Last day of the month.
if self.day == NumberDaysMonth(self.month, self.year):
self.day = 1
Expand Down Expand Up @@ -230,7 +230,7 @@ def __add__(self, n):
#Convert back to date format.
return DateFromJDNumber(temp)
else:
raise TypeError, "%s is not an integer." % str(n)
raise TypeError("%s is not an integer." % str(n))

def __sub__(self, date):
"""Returns the (signed) difference of days between the dates."""
Expand All @@ -253,7 +253,7 @@ def __sub__(self, date):
ret += NumberDaysYear(year)
return ret
else:
raise TypeError, "%s is neither an integer nor a Date." % str(date)
raise TypeError("%s is neither an integer nor a Date." % str(date))

#Adding an integer is "commutative".
def __radd__(self, n):
Expand Down Expand Up @@ -283,7 +283,7 @@ def ToCOMTime(self):
def DateFromJDNumber(n):
"""Returns a date corresponding to the given Julian day number."""
if not isinstance(n, int):
raise TypeError, "%s is not an integer." % str(n)
raise TypeError("%s is not an integer." % str(n))

a = n + 32044
b = (4*a + 3)//146097
Expand Down Expand Up @@ -320,21 +320,21 @@ def strpdate(s):
temp = Date()
curr_month = temp.month
while temp.month == curr_month:
print temp
temp.next()
print(temp)
next(temp)

print "\n"
print("\n")

#How many days until the end of the year?
temp = Date()
temp.day, temp.month = 1, 1
curr_year = temp.year
while temp.year == curr_year:
print "%s is %d days away from the end of the year." % (str(temp),
temp.DaysToEndYear())
print("%s is %d days away from the end of the year." % (str(temp),
temp.DaysToEndYear()))
temp += NumberDaysMonth(temp.month)

print "\n"
print("\n")

#Playing with __sub__.
temp = Date()
Expand All @@ -344,11 +344,11 @@ def strpdate(s):
temp_list.append(temp)
temp += NumberDaysMonth(temp.month)
for elem in temp_list:
print "%s differs %d days from current date: %s" % (str(elem),
print("%s differs %d days from current date: %s" % (str(elem),
elem - Date(),
str(Date()))
str(Date())))

print "\n"
print("\n")

#Swapping arguments works?
print 23 + Date()
print(23 + Date())
8 changes: 8 additions & 0 deletions Python/MAPL/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@
"""

__version__ = "1.0.0"

from .exp import *
from .job import *
from .run import *
from .config import *
from .history import *
from .Date import *
from .filelock import *
6 changes: 3 additions & 3 deletions Python/MAPL/exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __del__(self):
self.submit() # resubmit itsef

def submit(self):
raise NotImplementedError, "Not implemented yet"
raise NotImplementedError("Not implemented yet")


# --------------
Expand Down Expand Up @@ -74,15 +74,15 @@ def setup(inConfigFiles=None):
os.mkdir(tmpdir)
os.chdir(tmpdir)
if os.system(cmd):
raise IOerror, "red_ma.pl did not complete successfully"
raise IOerror("red_ma.pl did not complete successfully")

# Resources as specified by user
# ------------------------------
cf = Config(ConfigFiles)

# Setup directory tree
# --------------------
for dir in cf.regex('Dir$').values():
for dir in list(cf.regex('Dir$').values()):
os.mkdir(dir)

# Populate Resources
Expand Down
13 changes: 6 additions & 7 deletions Python/MAPL/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
A special class for handling history resources.
"""

from config import *
from .config import *

class History(Config):

Expand Down Expand Up @@ -35,15 +35,14 @@ def arc(self,outFile):
*.temkplate resources.
"""
dict = self.regex('template$')
Tmpl = [str.replace("'","").replace(",","") for str in dict.values()]
Coll = [ str.split('.')[0].replace(",","") for str in dict.keys() ]
Tmpl = [str.replace("'","").replace(",","") for str in list(dict.values())]
Coll = [ str.split('.')[0].replace(",","") for str in list(dict.keys()) ]
Arch = [str.replace("'","").replace(",","") \
for str in self.regex('archive$').values()]
for str in list(self.regex('archive$').values())]

if len(Tmpl) != len(Arch):
raise IOError,\
"There are %d template resources but only %d archive resources."\
%(len(Tmpl),len(Arch))
raise IOError("There are %d template resources but only %d archive resources."\
%(len(Tmpl),len(Arch)))

header = '# PESTO resource for History Collections ' + \
'(automatically generated - do not edit)'
Expand Down
10 changes: 5 additions & 5 deletions Python/MAPL/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"""

import Abstract
from exp import Exp
from . import Abstract
from .exp import Exp

class Job(Exp):

Expand Down Expand Up @@ -72,13 +72,13 @@ def __del__(self):
# -----------------

def getResources(self):
raise NotImplementedError, "Not implemented yet"
raise NotImplementedError("Not implemented yet")

def getRecyclables(self):
raise NotImplementedError, "Not implemented yet"
raise NotImplementedError("Not implemented yet")

def putRecyclables(self):
raise NotImplementedError, "Not implemented yet"
raise NotImplementedError("Not implemented yet")


# ----------------
Expand Down
2 changes: 1 addition & 1 deletion Python/MAPL/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""

from job import Job
from .job import Job

class Run(Job):

Expand Down

0 comments on commit ed7ba4e

Please sign in to comment.