Example #1
0
def build_sample_plugin():
    plugin_src_dir = os.path.join(os.path.dirname(__file__),
                                  '../../samples/scrapy-splitvariants-plugin')
    with cd(plugin_src_dir):
        if os.path.exists('dist'):
            shutil.rmtree('dist')
        d = Distribution(
            dict(
                version='1.0',
                name='scrapy_splitvariants_plugin',
                description='scrapy_splitvariants_plugin',
                packages=find_packages(exclude=['tests', 'tests.*']),
                entry_points={
                    'scrapydd.spliderplugin': [
                        'splitvariants = scrapy_splitvariants_plugin.plugin:Plugin',
                    ],
                },
                install_requires=['scrapy', 'scrapy-splitvariants'],
                zip_safe=True,
            ))
        d.script_name = 'setup.py'
        d.script_args = ['--quiet', 'clean', 'bdist_egg']
        d.parse_command_line()
        d.run_commands()

        egg_name = os.listdir('dist')[0]
        return os.path.abspath(os.path.join('dist', egg_name))
Example #2
0
 def get_install_lib(args):
     # This helper uses the distutils/setuptools machinery to determine
     # where a command will install files based on the arguments passed
     # to setup.py
     dist = Distribution({'script_args': args})
     dist.parse_command_line()
     install_cmd = dist.get_command_obj('install')
     install_cmd.ensure_finalized()
     return install_cmd.install_lib
Example #3
0
 def get_install_lib(args):
     # This helper uses the distutils/setuptools machinery to determine
     # where a command will install files based on the arguments passed
     # to setup.py
     dist = Distribution({'script_args': args})
     dist.parse_command_line()
     install_cmd = dist.get_command_obj('install')
     install_cmd.ensure_finalized()
     return install_cmd.install_lib
Example #4
0
def executable(request) -> pathlib.PosixPath:
    """Let setuptools compute the path to the built executable"""
    with chdir(request.config.rootdir) as root_dir:
        command = "build"
        distribution = Distribution({
            "script_name": __file__,
            "script_args": [command],
        })
        distribution.parse_config_files()
        distribution.parse_command_line()
        command = distribution.get_command_obj(command)
        command.ensure_finalized()
        return (pathlib.PosixPath(root_dir).absolute() /
                command.build_platlib / "hades-dhcp-script")
Example #5
0
    def getprefix(self):
        '''Retrieve setup tool calculated prefix

        :returns: prefix
        :rtype: string
        '''
        dist = Distribution({'cmdclass': {'install': OnlyGetScriptPath}})
        dist.dry_run = True  # not sure if necessary, but to be safe
        dist.parse_config_files()
        try:
            dist.parse_command_line()
        except (distutils.errors.DistutilsArgError, AttributeError):
            pass
        command = dist.get_command_obj('install')
        command.ensure_finalized()
        command.run()
        prefix = dist.install_scripts.replace('/bin', '')
        return prefix
Example #6
0
def extra_link_args():
    """
    Add arguments for Data Execution Prevention and ASLR.
    This is only relevant for older Python versions.

    :return: `list` of arguments
    """
    dist = Distribution()
    dist.parse_config_files()
    try:
        dist.parse_command_line()
    except (TypeError, DistutilsArgError):  # Happens with setup.py --help
        pass

    build = dist.get_command_obj('build')
    build.ensure_finalized()
    if new_compiler(compiler=build.compiler).compiler_type == 'msvc':
        return ["/NXCOMPAT", "/DYNAMICBASE"]

    return []
Example #7
0
def compile_c(code: str) -> Dict[str, Any]:
    """Compiles C code into a C extension, loads the extension and returns the included dict of compiled PyCapsules.

    This assumes that the code defines a module member
    ``__capi__``.

    :meta private:"""
    build_dir = "build"
    c_file_path = os.path.join(build_dir, "src", "module.c")
    prepare_c_src(c_file_path, code)
    dist = Distribution({
        "name":
        "c_api",
        "ext_modules": [Extension("c_api", sources=[c_file_path])],
        "script_name":
        "setup.py",
        "script_args": ["build_ext", "--inplace"],
    })
    dist.parse_command_line()
    dist.run_commands()
    sys.path.append(os.getcwd())
    return importlib.import_module("c_api").__capi__  # type: ignore
Example #8
0
import os
import sys
# Third-party modules - we depend on numpy for everything
import numpy

# Obtain the numpy include directory.  This logic works across numpy versions.
try:
    numpy_include = numpy.get_include()
except AttributeError:
    numpy_include = numpy.get_numpy_include()

# Get our own instance of Distribution
dist = Distribution()
dist.parse_config_files()
dist.parse_command_line()

# Get prefix from either config file or command line
prefix = dist.get_option_dict('install')['prefix'][1]
print("Prefix is: " + prefix)

pymod_name = "parcels_nodes"
py_version = 'python%d.%d' % (sys.version_info[0], sys.version_info[1])
print(sys.prefix)
PCLS_NODES_HOME = '/git_code/list_set_experiments'  # '/vps/otbknox/williams/OTB_2.0'
PCLS_NODES_INCLDIR = [
    os.path.join(PCLS_NODES_HOME, pymod_name, 'include'),
    os.path.join(sys.prefix, 'include'),
    os.path.join(sys.prefix, 'include', py_version),
    os.path.join(sys.prefix, 'lib', py_version, 'site-packages', pymod_name,
                 'include'),