This file is indexed.

/usr/lib/python2.7/dist-packages/easydev/package.py is in python-easydev 0.9.35+dfsg-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# -*- python -*-
# -*- coding: utf-8 -*-
#
#  This file is part of the easydev software
#
#  Copyright (c) 2011-2017
#
#  File author(s): Thomas Cokelaer <cokelaer@gmail.com>
#
#  Distributed under the GPLv3 License.
#  See accompanying file LICENSE.txt or copy at
#      http://www.gnu.org/licenses/gpl-3.0.html
#
#  Website: https://github.com/cokelaer/easydev
#  Documentation: http://easydev-python.readthedocs.io
#
##############################################################################
import os
from easydev.logging_tools import Logging

__all__ = ["PackageBuilder"]



setup_template1 = """# -*- coding: utf-8 -*-
__revision__ = "$Id$" # for the SVN Id
import sys
import os
from setuptools import setup, find_packages
import glob

_MAJOR               = %(MAJOR)s
_MINOR               = %(MINOR)s
_MICRO               = %(MICRO)s
version              = '%%d.%%d.%%d' %% (_MAJOR, _MINOR, _MICRO)
release              = '%%d.%%d' %% (_MAJOR, _MINOR)

metainfo = {
    'authors': {"main": ("%(author)s", "%(email)s")},
    'version': version,
    'license' : 'GPL',
    'download_url' : ['http://pypi.python.org/pypi/%(name)s'],
    'url' : ["http://pythonhosted.org/%(name)s/"],
    'description': "%(description)s" ,
    'platforms' : ['Linux', 'Unix', 'MacOsX', 'Windows'],
    'keywords' : [''],
    'classifiers' : [
          'Development Status :: 4 - Beta',
          'Intended Audience :: Developers',
          'Intended Audience :: Science/Research',
          'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
          'Operating System :: OS Independent',
          'Programming Language :: Python :: 2.7',
          'Topic :: Software Development :: Libraries :: Python Modules',
          'Topic :: Scientific/Engineering :: Bio-Informatics',
          'Topic :: Scientific/Engineering :: Information Analysis',
          'Topic :: Scientific/Engineering :: Mathematics',
          'Topic :: Scientific/Engineering :: Physics']
    }

# files in share/data
datadir = os.path.join('share','data')
datafiles = [(datadir, [f for f in glob.glob(os.path.join(datadir, '*'))])]

"""


setup_template2 = """
setup(
    name             = "%(name)s",
    version          = version,
    maintainer       = metainfo['authors']['main'][0],
    maintainer_email = metainfo['authors']['main'][1],
    author           = metainfo['authors']['main'][0],
    author_email     = metainfo['authors']['main'][1],
    long_description = open("README.txt").read(),
    keywords         = metainfo['keywords'],
    description      = metainfo['description'],
    license          = metainfo['license'],
    platforms        = metainfo['platforms'],
    url              = metainfo['url'],
    download_url     = metainfo['download_url'],
    classifiers      = metainfo['classifiers'],

    # package installation
    package_dir = {'':'src'},
    packages = ["%(pkgname)s"],

    install_requires = %(install_require)s,

    # uncomment if you have share/data files
    #data_files = datafiles,

    #use_2to3 = True, # causes issue with nosetests
)
"""

setup_template3 = """
namespace = '%(namespace)s'

# messy but works for namespaces under Python 2.7
pkgs = [pkg for pkg in find_packages("src")]
top_pkgs = [pkg for pkg in pkgs if  len(pkg.split('.')) < 2]
package_dir = {"": "src"}
for pkg in top_pkgs:
    package_dir[namespace + "." + pkg] = "src" + os.sep + pkg

setup(
    name             = "%(name)s",
    version          = version,
    maintainer       = metainfo['authors']['main'][0],
    maintainer_email = metainfo['authors']['main'][1],
    author           = metainfo['authors']['main'][0],
    author_email     = metainfo['authors']['main'][1],
    long_description = open("README.txt").read(),
    keywords         = metainfo['keywords'],
    description      = metainfo['description'],
    license          = metainfo['license'],
    platforms        = metainfo['platforms'],
    url              = metainfo['url'],
    download_url     = metainfo['download_url'],
    classifiers      = metainfo['classifiers'],

    # package installation
    package_dir = package_dir,
    packages = find_packages("src"),
    namespace_packages = [namespace],

    install_requires = %(install_require)s,
    # uncomment if you have share/data files
    #data_files = datafiles,

    #use_2to3 = True, # causes issue with nosetests
)
"""


namespace_init_template = """try:
    __import__('pkg_resources').declare_namespace(__name__)
except:
    from pkgutil import extend_path
    __path__ = extend_path(__path__, __name__)
"""

namespace_init_pkg_template = """# Redirect path
import os
cdir = os.path.dirname(__file__)
pdir = os.path.join(cdir, "../../%(pkgname)s")
pdir = os.path.abspath(pdir)

__path__ = [pdir] + __path__[:]

from %(namespace)s.%(pkgname)s.__init__ import *
del cdir
del pdir
"""


setup_cfg_template = """
[build_sphinx]
source_dir = doc/source
build_dir  = doc/build
all_files  = 1

[nosetests]
where=test
with_coverage=
cover_package=%(name)s
cover_erase=
verbosity=2
;cover_html=
;cover_html_dir=html
logging_level=ERROR

[upload_docs]
upload_dir=doc/build/html/
"""



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": "email@whatever.org",
                "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()


import argparse
class OptionsBuildPackage(argparse.ArgumentParser):
    """Options Parser for BuildPackage

    """
    def  __init__(self, args, version="1.0", prog="easydev_buildPackage"):
        usage = """USAGE: %s --pkgname pkgName""" % prog
        super(OptionsBuildPackage, self).__init__(usage=usage, prog=prog)
        self.add_general_options()
        self.options = self.parse_args(args)
        self.version = version

    def add_general_options(self):
        #self.add_argument('--version',
        #        action='version', version=self.version)
        self.add_argument("--pkgname", dest="pkgname",
            help="Name of the package to be created")
        self.add_argument("--package", dest="pkgname",
            help="Name of the package to be created")
        self.add_argument("--namespace", dest="namespace", default=None,
            help="If provided, creates a namespace.")
        self.add_argument("--no-share-directory", action="store_false",
            help="if five, the share directory is not created")
        self.add_argument("--verbosity", dest="verbosity", default="INFO",
            help="set verbosity to INFO, WARNING or ERROR")

def buildPackage():
    """The executable easydev_buildPackage """
    import sys
    if len(sys.argv) > 1:
        parser = OptionsBuildPackage(sys.argv[1:])

        p = PackageBuilder(
            name=parser.options.pkgname,
            share=parser.options.no_share_directory,
            namespace=parser.options.namespace)
        p.logging.debugLevel = parser.options.verbosity
        p.buildPackage()
    else:
        parser = OptionsBuildPackage(["--help"])