示例#1
0
    def test_dont_write_bytecode(self):
        pkg_dir, dist = self.create_dist()
        cmd = build_py(dist)
        cmd.compile = 1
        cmd.optimize = 1
        old_dont_write_bytecode = sys.dont_write_bytecode
        sys.dont_write_bytecode = True
        try:
            cmd.byte_compile([])
        finally:
            sys.dont_write_bytecode = old_dont_write_bytecode

        self.assertIn('byte-compiling is disabled', self.logs[0][1])
示例#2
0
    def test_dont_write_bytecode(self):
        pkg_dir, dist = self.create_dist()
        cmd = build_py(dist)
        cmd.compile = 1
        cmd.optimize = 1
        old_dont_write_bytecode = sys.dont_write_bytecode
        sys.dont_write_bytecode = True
        try:
            cmd.byte_compile([])
        finally:
            sys.dont_write_bytecode = old_dont_write_bytecode

        self.assertIn('byte-compiling is disabled', self.logs[0][1])
    def test_package_data(self):
        sources = self.mkdtemp()
        f = open(os.path.join(sources, "__init__.py"), "w")
        try:
            f.write("# Pretend this is a package.")
        finally:
            f.close()
        f = open(os.path.join(sources, "README.txt"), "w")
        try:
            f.write("Info about this package")
        finally:
            f.close()

        destination = self.mkdtemp()

        dist = Distribution({
            "packages": ["pkg"],
            "package_dir": {
                "pkg": sources
            }
        })
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(sources, "setup.py")
        dist.command_obj["build"] = support.DummyCommand(force=0,
                                                         build_lib=destination)
        dist.packages = ["pkg"]
        dist.package_data = {"pkg": ["README.txt"]}
        dist.package_dir = {"pkg": sources}

        cmd = build_py(dist)
        cmd.compile = 1
        cmd.ensure_finalized()
        self.assertEqual(cmd.package_data, dist.package_data)

        cmd.run()

        # This makes sure the list of outputs includes byte-compiled
        # files for Python modules but not for package data files
        # (there shouldn't *be* byte-code files for those!).
        self.assertEqual(len(cmd.get_outputs()), 3)
        pkgdest = os.path.join(destination, "pkg")
        files = os.listdir(pkgdest)
        pycache_dir = os.path.join(pkgdest, "__pycache__")
        self.assertIn("__init__.py", files)
        self.assertIn("README.txt", files)
        if sys.dont_write_bytecode:
            self.assertFalse(os.path.exists(pycache_dir))
        else:
            pyc_files = os.listdir(pycache_dir)
            self.assertIn("__init__.%s.pyc" % sys.implementation.cache_tag,
                          pyc_files)
示例#4
0
    def test_byte_compile(self):
        project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
        os.chdir(project_dir)
        self.write_file('boiledeggs.py', 'import antigravity')
        cmd = build_py(dist)
        cmd.compile = 1
        cmd.build_lib = 'here'
        cmd.finalize_options()
        cmd.run()

        found = os.listdir(cmd.build_lib)
        self.assertEqual(sorted(found), ['__pycache__', 'boiledeggs.py'])
        found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
        self.assertEqual(found, ['boiledeggs.%s.pyc' % imp.get_tag()])
 def test_byte_compile_optimized(self):
     project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
     os.chdir(project_dir)
     self.write_file('boiledeggs.py', 'import antigravity')
     cmd = build_py(dist)
     cmd.compile = 0
     cmd.optimize = 1
     cmd.build_lib = 'here'
     cmd.finalize_options()
     cmd.run()
     found = os.listdir(cmd.build_lib)
     self.assertEqual(sorted(found), ['__pycache__', 'boiledeggs.py'])
     found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
     expect = 'boiledeggs.{}.opt-1.pyc'.format(sys.implementation.cache_tag)
     self.assertEqual(sorted(found), [expect])
示例#6
0
    def test_package_data(self):
        sources = self.mkdtemp()
        f = open(os.path.join(sources, "__init__.py"), "w")
        try:
            f.write("# Pretend this is a package.")
        finally:
            f.close()
        f = open(os.path.join(sources, "README.txt"), "w")
        try:
            f.write("Info about this package")
        finally:
            f.close()

        destination = self.mkdtemp()

        dist = Distribution({"packages": ["pkg"],
                             "package_dir": {"pkg": sources}})
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(sources, "setup.py")
        dist.command_obj["build"] = support.DummyCommand(
            force=0,
            build_lib=destination)
        dist.packages = ["pkg"]
        dist.package_data = {"pkg": ["README.txt"]}
        dist.package_dir = {"pkg": sources}

        cmd = build_py(dist)
        cmd.compile = 1
        cmd.ensure_finalized()
        self.assertEqual(cmd.package_data, dist.package_data)

        cmd.run()

        # This makes sure the list of outputs includes byte-compiled
        # files for Python modules but not for package data files
        # (there shouldn't *be* byte-code files for those!).
        self.assertEqual(len(cmd.get_outputs()), 3)
        pkgdest = os.path.join(destination, "pkg")
        files = os.listdir(pkgdest)
        pycache_dir = os.path.join(pkgdest, "__pycache__")
        self.assertIn("__init__.py", files)
        self.assertIn("README.txt", files)
        if sys.dont_write_bytecode:
            self.assertFalse(os.path.exists(pycache_dir))
        else:
            pyc_files = os.listdir(pycache_dir)
            self.assertIn("__init__.%s.pyc" % sys.implementation.cache_tag,
                          pyc_files)
    def test_dont_write_bytecode(self):
        # makes sure byte_compile is not used
        dist = self.create_dist()[1]
        cmd = build_py(dist)
        cmd.compile = 1
        cmd.optimize = 1

        old_dont_write_bytecode = sys.dont_write_bytecode
        sys.dont_write_bytecode = True
        try:
            cmd.byte_compile([])
        finally:
            sys.dont_write_bytecode = old_dont_write_bytecode

        self.assertIn('byte-compiling is disabled',
                      self.logs[0][1] % self.logs[0][2])
示例#8
0
    def test_byte_compile_optimized(self):
        project_dir, dist = self.create_dist(py_modules=['boiledeggs'])
        os.chdir(project_dir)
        self.write_file('boiledeggs.py', 'import antigravity')
        cmd = build_py(dist)
        cmd.compile = 0
        cmd.optimize = 1
        cmd.build_lib = 'here'
        cmd.finalize_options()
        cmd.run()

        found = os.listdir(cmd.build_lib)
        self.assertEqual(sorted(found), ['__pycache__', 'boiledeggs.py'])
        found = os.listdir(os.path.join(cmd.build_lib, '__pycache__'))
        expect = 'boiledeggs.{}.opt-1.pyc'.format(sys.implementation.cache_tag)
        self.assertEqual(sorted(found), [expect])
示例#9
0
    def test_dont_write_bytecode(self):
        # makes sure byte_compile is not used
        dist = self.create_dist()[1]
        cmd = build_py(dist)
        cmd.compile = 1
        cmd.optimize = 1

        old_dont_write_bytecode = sys.dont_write_bytecode
        sys.dont_write_bytecode = True
        try:
            cmd.byte_compile([])
        finally:
            sys.dont_write_bytecode = old_dont_write_bytecode

        self.assertIn('byte-compiling is disabled',
                      self.logs[0][1] % self.logs[0][2])
示例#10
0
    def false_setup(*args, **kwargs):
        cmdline = []
        setupdir = os.path.dirname(globals['__file__'])
        storepath = os.path.join(setupdir, 'setupargs-pypicontents.json')
        banned_options = [
            'setup_requires', 'test_requires', 'conda_buildnum', 'd2to1',
            'distclass', 'email', 'entry_points', 'executables', 'home_page',
            'include_package_data', 'install_requires', 'licesne',
            'namespace_packages', 'pbr', 'platform', 'use_2to3',
            'use_scm_version'
        ]

        from distutils.dist import Distribution
        from distutils.command.build_py import build_py
        from pkg_resources import EntryPoint

        for opt in banned_options:
            kwargs.pop(opt, None)

        kwargs.update({'script_name': globals['__file__'], 'script_args': []})

        bpy = build_py(Distribution(kwargs))
        bpy.finalize_options()
        _bpy_mods = bpy.find_all_modules()
        _join_mods = ['.'.join([p, m]).strip('.') for p, m, f in _bpy_mods]
        modules = [
            '.'.join(m.split('.')[:-1])
            if m.endswith('.__init__') or m.endswith('.__main__') else m
            for m in _join_mods
        ]

        if 'scripts' in kwargs:
            cmdline.extend([os.path.basename(s) for s in kwargs['scripts']])
        if 'entry_points' in kwargs:
            entrymap = EntryPoint.parse_map(kwargs['entry_points'])
            if 'console_scripts' in entrymap:
                cmdline.extend(entrymap['console_scripts'].keys())

        with open(storepath, 'w') as store:
            store.write(
                u(
                    json.dumps({
                        'modules': sorted(set(modules)),
                        'cmdline': sorted(set(cmdline))
                    })))
示例#11
0
    def test_package_data(self):
        sources = self.mkdtemp()
        f = open(os.path.join(sources, "__init__.py"), "w")
        f.write("# Pretend this is a package.")
        f.close()
        f = open(os.path.join(sources, "README.txt"), "w")
        f.write("Info about this package")
        f.close()

        destination = self.mkdtemp()

        dist = Distribution({
            "packages": ["pkg"],
            "package_dir": {
                "pkg": sources
            }
        })
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(sources, "setup.py")
        dist.command_obj["build"] = support.DummyCommand(force=0,
                                                         build_lib=destination)
        dist.packages = ["pkg"]
        dist.package_data = {"pkg": ["README.txt"]}
        dist.package_dir = {"pkg": sources}

        cmd = build_py(dist)
        cmd.compile = 1
        cmd.ensure_finalized()
        self.assertEqual(cmd.package_data, dist.package_data)

        cmd.run()

        # This makes sure the list of outputs includes byte-compiled
        # files for Python modules but not for package data files
        # (there shouldn't *be* byte-code files for those!).
        #
        self.assertEqual(len(cmd.get_outputs()), 3)
        pkgdest = os.path.join(destination, "pkg")
        files = os.listdir(pkgdest)
        self.assert_("__init__.py" in files)
        if sys.platform.startswith('java'):
            self.assert_("__init__$py.class" in files, files)
        else:
            self.assert_("__init__.pyc" in files)
        self.assert_("README.txt" in files)
示例#12
0
 def test_package_data(self):
     sources = self.mkdtemp()
     f = open(os.path.join(sources, '__init__.py'), 'w')
     try:
         f.write('# Pretend this is a package.')
     finally:
         f.close()
     f = open(os.path.join(sources, 'README.txt'), 'w')
     try:
         f.write('Info about this package')
     finally:
         f.close()
     destination = self.mkdtemp()
     dist = Distribution({
         'packages': ['pkg'],
         'package_dir': {
             'pkg': sources
         }
     })
     dist.script_name = os.path.join(sources, 'setup.py')
     dist.command_obj['build'] = support.DummyCommand(force=0,
                                                      build_lib=destination)
     dist.packages = ['pkg']
     dist.package_data = {'pkg': ['README.txt']}
     dist.package_dir = {'pkg': sources}
     cmd = build_py(dist)
     cmd.compile = 1
     cmd.ensure_finalized()
     self.assertEqual(cmd.package_data, dist.package_data)
     cmd.run()
     self.assertEqual(len(cmd.get_outputs()), 3)
     pkgdest = os.path.join(destination, 'pkg')
     files = os.listdir(pkgdest)
     pycache_dir = os.path.join(pkgdest, '__pycache__')
     self.assertIn('__init__.py', files)
     self.assertIn('README.txt', files)
     if sys.dont_write_bytecode:
         self.assertFalse(os.path.exists(pycache_dir))
     else:
         pyc_files = os.listdir(pycache_dir)
         self.assertIn('__init__.%s.pyc' % sys.implementation.cache_tag,
                       pyc_files)
示例#13
0
    def test_package_data(self):
        sources = self.mkdtemp()
        f = open(os.path.join(sources, "__init__.py"), "w")
        f.write("# Pretend this is a package.")
        f.close()
        f = open(os.path.join(sources, "README.txt"), "w")
        f.write("Info about this package")
        f.close()

        destination = self.mkdtemp()

        dist = Distribution({"packages": ["pkg"],
                             "package_dir": {"pkg": sources}})
        # script_name need not exist, it just need to be initialized
        dist.script_name = os.path.join(sources, "setup.py")
        dist.command_obj["build"] = support.DummyCommand(
            force=0,
            build_lib=destination)
        dist.packages = ["pkg"]
        dist.package_data = {"pkg": ["README.txt"]}
        dist.package_dir = {"pkg": sources}

        cmd = build_py(dist)
        cmd.compile = 1
        cmd.ensure_finalized()
        self.assertEqual(cmd.package_data, dist.package_data)

        cmd.run()

        # This makes sure the list of outputs includes byte-compiled
        # files for Python modules but not for package data files
        # (there shouldn't *be* byte-code files for those!).
        #
        self.assertEqual(len(cmd.get_outputs()), 3)
        pkgdest = os.path.join(destination, "pkg")
        files = os.listdir(pkgdest)
        self.assert_("__init__.py" in files)
        if sys.platform.startswith('java'):
            self.assert_("__init__$py.class" in files, files)
        else:
            self.assert_("__init__.pyc" in files)
        self.assert_("README.txt" in files)
示例#14
0
    def false_setup(*args, **kwargs):
        cmdline = []
        setupdir = os.path.dirname(globals['__file__'])
        storepath = os.path.join(setupdir, 'setupargs-pypicontents.json')
        banned_options = ['setup_requires', 'test_requires', 'conda_buildnum',
                          'd2to1', 'distclass', 'email', 'entry_points',
                          'executables', 'home_page', 'include_package_data',
                          'install_requires', 'licesne', 'namespace_packages',
                          'pbr', 'platform', 'use_2to3', 'use_scm_version']

        from distutils.dist import Distribution
        from distutils.command.build_py import build_py
        from pkg_resources import EntryPoint

        for opt in banned_options:
            kwargs.pop(opt, None)

        kwargs.update({'script_name': globals['__file__'],
                       'script_args': []})

        bpy = build_py(Distribution(kwargs))
        bpy.finalize_options()
        _bpy_mods = bpy.find_all_modules()
        _join_mods = ['.'.join([p, m]).strip('.') for p, m, f in _bpy_mods]
        modules = ['.'.join(m.split('.')[:-1])
                   if m.endswith('.__init__') or m.endswith('.__main__')
                   else m for m in _join_mods]

        if 'scripts' in kwargs:
            cmdline.extend([os.path.basename(s) for s in kwargs['scripts']])
        if 'entry_points' in kwargs:
            entrymap = EntryPoint.parse_map(kwargs['entry_points'])
            if 'console_scripts' in entrymap:
                cmdline.extend(entrymap['console_scripts'].keys())

        with open(storepath, 'w') as store:
            store.write(u(json.dumps({'modules': sorted(set(modules)),
                                      'cmdline': sorted(set(cmdline))})))
示例#15
0
def _get_version(dist, keyword, value):
    """
    Get the version from the package listed in the Distribution.
    """
    if not value:
        return

    from distutils.command import build_py

    sp_command = build_py.build_py(dist)
    sp_command.finalize_options()

    for item in sp_command.find_all_modules():
        if item[1] == "_version":
            version_file = {}

            with open(item[2]) as f:
                exec(f.read(), version_file)

            dist.metadata.version = version_file["__version__"].public()
            return None

    raise Exception("No _version.py found.")
示例#16
0
def _get_version(dist, keyword, value):
    """
    Get the version from the package listed in the Distribution.
    """
    if not value:
        return

    from distutils.command import build_py

    sp_command = build_py.build_py(dist)
    sp_command.finalize_options()

    for item in sp_command.find_all_modules():
        if item[1] == "_version":
            version_file = {}

            with open(item[2]) as f:
                exec(f.read(), version_file)

            dist.metadata.version = version_file["__version__"].public()
            return None

    raise Exception("No _version.py found.")
示例#17
0
    def test_package_data(self):
        sources = self.mkdtemp()
        f = open(os.path.join(sources, '__init__.py'), 'w')
        try:
            f.write('# Pretend this is a package.')
        finally:
            f.close()

        f = open(os.path.join(sources, 'README.txt'), 'w')
        try:
            f.write('Info about this package')
        finally:
            f.close()

        destination = self.mkdtemp()
        dist = Distribution({'packages': ['pkg'],
         'package_dir': {'pkg': sources}})
        dist.script_name = os.path.join(sources, 'setup.py')
        dist.command_obj['build'] = support.DummyCommand(force=0, build_lib=destination)
        dist.packages = ['pkg']
        dist.package_data = {'pkg': ['README.txt']}
        dist.package_dir = {'pkg': sources}
        cmd = build_py(dist)
        cmd.compile = 1
        cmd.ensure_finalized()
        self.assertEqual(cmd.package_data, dist.package_data)
        cmd.run()
        self.assertEqual(len(cmd.get_outputs()), 3)
        pkgdest = os.path.join(destination, 'pkg')
        files = os.listdir(pkgdest)
        self.assertIn('__init__.py', files)
        self.assertIn('README.txt', files)
        if sys.dont_write_bytecode:
            self.assertNotIn('__init__.pyc', files)
        else:
            self.assertIn('__init__.pyc', files)
示例#18
0
文件: setup.py 项目: mjlong/OpenMOC
                + "openmoc/cuda/double/openmoc_cuda_double.i"
            )

        build_ext.build_extensions(self)


# Run the distutils setup method for the complete build
dist = setup(
    name="openmoc",
    version="0.1.2",
    description="An open source method of characteristics code for "
    + "solving the 2D neutron distribution in nuclear reactors",
    author="Will Boyd",
    author_email="*****@*****.**",
    url="https://github.com/mit-crpg/OpenMOC",
    # Set the C/C++/CUDA extension modules built in setup_extension_modules()
    # in config.py based on the user-defined flags at compile time
    ext_modules=config.extensions,
    # Extract all of the Python packages for OpenMOC
    # (ie, openmoc.log, openmoc.materialize, etc)
    packages=config.packages,
    # Inject our custom compiler and linker triggers
    cmdclass={"build_ext": custom_build_ext, "install": custom_install},
)

# Rerun the build_py to setup links for C++ extension modules created by SWIG
# This prevents us from having to install twice
build_py = build_py(dist)
build_py.ensure_finalized()
build_py.run()
示例#19
0
    name='PyMobot',
    version='0.1',
    description='Mobot Control Python Library',
    author='David Ko',
    author_email='*****@*****.**',
    url='http://www.barobo.com',
    packages=['barobo'],
    ext_modules=[
        Extension(
            'barobo._mobot',
            ['barobo/mobot.i'],
            swig_opts=['-c++', '-I../'],
            include_dirs=[
                '../', '../BaroboConfigFile', '../BaroboConfigFile/mxml-2.7'
            ],
            define_macros=[('NONRELEASE', '1')],
            extra_compile_args=['-fpermissive'],
            library_dirs=[
                '../', '../BaroboConfigFile', '../BaroboConfigFile/mxml-2.7'
            ],
            libraries=[
                'baroboStatic', 'baroboconfigfile', 'mxml', 'pthread', 'ws2_32'
            ],
        )
    ],
)

build_py = build_py(dist)
build_py.ensure_finalized()
build_py.run()