def __init__(self, name, share=True, namespace=None):
        """.. rubric:: Constructor


        :param str name:
        :param str share:
        """
        self.pkgname = name   # can be only the pkg name without namespace
        self.name = name      # can be pkg or namespace.pkg
        self.share = share
        self.namespace = namespace

        self.metainfo = {
                "pkgname": self.pkgname,
                "name":self.pkgname,
                "version": "version",
                "MINOR": '0',
                "MAJOR": '0',
                "MICRO": '1',
                "install_require": '[]',
                "description": "Put a short description here",
                "author": "yourname",
                "email": "*****@*****.**",
                "namespace": self.namespace,
        }
        if self.namespace:
            self.metainfo["name"] = ".".join([self.namespace, self.pkgname])
            self.metainfo["url"] = os.sep.join([self.namespace, self.pkgname])
        self.logging = Logging("INFO")
Beispiel #2
0
    def __init__(self, name, share=True, namespace=None):
        """.. rubric:: Constructor


        :param str name:
        :param str share:
        """
        self.pkgname = name   # can be only the pkg name without namespace
        self.name = name      # can be pkg or namespace.pkg
        self.share = share
        self.namespace = namespace

        self.metainfo = {
                "pkgname": self.pkgname,
                "name":self.pkgname,
                "version": "version",
                "MINOR": '0',
                "MAJOR": '0',
                "MICRO": '1',
                "install_require": '[]',
                "description": "Put a short description here",
                "author": "yourname",
                "email": "*****@*****.**",
                "namespace": self.namespace,
        }
        if self.namespace:
            self.metainfo["name"] = ".".join([self.namespace, self.pkgname])
            self.metainfo["url"] = os.sep.join([self.namespace, self.pkgname])
        self.logging = Logging("INFO")
Beispiel #3
0
import pkg_resources
try:
    version = pkg_resources.require("sequana")[0].version
except:
    version = ">=0.7.1"

try:
    from easydev.logging_tools import Logging
    logger = Logging("sequana", "WARNING")
except:
    import colorlog
    logger = colorlog.getLogger("sequana")

from easydev import CustomConfig
configuration = CustomConfig("sequana", verbose=False)
sequana_config_path = configuration.user_config_dir

# This must be import before all other modules (sequana_data function)
from .datatools import sequana_data

from .assembly import *
from .adapters import AdapterReader, FindAdaptersFromDesign, Adapter
from .bamtools import BAM, SAMFlags, SAM, CRAM
from .bedtools import GenomeCov
from .cigar import Cigar
from .coverage import Coverage
from .expdesign import ExpDesignAdapter
from .fastq import FastQ, FastQC, Identifier
from .fasta import FastA
from .freebayes_vcf_filter import VCF_freebayes
from .freebayes_bcf_filter import BCF_freebayes
Beispiel #4
0
except:
    version = __version__

import os
import colorlog

# This will create a HOME/.config/bioconvert where files (e.g., executables)
# can be downloaded
from easydev import CustomConfig
configuration = CustomConfig("bioconvert", verbose=True)

os.environ["GOPATH"]= os.environ["HOME"]+"/go"
os.environ["PATH"] = os.environ["GOPATH"]+"/bin/:"+os.environ["PATH"]

from easydev.logging_tools import Logging
logger = Logging("bioconvert", "INFO")


def bioconvert_script(filename, where=None):
    bioconvert_path = bioconvert.__path__[0]
    share = os.path.join(bioconvert_path, 'misc')
    if where:
        filename = os.path.join(share, where, filename)
    else:
        filename = os.path.join(share, filename)
    if not os.path.exists(filename):
        raise FileNotFoundError('unknown file {}'.format(filename))
    return filename


def bioconvert_data(filename, where=None):
class PackageBuilder(object):
    """simple class to automatically build a package layout

    .. doctest::
        :options: +SKIP

        >>> from easydev import PackageBuilder
        >>> p = PackageBuilder(name="testpackage")
        >>> p.buildPackage()

    For the time being, this example creates the following layout::

        pkg/
        |-- doc
        |   |-- source
        |   |-- _static
        |-- README.txt
        |-- setup.py
        |-- share
        |     |-- data
        |-- src
        |     |-- pkg
        |         |-- __init__.py
        |-- test

    You can avoid the shared directory creation.
    The namespace is not implemented so far.
    The doc directory is empty so far.

    The version is set to 0.0.1

    Metainfo in the setup file need to be filed but the package should already be functional.

    New modules can be added inside the src/pkgname directory.
    """
    def __init__(self, name, share=True, namespace=None):
        """.. rubric:: Constructor


        :param str name:
        :param str share:
        """
        self.pkgname = name   # can be only the pkg name without namespace
        self.name = name      # can be pkg or namespace.pkg
        self.share = share
        self.namespace = namespace

        self.metainfo = {
                "pkgname": self.pkgname,
                "name":self.pkgname,
                "version": "version",
                "MINOR": '0',
                "MAJOR": '0',
                "MICRO": '1',
                "install_require": '[]',
                "description": "Put a short description here",
                "author": "yourname",
                "email": "*****@*****.**",
                "namespace": self.namespace,
        }
        if self.namespace:
            self.metainfo["name"] = ".".join([self.namespace, self.pkgname])
            self.metainfo["url"] = os.sep.join([self.namespace, self.pkgname])
        self.logging = Logging("INFO")
                    #self.init()

    def init(self, force=False):
        self.logging.info("Creating the package directory")
        if os.path.isdir(self.pkgname):
            self.logging.warning("Directory %s already exists." % self.pkgname)
            self.logging.warning("You are about to delete this directory %s. " % self.pkgname)
            if force==True:
                res = "y"
            else:
                res = raw_input("Do you wish to proceed (y/n)?")
            if res == "y":
                import shutil
                shutil.rmtree(self.pkgname)
                os.mkdir(self.pkgname)
                return True
            else:
                return False
        else:
            os.mkdir(self.pkgname)
            return True

    def create_namespace(self): #pragma: no cover
        if self.namespace == None:
            self.logging.warning("namespace is not set, cannot create namespace directories")
            return

        dir1 = "src" + os.sep + self.namespace
        dir2 = "src" + os.sep + self.namespace + os.sep + self.pkgname

        self._mkdir(dir1)
        self._mkdir(dir2)
        f = open(self.pkgname + os.sep + dir1 + os.sep + "__init__.py", "w")
        f.write(namespace_init_template)
        f.close()

        f = open(self.pkgname + os.sep + dir2 + os.sep + "__init__.py", "w")
        f.write(namespace_init_pkg_template % self.metainfo)
        f.close()

    def create_setup(self):
        """Creates a setup.py file"""
        self.logging.info("Creating the setup.py file (you will need to update the metadata!")
        filename = self.pkgname + os.sep + "setup.py"
        f = open(filename, "w")
        f.write(setup_template1 % self.metainfo)
        if self.namespace == None:
            f.write(setup_template2 % self.metainfo)
        else:
            f.write(setup_template3 % self.metainfo)
        f.close()

        # config file
        filename = self.pkgname + os.sep + "setup.cfg"
        f = open(filename, "w")
        f.write("# a setup configuration")
        f.write(setup_cfg_template % self.metainfo)
        f.close()

    def create_readme(self):
        """Creates a README file"""
        self.logging.info("Creating a README file")
        filename = self.pkgname + os.sep + "README.txt"
        f = open(filename, "w")
        f.write("""Provide some information to users about this package.""")
        f.close()

    def create_sphinx_directory(self):
        """Create layout for sphinx documentation"""
        self._mkdir("doc")
        self._mkdir("doc" + os.sep + "source")
        self._mkdir("doc" + os.sep + "_static")

    def create_test_directory(self):
        """Create a test directory"""
        self._mkdir("test")

    def _mkdir(self, name):
        filename = self.pkgname + os.sep
        self.logging.info("Creating a directory %s " % (filename + name))
        os.mkdir(filename + name)

    def create_src_directory(self):
        """Create a source directory and empty __init__ file"""
        self._mkdir("src")
        dirname = "src" + os.sep + self.pkgname
        self._mkdir(dirname)
        dirname = self.pkgname + os.sep + dirname
        self.logging.info("Create %s/__init__ file " % dirname)
        f = open(dirname + os.sep + "__init__.py", "w")
        f.write("""__version__ = "$Rev: 10 $"
import pkg_resources
try:
    version = pkg_resources.require("%(name)s")[0].version
except:
    version = __version__
""" % self.metainfo)

        f.close()

    def create_share_directory(self):
        """Create share/data directory if required"""
        self._mkdir("share")
        self._mkdir("share" + os.sep + "data")

    def buildPackage(self, force=False):
        """Builds the entire package

        This function removes the directory "pkgname" if it exists,
        to create it back (empty), and then calsl the methods starting with "create" word.
        """
        res = self.init(force=force)
        if res == False:
            return
        self.create_setup()
        self.create_readme()
        self.create_sphinx_directory()
        self.create_test_directory()
        self.create_src_directory()
        if self.share:
            self.create_share_directory()
        if self.namespace:
            self.create_namespace()
Beispiel #6
0
import pkg_resources
try:
    version = pkg_resources.require("sequana_pipetools")[0].version
except:  #pragma: no cover
    version = ">=0.2.0"

from easydev.logging_tools import Logging
logger = Logging("sequana_pipetools", "WARNING")
# To keep the inheritance/propagation of levels. Logging from easydev will do
# the formatting only.
import colorlog
logger = colorlog.getLogger(logger.name)
Beispiel #7
0
class PackageBuilder(object):
    """simple class to automatically build a package layout

    .. doctest::
        :options: +SKIP

        >>> from easydev import PackageBuilder
        >>> p = PackageBuilder(name="testpackage")
        >>> p.buildPackage()

    For the time being, this example creates the following layout::

        pkg/
        |-- doc
        |   |-- source
        |   |-- _static
        |-- README.txt
        |-- setup.py
        |-- share
        |     |-- data
        |-- src
        |     |-- pkg
        |         |-- __init__.py
        |-- test

    You can avoid the shared directory creation.
    The namespace is not implemented so far.
    The doc directory is empty so far.

    The version is set to 0.0.1

    Metainfo in the setup file need to be filed but the package should already be functional.

    New modules can be added inside the src/pkgname directory.
    """
    def __init__(self, name, share=True, namespace=None):
        """.. rubric:: Constructor


        :param str name:
        :param str share:
        """
        self.pkgname = name   # can be only the pkg name without namespace
        self.name = name      # can be pkg or namespace.pkg
        self.share = share
        self.namespace = namespace

        self.metainfo = {
                "pkgname": self.pkgname,
                "name":self.pkgname,
                "version": "version",
                "MINOR": '0',
                "MAJOR": '0',
                "MICRO": '1',
                "install_require": '[]',
                "description": "Put a short description here",
                "author": "yourname",
                "email": "*****@*****.**",
                "namespace": self.namespace,
        }
        if self.namespace:
            self.metainfo["name"] = ".".join([self.namespace, self.pkgname])
            self.metainfo["url"] = os.sep.join([self.namespace, self.pkgname])
        self.logging = Logging("INFO")
                    #self.init()

    def init(self, force=False):
        self.logging.info("Creating the package directory")
        if os.path.isdir(self.pkgname):
            self.logging.warning("Directory %s already exists." % self.pkgname)
            self.logging.warning("You are about to delete this directory %s. " % self.pkgname)
            if force==True:
                res = "y"
            else:
                res = raw_input("Do you wish to proceed (y/n)?")
            if res == "y":
                import shutil
                shutil.rmtree(self.pkgname)
                os.mkdir(self.pkgname)
                return True
            else:
                return False
        else:
            os.mkdir(self.pkgname)
            return True

    def create_namespace(self):
        if self.namespace == None:
            self.logging.warning("namespace is not set, cannot create namespace directories")
            return

        dir1 = "src" + os.sep + self.namespace
        dir2 = "src" + os.sep + self.namespace + os.sep + self.pkgname

        self._mkdir(dir1)
        self._mkdir(dir2)
        f = open(self.pkgname + os.sep + dir1 + os.sep + "__init__.py", "w")
        f.write(namespace_init_template)
        f.close()

        f = open(self.pkgname + os.sep + dir2 + os.sep + "__init__.py", "w")
        f.write(namespace_init_pkg_template % self.metainfo)
        f.close()

    def create_setup(self):
        """Creates a setup.py file"""
        self.logging.info("Creating the setup.py file (you will need to update the metadata!")
        filename = self.pkgname + os.sep + "setup.py"
        f = open(filename, "w")
        f.write(setup_template1 % self.metainfo)
        if self.namespace == None:
            f.write(setup_template2 % self.metainfo)
        else:
            f.write(setup_template3 % self.metainfo)
        f.close()

        # config file
        filename = self.pkgname + os.sep + "setup.cfg"
        f = open(filename, "w")
        f.write("# a setup configuration")
        f.write(setup_cfg_template % self.metainfo)
        f.close()

    def create_readme(self):
        """Creates a README file"""
        self.logging.info("Creating a README file")
        filename = self.pkgname + os.sep + "README.txt"
        f = open(filename, "w")
        f.write("""Provide some information to users about this package.""")
        f.close()

    def create_sphinx_directory(self):
        """Create layout for sphinx documentation"""
        self._mkdir("doc")
        self._mkdir("doc" + os.sep + "source")
        self._mkdir("doc" + os.sep + "_static")

    def create_test_directory(self):
        """Create a test directory"""
        self._mkdir("test")

    def _mkdir(self, name):
        filename = self.pkgname + os.sep
        self.logging.info("Creating a directory %s " % (filename + name))
        os.mkdir(filename + name)

    def create_src_directory(self):
        """Create a source directory and empty __init__ file"""
        self._mkdir("src")
        dirname = "src" + os.sep + self.pkgname
        self._mkdir(dirname)
        dirname = self.pkgname + os.sep + dirname
        self.logging.info("Create %s/__init__ file " % dirname)
        f = open(dirname + os.sep + "__init__.py", "w")
        f.write("""__version__ = "$Rev: 10 $"
import pkg_resources
try:
    version = pkg_resources.require("%(name)s")[0].version
except:
    version = __version__
""" % self.metainfo)

        f.close()

    def create_share_directory(self):
        """Create share/data directory if required"""
        self._mkdir("share")
        self._mkdir("share" + os.sep + "data")

    def buildPackage(self, force=False):
        """Builds the entire package

        This function removes the directory "pkgname" if it exists,
        to create it back (empty), and then calsl the methods starting with "create" word.
        """
        res = self.init(force=force)
        if res == False:
            return
        self.create_setup()
        self.create_readme()
        self.create_sphinx_directory()
        self.create_test_directory()
        self.create_src_directory()
        if self.share:
            self.create_share_directory()
        if self.namespace:
            self.create_namespace()