Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to use Python3 #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion esgprep/checkvocab/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

"""

from constants import *
from .constants import *
from esgprep.utils.collectors import PathCollector, DatasetCollector, Collector
from esgprep.utils.context import MultiprocessingContext
from esgprep.utils.custom_print import *
Expand Down
4 changes: 2 additions & 2 deletions esgprep/checkvocab/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from fuzzywuzzy.fuzz import partial_ratio
from fuzzywuzzy.process import extractOne

from constants import *
from context import ProcessingContext
from .constants import *
from .context import ProcessingContext
from esgprep.utils.custom_print import *
from esgprep.utils.misc import ProcessContext, ncopen

Expand Down
4 changes: 2 additions & 2 deletions esgprep/drs/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

from uuid import uuid4 as uuid

from constants import *
from custom_exceptions import *
from .constants import *
from .custom_exceptions import *
from esgprep.utils.collectors import Collector
from esgprep.utils.context import MultiprocessingContext
from esgprep.utils.custom_print import *
Expand Down
4 changes: 2 additions & 2 deletions esgprep/drs/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from treelib import Tree
from treelib.tree import DuplicatedNodeIdError

from constants import *
from custom_exceptions import *
from .constants import *
from .custom_exceptions import *
from esgprep.utils.custom_print import *
from esgprep.utils.misc import ncopen

Expand Down
8 changes: 4 additions & 4 deletions esgprep/drs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import traceback
from multiprocessing import Pool

from constants import *
from context import ProcessingContext
from custom_exceptions import *
from .constants import *
from .context import ProcessingContext
from .custom_exceptions import *
from esgprep.utils.custom_print import *
from esgprep.utils.misc import load, store, evaluate, ProcessContext, get_tracking_id, get_checksum
from handler import File, DRSPath, DRSTree
from .handler import File, DRSPath, DRSTree


def process(source):
Expand Down
6 changes: 3 additions & 3 deletions esgprep/esgcheckvocab.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Expand All @@ -10,8 +10,8 @@

from esgprep.checkvocab.main import run
from esgprep.utils.help import *
from utils.constants import *
from utils.parser import *
from .utils.constants import *
from .utils.parser import *

__version__ = 'from esgprep v{} {}'.format(VERSION, VERSION_DATE)

Expand Down
6 changes: 3 additions & 3 deletions esgprep/esgdrs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Expand All @@ -11,8 +11,8 @@

from esgprep.drs.main import run
from esgprep.utils.help import *
from utils.constants import *
from utils.parser import *
from .utils.constants import *
from .utils.parser import *

__version__ = 'from esgprep v{} {}'.format(VERSION, VERSION_DATE)

Expand Down
8 changes: 4 additions & 4 deletions esgprep/esgfetchini.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Expand All @@ -8,9 +8,9 @@
"""

from esgprep.fetchini.main import run
from utils.constants import *
from utils.help import *
from utils.parser import *
from .utils.constants import *
from .utils.help import *
from .utils.parser import *

__version__ = 'from esgprep v{} {}'.format(VERSION, VERSION_DATE)

Expand Down
8 changes: 4 additions & 4 deletions esgprep/esgfetchtables.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Expand All @@ -8,9 +8,9 @@
"""

from esgprep.fetchtables.main import run
from utils.constants import *
from utils.help import *
from utils.parser import *
from .utils.constants import *
from .utils.help import *
from .utils.parser import *

__version__ = 'from esgprep v{} {}'.format(VERSION, VERSION_DATE)

Expand Down
6 changes: 3 additions & 3 deletions esgprep/esgmapfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
Expand All @@ -11,8 +11,8 @@

from esgprep.mapfile.main import run
from esgprep.utils.help import *
from utils.constants import *
from utils.parser import *
from .utils.constants import *
from .utils.parser import *

__version__ = 'from esgprep v{} {}'.format(VERSION, VERSION_DATE)

Expand Down
2 changes: 1 addition & 1 deletion esgprep/fetchini/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

"""

from constants import *
from .constants import *
from esgprep.utils.constants import GITHUB_API_PARAMETER
from esgprep.utils.context import GitHubBaseContext
from esgprep.utils.github import *
Expand Down
2 changes: 1 addition & 1 deletion esgprep/fetchtables/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

"""

from constants import *
from .constants import *
from esgprep.utils.collectors import FilterCollection
from esgprep.utils.context import GitHubBaseContext
from esgprep.utils.custom_print import *
Expand Down
4 changes: 2 additions & 2 deletions esgprep/fetchtables/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import traceback

from constants import *
from context import ProcessingContext
from .constants import *
from .context import ProcessingContext
from esgprep.utils.constants import GITHUB_API_PARAMETER
from esgprep.utils.github import *

Expand Down
2 changes: 1 addition & 1 deletion esgprep/mapfile/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import fnmatch

from constants import *
from .constants import *
from esgprep.utils.collectors import VersionedPathCollector, DatasetCollector
from esgprep.utils.context import MultiprocessingContext
from esgprep.utils.custom_print import *
Expand Down
2 changes: 1 addition & 1 deletion esgprep/mapfile/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ESGConfigParser import interpolate
from ESGConfigParser.custom_exceptions import ExpressionNotMatch, NoConfigOption, MissingPatternKey

from constants import *
from .constants import *
from esgprep.utils.custom_exceptions import *


Expand Down
19 changes: 11 additions & 8 deletions esgprep/mapfile/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
from ESGConfigParser import interpolate, MissingPatternKey, BadInterpolation, InterpolationDepthError
from lockfile import LockFile

from constants import *
from context import ProcessingContext
from custom_exceptions import *
from .constants import *
from .context import ProcessingContext
from .custom_exceptions import *
from esgprep.utils.custom_print import *
from esgprep.utils.misc import evaluate, remove, get_checksum, ProcessContext
from esgprep.utils.output_control import OutputControl
from handler import File, Dataset
from .handler import File, Dataset


def get_output_mapfile(outdir, attributes, mapfile_name, dataset_id, dataset_version, mapfile_drs=None, basename=False):
Expand Down Expand Up @@ -221,7 +221,8 @@ def initializer(keys, values):
"""
assert len(keys) == len(values)
global pctx
pctx = ProcessContext({key: values[i] for i, key in enumerate(keys)})
v = list(values)
pctx = ProcessContext({key: v[i] for i, key in enumerate(keys)})


def run(args):
Expand Down Expand Up @@ -266,11 +267,13 @@ def run(args):
# Flush buffer
Print.flush()
# Get number of files scanned (excluding errors/skipped files)
ctx.scan_data = len(filter(None, results))
l = list(filter(None, results))
ctx.scan_data = len(l)
# Get number of scan errors
ctx.scan_errors = results.count(None)
# Get number of generated mapfiles
ctx.nbmap = len(filter(None, set(results)))
l = list(filter(None, set(results)))
ctx.nbmap = len(l)
# Evaluates the scan results to finalize mapfiles writing
if evaluate(results):
for mapfile in filter(None, set(results)):
Expand All @@ -280,7 +283,7 @@ def run(args):
result = remove(WORKING_EXTENSION, mapfile)
if quiet:
output_control.stdout_on()
print result
print (result)
output_control.stdout_off()
else:
Print.result(result)
Expand Down
2 changes: 1 addition & 1 deletion esgprep/utils/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class FilterCollection(object):
indicating to match (i.e., include) or non-match (i.e., exclude) the corresponding expression.

"""
FILTER_TYPES = (str, re._pattern_type)
FILTER_TYPES = (str, re.Pattern)

def __init__(self):
self.filters = dict()
Expand Down
2 changes: 1 addition & 1 deletion esgprep/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
VERSION = '2.9.7' # remember to change VERSION_DATE when updating

# Date
VERSION_DATE = datetime(year=2019, month=04, day=15).strftime("%Y-%d-%m")
VERSION_DATE = datetime(year=2019, month=4, day=15).strftime("%Y-%d-%m")

# Shell colors map
SHELL_COLORS = {'red': 1,
Expand Down
6 changes: 3 additions & 3 deletions esgprep/utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def __init__(self, args):
self.manager = SyncManager()
self.manager.start()
self.progress = self.manager.Value('i', 0)
Print.BUFFER = self.manager.Value(c_char_p, '')
Print.BUFFER = self.manager.Value(c_char_p, b'')
else:
self.progress = Value('i', 0)
# Stdout lock
Expand Down Expand Up @@ -200,8 +200,8 @@ def get_checksum_type(self):
checksum_type = _cfg.get_options_from_table('checksum')[0][1].lower()
else: # Use SHA256 as default because esg.ini not mandatory in configuration directory
checksum_type = 'sha256'
if checksum_type not in checksum_types:
raise InvalidChecksumType(checksum_type)
#if checksum_type not in checksum_types:
# raise InvalidChecksumType(checksum_type)
_cfg.reset()
return checksum_type

Expand Down
4 changes: 2 additions & 2 deletions esgprep/utils/custom_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

from datetime import datetime
from hashlib import algorithms as checksum_types
import hashlib


###############################
Expand Down Expand Up @@ -70,7 +70,7 @@ class InvalidChecksumType(Exception):
def __init__(self, client):
self.msg = "Checksum type not supported or invalid."
self.msg += "\n<checksum type: '{}'>".format(client)
self.msg += "\n<allowed algorithms: '{}'>".format(checksum_types)
self.msg += "\n<allowed algorithms: '{}'>".format(algorithms)
super(self.__class__, self).__init__(self.msg)


Expand Down
6 changes: 3 additions & 3 deletions esgprep/utils/custom_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
from ctypes import c_char_p
from multiprocessing import Value

from constants import SHELL_COLORS
from custom_exceptions import *
from .constants import SHELL_COLORS
from .custom_exceptions import *

_colors_enabled = [sys.stdout.isatty()]

Expand Down Expand Up @@ -181,7 +181,7 @@ class Print(object):
DEBUG = False
CMD = None
LOG_TO_STDOUT = False
BUFFER = Value(c_char_p, '')
BUFFER = Value(c_char_p, b'')
LOGFILE = None
CARRIAGE_RETURNED = True

Expand Down
2 changes: 1 addition & 1 deletion esgprep/utils/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

"""

from custom_print import *
from .custom_print import *

# Help
TITLE = COLOR('yellow').bold(""".___ ___ ___ ___ ___ ___ ___.
Expand Down
2 changes: 1 addition & 1 deletion esgprep/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from netCDF4 import Dataset

from custom_print import *
from .custom_print import *
from esgprep.drs.constants import PID_PREFIXES


Expand Down
14 changes: 6 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
lockfile==0.12.2
cftime==1.0.3.4
esgconfigparser==0.1.17
requests==2.20.0
fuzzywuzzy==0.16.0
netCDF4==1.4.0
hurry.filesize==0.9
treelib==1.4.0
lockfile
cftime
requests
fuzzywuzzy
hurry.filesize
treelib
18 changes: 9 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ def run(self):
url='https://github.com/ESGF/esgf-prepare',
packages=find_packages(),
include_package_data=True,
python_requires='>=2.7, <3.0',
install_requires=['lockfile==0.12.2',
'cftime==1.0.3.4'
'esgconfigparser==0.1.17',
'requests==2.20.0',
'fuzzywuzzy==0.16.0',
'netCDF4==1.4.0',
'hurry.filesize==0.9',
'treelib==1.4.0'],
python_requires='>=3.0, <4.0',
install_requires=['lockfile',
'cftime',
'esgconfigparser',
'requests',
'fuzzywuzzy',
'netCDF4',
'hurry.filesize',
'treelib'],
platforms=['Unix'],
zip_safe=False,
entry_points={'console_scripts': ['esgmapfile=esgprep.esgmapfile:main',
Expand Down