Python distutils.core 模块,setup() 实例源码

我们从Python开源项目中,提取了以下12个代码示例,用于说明如何使用distutils.core.setup()

项目:abusehelper    作者:Exploit-install    | 项目源码 | 文件源码
def install_other(subdir):
    cwd = os.getcwd()
    path = os.path.join(cwd, subdir)

    try:
        os.chdir(path)
    except OSError, error:
        if error.errno not in (errno.ENOENT, errno.ENOTDIR):
            raise
        print >> sys.stderr, "Could not find directory %r" % path
        return

    try:
        module_info = imp.find_module("setup", ["."])
        imp.load_module("setup", *module_info)
    finally:
        os.chdir(cwd)
项目:sslstrip-hsts-openwrt    作者:adde88    | 项目源码 | 文件源码
def setup(**kw):
    """
    An alternative to distutils' setup() which is specially designed
    for Twisted subprojects.

    Pass twisted_subproject=projname if you want package and data
    files to automatically be found for you.

    Pass detectExtensions=detectorFunction if your project has
    extension modules. detectorFunction will be called with an
    instance of build_ext_twisted and should return a list of
    distutils Extensions.
    """
    if 'twisted_subproject' in kw:
        if 'twisted' not in os.listdir('.'):
            raise RuntimeError("Sorry, you need to run setup.py from the "
                               "toplevel source directory.")
        projname = kw['twisted_subproject']
        projdir = os.path.join('twisted', projname)

        kw['packages'] = getPackages(projdir, parent='twisted')
        kw['version'] = getVersion(projname)

        plugin = "twisted/plugins/twisted_" + projname + ".py"
        if os.path.exists(plugin):
            kw.setdefault('py_modules', []).append(plugin.replace("/", ".")[:-3])

        kw['data_files'] = getDataFiles(projdir, parent='twisted')

        del kw['twisted_subproject']
    else:
        if 'plugins' in kw:
            py_modules = []
            for plg in kw['plugins']:
                py_modules.append("twisted.plugins." + plg)
            kw.setdefault('py_modules', []).extend(py_modules)
            del kw['plugins']

    if 'cmdclass' not in kw:
        kw['cmdclass'] = {
            'install_data': install_data_twisted,
            'build_scripts': build_scripts_twisted}
        if sys.version_info[:3] < (2, 3, 0):
            kw['cmdclass']['build_py'] = build_py_twisted

    if 'detectExtensions' in kw:
        if 'ext_modules' not in kw:
            kw['ext_modules'] = [True] # distutils is so lame

        dE = kw['detectExtensions']
        del kw['detectExtensions']
        class my_build_ext(build_ext_twisted):
            detectExtensions = dE
        kw.setdefault('cmdclass', {})['build_ext'] = my_build_ext
    return core.setup(**kw)
项目:cgpm    作者:probcomp    | 项目源码 | 文件源码
def make_release_tree(self, base_dir, files):
        import os
        sdist.make_release_tree(self, base_dir, files)
        version_file = os.path.join(base_dir, 'VERSION')
        print('updating %s' % (version_file,))
        # Write to temporary file first and rename over permanent not
        # just to avoid atomicity issues (not likely an issue since if
        # interrupted the whole sdist directory is only partially
        # written) but because the upstream sdist may have made a hard
        # link, so overwriting in place will edit the source tree.
        with open(version_file + '.tmp', 'wb') as f:
            f.write('%s\n' % (pkg_version,))
        os.rename(version_file + '.tmp', version_file)

# XXX These should be attributes of `setup', but helpful distutils
# doesn't pass them through when it doesn't know about them a priori.
项目:sqlalchemy-stubs    作者:JelleZijlstra    | 项目源码 | 文件源码
def find_installable_stubs(package_names):
    """Find all stubs to install, for setup(data_files=).

    Arguments:
      package_names:  List of directories to search in.

    """
    result = []
    for package_name in package_names:
        for root, _, files in os.walk(package_name):
            files = [os.path.join(root, filename) for filename in files
                     if filename.endswith('.pyi')]
            if not files:
                continue
            target = os.path.join(
                'shared', 'type-hinting',
                'python{}.{}'.format(*sys.version_info[:2]),
                root)
            result.append((target, files))
    return result
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def macos_build():
    from setuptools import setup
    import shutil

    APP = ['chirp-%s.py' % CHIRP_VERSION]
    shutil.copy("chirpw", APP[0])
    DATA_FILES = [('../Frameworks', ['/opt/local/lib/libpangox-1.0.dylib']),
                  ('../Resources/', ['/opt/local/lib/pango']),
                  ]
    OPTIONS = {'argv_emulation': True, "includes": "gtk,atk,pangocairo,cairo"}

    setup(
        app=APP,
        data_files=DATA_FILES,
        options={'py2app': OPTIONS},
        setup_requires=['py2app'],
        )

    EXEC = 'bash ./build/macos/make_pango.sh ' + \
           '/opt/local dist/chirp-%s.app' % CHIRP_VERSION
    # print "exec string: %s" % EXEC
    os.system(EXEC)
项目:PortableApps.com-DevelopmentToolkit    作者:3D1T0R    | 项目源码 | 文件源码
def build():
# options['py2exe']['bundle_files']=1 and zipfile=None make it compress less
# well with UPX, so they're not turned on.
    argv = sys.argv
    sys.argv = [sys.argv[0], 'py2exe']
    success = setup(
    options={'py2exe': dict(compressed=1, optimize=1, includes=['sip'])},
    data_files=data_files,
    windows=[dict(
        script='main.py',
        icon_resources=[(1, 'resources/appicon.ico')],
        description='PortableApps.com Development Toolkit',
        # Not including the manifest as it makes the app crash for some reason
        #other_resources=[(24, 1, manifest)],

        dest_base='DevelopmentToolkit',

        # VersionInfo table stuff
        version=version,
        name='PortableApps.com Development Toolkit',
        comments=('A simple yet powerful way to develop portable apps. ' +
               'For additional details, visit PortableApps.com'),
        company_name='PortableApps.com',
        copyright='PortableApps.com',
        trademarks='PortableApps.com is a Trademark of Rare Ideas, LLC.',
        )],
    )
    sys.argv = argv
    return success
项目:snakefood    作者:Shapeways    | 项目源码 | 文件源码
def read_version():
    try:
        return open('VERSION', 'r').readline().strip()
    except IOError:
        _, e, _ = sys.exc_info()
        raise SystemExit(
            "Error: you must run setup from the root directory (%s)" % str(e))


# Include all files without having to create MANIFEST.in
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def default_build():
    from distutils.core import setup
    from glob import glob

    os.system("make -C locale clean all")

    desktop_files = glob("share/*.desktop")
    # form_files = glob("forms/*.x?l")
    image_files = glob("images/*")
    _locale_files = glob("locale/*/LC_MESSAGES/CHIRP.mo")
    stock_configs = glob("stock_configs/*")

    locale_files = []
    for f in _locale_files:
        locale_files.append(("share/chirp/%s" % os.path.dirname(f), [f]))

    print "LOC: %s" % str(locale_files)

    xsd_files = glob("chirp*.xsd")

    setup(
        name="chirp",
        packages=["chirp", "chirp.drivers", "chirp.ui"],
        version=CHIRP_VERSION,
        scripts=["chirpw"],
        data_files=[('share/applications', desktop_files),
                    ('share/chirp/images', image_files),
                    ('share/chirp', xsd_files),
                    ('share/doc/chirp', ['COPYING']),
                    ('share/pixmaps', ['share/chirp.png']),
                    ('share/man/man1', ["share/chirpw.1"]),
                    ('share/chirp/stock_configs', stock_configs),
                    ] + locale_files)
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def rpttool_build():
    from distutils.core import setup

    setup(name="rpttool",
          packages=["chirp"],
          version="0.3",
          scripts=["rpttool"],
          description="A frequency tool for ICOM D-STAR Repeaters",
          data_files=[('/usr/sbin', ["tools/icomsio.sh"])],
          )
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def setup(**kw):
    """
    An alternative to distutils' setup() which is specially designed
    for Twisted subprojects.

    Pass twisted_subproject=projname if you want package and data
    files to automatically be found for you.

    Pass detectExtensions=detectorFunction if your project has
    extension modules. detectorFunction will be called with an
    instance of build_ext_twisted and should return a list of
    distutils Extensions.
    """
    if 'twisted_subproject' in kw:
        if 'twisted' not in os.listdir('.'):
            raise RuntimeError("Sorry, you need to run setup.py from the "
                               "toplevel source directory.")
        projname = kw['twisted_subproject']
        projdir = os.path.join('twisted', projname)

        kw['packages'] = getPackages(projdir, parent='twisted')
        kw['version'] = getVersion(projname)

        plugin = "twisted/plugins/twisted_" + projname + ".py"
        if os.path.exists(plugin):
            kw.setdefault('py_modules', []).append(plugin.replace("/", ".")[:-3])

        kw['data_files'] = getDataFiles(projdir, parent='twisted')

        del kw['twisted_subproject']
    else:
        if 'plugins' in kw:
            py_modules = []
            for plg in kw['plugins']:
                py_modules.append("twisted.plugins." + plg)
            kw.setdefault('py_modules', []).extend(py_modules)
            del kw['plugins']

    if 'cmdclass' not in kw:
        kw['cmdclass'] = {
            'install_data': install_data_twisted,
            'build_scripts': build_scripts_twisted}
        if sys.version_info[:3] < (2, 3, 0):
            kw['cmdclass']['build_py'] = build_py_twisted

    if 'detectExtensions' in kw:
        if 'ext_modules' not in kw:
            kw['ext_modules'] = [True] # distutils is so lame

        dE = kw['detectExtensions']
        del kw['detectExtensions']
        class my_build_ext(build_ext_twisted):
            detectExtensions = dE
        kw.setdefault('cmdclass', {})['build_ext'] = my_build_ext
    return core.setup(**kw)
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
def run(self):
        if os.path.isdir(self.dist_dir):  # Erase previous destination dir
            shutil.rmtree(self.dist_dir)

        # Use the default pygame icon, if none given
        if self.icon_file is None:
            path = os.path.split(pygame.__file__)[0]
            self.icon_file = os.path.join(path, 'pygame.ico')

        # List all data files to add
        extra_datas = ["__init__.py", "CHANGES.txt", "CREDITS.txt", "eduactiv8.py", "LICENSE", "README.txt"]
        for data in self.extra_datas:
            if os.path.isdir(data):
                extra_datas.extend(self.find_data_files(data, '*'))
            else:
                extra_datas.append(('.', [data]))

        setup(
            cmdclass={'py2exe': pygame2exe},
            version=self.project_version,
            description=self.project_description,
            name=self.project_name,
            url=self.project_url,
            author=self.author_name,
            author_email=self.author_email,
            license=self.license,

            # targets to build
            # console = [{
            windows=[{
                'script': self.script,
                'icon_resources': [(0, self.icon_file)],
                'copyright': self.copyright
            }],
            options={'py2exe': {'optimize': 2, 'bundle_files': 1, 'compressed': True,
                                'excludes': self.exclude_modules, 'packages': self.extra_modules,
                                'dll_excludes': self.exclude_dll,
                                'includes': self.extra_scripts}},
            zipfile=self.zipfile_name,
            data_files=extra_datas,
            dist_dir=self.dist_dir
        )

        if os.path.isdir('build'):  # Clean up build dir
            shutil.rmtree('build')
项目:chirp_fork    作者:mach327    | 项目源码 | 文件源码
def win32_build():
    from distutils.core import setup
    import py2exe

    try:
        # if this doesn't work, try import modulefinder
        import py2exe.mf as modulefinder
        import win32com
        for p in win32com.__path__[1:]:
            modulefinder.AddPackagePath("win32com", p)
        for extra in ["win32com.shell"]:  # ,"win32com.mapi"
            __import__(extra)
            m = sys.modules[extra]
            for p in m.__path__[1:]:
                modulefinder.AddPackagePath(extra, p)
    except ImportError:
        # no build path setup, no worries.
        pass

    staticify_chirp_module()
    staticify_drivers_module()

    opts = {
        "py2exe": {
            "includes": "pango,atk,gobject,cairo,pangocairo," +
                        "win32gui,win32com,win32com.shell," +
                        "email.iterators,email.generator,gio",

            "compressed": 1,
            "optimize": 2,
            "bundle_files": 3,
            # "packages": ""
            }
        }

    mods = []
    for mod in chirp.__all__:
        mods.append("chirp.%s" % mod)
    for mod in chirp.drivers.__all__:
        mods.append("chirp.drivers.%s" % mod)
    opts["py2exe"]["includes"] += ("," + ",".join(mods))

    setup(
        zipfile=None,
        windows=[{'script':         "chirpw",
                  'icon_resources': [(0x0004, 'share/chirp.ico')],
                  }],
        options=opts)