Loading PKG-INFO +3 −2 Original line number Diff line number Diff line Metadata-Version: 1.1 Name: easydev Version: 0.9.35 Version: 0.9.37 Summary: Common utilities to ease the development of Python packages Home-page: ['http://packages.python.org/easydev/'] Author: Thomas Cokelaer Author-email: cokelaer@ebi.ac.uk License: new BSD Download-URL: ['http://pypi.python.org/pypi/easydev'] Description-Content-Type: UNKNOWN Description: easydev ########## Loading @@ -28,7 +29,7 @@ Description: easydev :contributions: Please join https://github.com/cokelaer/easydev :source: Please use https://github.com/cokelaer/easydev :issues: Please use https://github.com/cokelaer/easydev/issues :Python version supported: 2.6, 2.7, 3.3, 3.4, 3.5, 3.6 :Python version supported: 2.7, 3.3, 3.4, 3.5, 3.6 The `easydev <http://pypi.python.org/pypi/easydev/>`_ package Loading README.rst +1 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ easydev :contributions: Please join https://github.com/cokelaer/easydev :source: Please use https://github.com/cokelaer/easydev :issues: Please use https://github.com/cokelaer/easydev/issues :Python version supported: 2.6, 2.7, 3.3, 3.4, 3.5, 3.6 :Python version supported: 2.7, 3.3, 3.4, 3.5, 3.6 The `easydev <http://pypi.python.org/pypi/easydev/>`_ package Loading easydev/__init__.py +8 −4 Original line number Diff line number Diff line Loading @@ -18,13 +18,17 @@ from __future__ import print_function #from __future__ import absolute_import __version__ = "0.9.34" import pkg_resources __version__ = "0.9.36" try: version = pkg_resources.require("easydev")[0].version except: import pkg_resources except ImportError as err: print(err) print("version set to {} manually.".format(__version__)) version = __version__ else: version = pkg_resources.require("easydev")[0].version __version__ = version from . import browser from .browser import browse as onweb Loading easydev/config_tools.py +9 −6 Original line number Diff line number Diff line Loading @@ -98,9 +98,11 @@ class ConfigExample(object): which can be read with ConfigParser as follows: .. code-block:: python >>> from ConfigParser import ConfigParser .. doctest:: >>> # Python 3 code >>> from configparser import ConfigParser >>> config = ConfigParser() >>> config.read("file.ini") [] Loading Loading @@ -133,13 +135,13 @@ class DynamicConfigParser(ConfigParser, object): You can now also directly access to an option as follows:: >>> c.General.tag c.General.tag Then, you can add or remove sections (:meth:`remove_section`, :meth:`add_section`), or option from a section :meth:`remove_option`. You can save the instance into a file or print it:: >>> print(c) print(c) .. warning:: if you set options manually (e.G. self.GA.test =1 if GA is a section and test one of its options), then the save/write does not work Loading Loading @@ -231,8 +233,9 @@ class DynamicConfigParser(ConfigParser, object): Let us build up a standard config file: .. code-block:: python >>> import ConfigParser >>> c = ConfigParser.ConfigParser() >>> # Python 3 code >>> from configparser import ConfigParser >>> c = ConfigParser() >>> c.add_section('general') >>> c.set('general', 'step', str(1)) >>> c.set('general', 'verbose', 'True') Loading easydev/logging_tools.py +77 −56 Original line number Diff line number Diff line Loading @@ -14,77 +14,98 @@ # ############################################################################## import logging import colorlog __all__ = ["Logging"] class Logging(object): """logging utility. colors = { 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'bold_red'} When using the logging utility, it works like a singleton. So, once logging level is set, you cannot set it again easily. Here is a class that allows to do that. .. warning:: this is a bit of a hack. Maybe this is not a proper solution but it seems to do the job. class Logging(object): """logging utility. :: >>> l = Logging("INFO") >>> l = Logging("root", "INFO") >>> l.info("test") INFO:root:test >>> l.level = "WARNING" >>> l.info("test") """ # I think that we can not inherit from logging. def __init__(self, level): """.. rubric:: constructor :param str level: valid levels are ["INFO", "DEBUG", "WARNING", "CRITICAL", "ERROR"]. If set to True, level is internally set to INFO. If set to False, level is seet internally to ERROR. """ self._debugLevel = None self.debugLevel = level self.logging = logging self.info = logging.info self.warning = logging.warning self.critical = logging.critical self.error = logging.error self.debug = logging.debug def __init__(self, name="root", level="WARNING"): self.name = name formatter = colorlog.ColoredFormatter( "%(log_color)s%(levelname)-8s[%(name)s]: %(reset)s %(blue)s%(message)s", datefmt=None, reset=True, log_colors=colors, secondary_log_colors={}, style='%' ) handler = colorlog.StreamHandler() handler.setFormatter(formatter) logger = colorlog.getLogger(self.name) if len(logger.handlers) == 0: logger.addHandler(handler) self._set_level(level) def _set_level(self, level): valid_level = [True, False, "INFO", "DEBUG", "WARNING", "CRITICAL", "ERROR"] if isinstance(level, bool): if level is True: level = "INFO" if level is False: level = "ERROR" if level in valid_level: self._debugLevel = level else: raise ValueError("The level of debugging must be in %s " %valid_level) # I'm not sure this is the best solution, but basicConfig can be called # only once and populatse root.handlers list with one instance of # logging.StreamHandler. So, I reset it before calling basicConfig # that effectively changes the logging behaviour logging.root.handlers = [] logging.basicConfig(level=self._debugLevel) assert level in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] logging_level = getattr(colorlog.logging.logging, level) colorlog.getLogger(self.name).setLevel(level) def _get_level(self): return self._debugLevel debugLevel = property(_get_level, _set_level, doc="Read/Write access to the debug level. Must be one of INFO, " + \ "DEBUG, WARNING, CRITICAL, ERROR") level = property(_get_level, _set_level, doc="alias to :attr:`~easydev.logging_tools.Logging.debugLevel` (Read-only access)") # Used copy/deepcopy module def __copy__(self): print("WARNING: easydev.logging_tools.__copy__ deprecated. use copy() instead") s = Logging(self.level) return s def __deepcopy__(self, memo): s = Logging(self.level) return s level = colorlog.getLogger(self.name).level if level == 10: return "DEBUG" elif level == 20: return "INFO" elif level == 30: return "WARNING" elif level == 40: return "ERROR" elif level == 50: return "CRITICAL" else: return level level = property(_get_level, _set_level) def debug(self, msg): colorlog.getLogger(self.name).debug(msg) def info(self, msg): colorlog.getLogger(self.name).info(msg) def warning(self, msg): colorlog.getLogger(self.name).warning(msg) def critical(self, msg): colorlog.getLogger(self.name).critical(msg) def error(self, msg): colorlog.getLogger(self.name).error(msg) Loading
PKG-INFO +3 −2 Original line number Diff line number Diff line Metadata-Version: 1.1 Name: easydev Version: 0.9.35 Version: 0.9.37 Summary: Common utilities to ease the development of Python packages Home-page: ['http://packages.python.org/easydev/'] Author: Thomas Cokelaer Author-email: cokelaer@ebi.ac.uk License: new BSD Download-URL: ['http://pypi.python.org/pypi/easydev'] Description-Content-Type: UNKNOWN Description: easydev ########## Loading @@ -28,7 +29,7 @@ Description: easydev :contributions: Please join https://github.com/cokelaer/easydev :source: Please use https://github.com/cokelaer/easydev :issues: Please use https://github.com/cokelaer/easydev/issues :Python version supported: 2.6, 2.7, 3.3, 3.4, 3.5, 3.6 :Python version supported: 2.7, 3.3, 3.4, 3.5, 3.6 The `easydev <http://pypi.python.org/pypi/easydev/>`_ package Loading
README.rst +1 −1 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ easydev :contributions: Please join https://github.com/cokelaer/easydev :source: Please use https://github.com/cokelaer/easydev :issues: Please use https://github.com/cokelaer/easydev/issues :Python version supported: 2.6, 2.7, 3.3, 3.4, 3.5, 3.6 :Python version supported: 2.7, 3.3, 3.4, 3.5, 3.6 The `easydev <http://pypi.python.org/pypi/easydev/>`_ package Loading
easydev/__init__.py +8 −4 Original line number Diff line number Diff line Loading @@ -18,13 +18,17 @@ from __future__ import print_function #from __future__ import absolute_import __version__ = "0.9.34" import pkg_resources __version__ = "0.9.36" try: version = pkg_resources.require("easydev")[0].version except: import pkg_resources except ImportError as err: print(err) print("version set to {} manually.".format(__version__)) version = __version__ else: version = pkg_resources.require("easydev")[0].version __version__ = version from . import browser from .browser import browse as onweb Loading
easydev/config_tools.py +9 −6 Original line number Diff line number Diff line Loading @@ -98,9 +98,11 @@ class ConfigExample(object): which can be read with ConfigParser as follows: .. code-block:: python >>> from ConfigParser import ConfigParser .. doctest:: >>> # Python 3 code >>> from configparser import ConfigParser >>> config = ConfigParser() >>> config.read("file.ini") [] Loading Loading @@ -133,13 +135,13 @@ class DynamicConfigParser(ConfigParser, object): You can now also directly access to an option as follows:: >>> c.General.tag c.General.tag Then, you can add or remove sections (:meth:`remove_section`, :meth:`add_section`), or option from a section :meth:`remove_option`. You can save the instance into a file or print it:: >>> print(c) print(c) .. warning:: if you set options manually (e.G. self.GA.test =1 if GA is a section and test one of its options), then the save/write does not work Loading Loading @@ -231,8 +233,9 @@ class DynamicConfigParser(ConfigParser, object): Let us build up a standard config file: .. code-block:: python >>> import ConfigParser >>> c = ConfigParser.ConfigParser() >>> # Python 3 code >>> from configparser import ConfigParser >>> c = ConfigParser() >>> c.add_section('general') >>> c.set('general', 'step', str(1)) >>> c.set('general', 'verbose', 'True') Loading
easydev/logging_tools.py +77 −56 Original line number Diff line number Diff line Loading @@ -14,77 +14,98 @@ # ############################################################################## import logging import colorlog __all__ = ["Logging"] class Logging(object): """logging utility. colors = { 'DEBUG': 'cyan', 'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red', 'CRITICAL': 'bold_red'} When using the logging utility, it works like a singleton. So, once logging level is set, you cannot set it again easily. Here is a class that allows to do that. .. warning:: this is a bit of a hack. Maybe this is not a proper solution but it seems to do the job. class Logging(object): """logging utility. :: >>> l = Logging("INFO") >>> l = Logging("root", "INFO") >>> l.info("test") INFO:root:test >>> l.level = "WARNING" >>> l.info("test") """ # I think that we can not inherit from logging. def __init__(self, level): """.. rubric:: constructor :param str level: valid levels are ["INFO", "DEBUG", "WARNING", "CRITICAL", "ERROR"]. If set to True, level is internally set to INFO. If set to False, level is seet internally to ERROR. """ self._debugLevel = None self.debugLevel = level self.logging = logging self.info = logging.info self.warning = logging.warning self.critical = logging.critical self.error = logging.error self.debug = logging.debug def __init__(self, name="root", level="WARNING"): self.name = name formatter = colorlog.ColoredFormatter( "%(log_color)s%(levelname)-8s[%(name)s]: %(reset)s %(blue)s%(message)s", datefmt=None, reset=True, log_colors=colors, secondary_log_colors={}, style='%' ) handler = colorlog.StreamHandler() handler.setFormatter(formatter) logger = colorlog.getLogger(self.name) if len(logger.handlers) == 0: logger.addHandler(handler) self._set_level(level) def _set_level(self, level): valid_level = [True, False, "INFO", "DEBUG", "WARNING", "CRITICAL", "ERROR"] if isinstance(level, bool): if level is True: level = "INFO" if level is False: level = "ERROR" if level in valid_level: self._debugLevel = level else: raise ValueError("The level of debugging must be in %s " %valid_level) # I'm not sure this is the best solution, but basicConfig can be called # only once and populatse root.handlers list with one instance of # logging.StreamHandler. So, I reset it before calling basicConfig # that effectively changes the logging behaviour logging.root.handlers = [] logging.basicConfig(level=self._debugLevel) assert level in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] logging_level = getattr(colorlog.logging.logging, level) colorlog.getLogger(self.name).setLevel(level) def _get_level(self): return self._debugLevel debugLevel = property(_get_level, _set_level, doc="Read/Write access to the debug level. Must be one of INFO, " + \ "DEBUG, WARNING, CRITICAL, ERROR") level = property(_get_level, _set_level, doc="alias to :attr:`~easydev.logging_tools.Logging.debugLevel` (Read-only access)") # Used copy/deepcopy module def __copy__(self): print("WARNING: easydev.logging_tools.__copy__ deprecated. use copy() instead") s = Logging(self.level) return s def __deepcopy__(self, memo): s = Logging(self.level) return s level = colorlog.getLogger(self.name).level if level == 10: return "DEBUG" elif level == 20: return "INFO" elif level == 30: return "WARNING" elif level == 40: return "ERROR" elif level == 50: return "CRITICAL" else: return level level = property(_get_level, _set_level) def debug(self, msg): colorlog.getLogger(self.name).debug(msg) def info(self, msg): colorlog.getLogger(self.name).info(msg) def warning(self, msg): colorlog.getLogger(self.name).warning(msg) def critical(self, msg): colorlog.getLogger(self.name).critical(msg) def error(self, msg): colorlog.getLogger(self.name).error(msg)