Exemplo n.º 1
0
            build_rust.debug = self.debug
            os.environ['CARGO_TARGET_DIR'] = (
                str(pathlib.Path(self.build_temp) / 'rust' / 'extensions'))
            build_rust.run()

            for src, dst in copy_list:
                shutil.copyfile(src, dst)

        super().run()


if setuptools_rust is not None:
    rust_extensions = [
        setuptools_rust.RustExtension(
            "edb._edgeql_rust",
            path="edb/edgeql-rust/Cargo.toml",
            binding=setuptools_rust.Binding.RustCPython,
        ),
        setuptools_rust.RustExtension(
            "edb._graphql_rewrite",
            path="edb/graphql-rewrite/Cargo.toml",
            binding=setuptools_rust.Binding.RustCPython,
        ),
    ]
else:
    rust_extensions = []


setuptools.setup(
    setup_requires=RUNTIME_DEPS + BUILD_DEPS,
    use_scm_version=True,
Exemplo n.º 2
0
    def wrapper(func):
        def object2binding(obj):
            # use pxt default binding
            if obj is None:
                return setuptools_rust.utils.Binding.NoBinding

            # no conversion needed
            if isinstance(obj, setuptools_rust.utils.Binding):
                return obj

            # in case of a string, convert it to a binding type
            if isinstance(obj, str):
                obj = obj.lower()
                if obj == 'pyo3':
                    return setuptools_rust.utils.Binding.PyO3
                elif obj == 'rustcpython':
                    return setuptools_rust.utils.Binding.RustCPython
                elif obj == 'nobinding':
                    return setuptools_rust.utils.Binding.NoBinding

            raise ValueError('The specified python-rust binding "{}" '
                             'is not supported.'.format(obj))

        # get the package name and folder of the decorated function
        _, parent = pxt.helpers.function_frame(0 if func is not None else -1)

        # get environment settings (they override function arguments)
        force_enabled = pxt.helpers.env_default(frame, 'FORCE', force)
        fallback_enabled = pxt.helpers.env_default(frame, 'ENABLE_FALLBACK',
                                                   enable_fallback)

        # gather relevant compile path information
        _, package_folder, tmp_path = _get_build_info(parent, cargo_file)
        cargo_path = os.path.split(cargo_file)[0]
        if os.path.isabs(cargo_path):
            cargo_path = os.path.relpath(cargo_path, package_folder)

        # Change the current working directory to the package folder.
        # This way, the build function can be used the same way by
        # different packages (the working directory is always the package).
        with pxt.helpers.chdir(package_folder):
            # Use the module name specified in the Cargo.toml file
            # if no name is provided by the user.
            if name is None:
                # make sure toml is installed
                if importlib.util.find_spec('toml') is None:
                    raise RuntimeError(
                        '"toml" module could not be found. Please '
                        'make sure you have "toml" installed.')
                import toml
                config = toml.load(cargo_file)
                if 'lib' in config and 'name' in config['lib']:
                    lib_name = config['lib']['name']
                else:
                    raise KeyError(
                        'Cargo file does not specify a `name` in `[lib]`.')
            else:
                lib_name = name

            # get binary file path
            binary_file = pxt.helpers.get_binary_name(
                os.path.join(package_folder, cargo_path, lib_name))
            result = func if func is not None else binary_file

            # only check for changes if compilation should not be forced
            if not force_enabled:
                # get source file path
                source_files = pxt.helpers.recursive_file_search(
                    ext=['rs', 'toml'])

                # get target and source file timestamps
                binary_timestamp = os.path.getmtime(
                    binary_file) if os.path.exists(binary_file) else 0
                source_timestamp = [os.path.getmtime(f) for f in source_files
                                    ] if len(source_files) > 0 else [0]

                # if all binary files are newer than all source files
                # there are no changes that make compilation necessary
                if binary_timestamp > max(source_timestamp):
                    return result

            # make sure setuptools_rust is installed
            if importlib.util.find_spec('setuptools_rust') is None:
                return pxt.helpers.fallback(
                    RuntimeError(
                        '"setuptools_rust" module could not be found. Please '
                        'make sure you have "setuptools-rust" installed.'),
                    result, fallback_enabled)

            # evaluate the binding keyword argument for the rust-python binding to be used
            import setuptools_rust
            kwargs['binding'] = object2binding(
                kwargs['binding'] if 'binding' in kwargs else None)

            # build the rust extension
            namespace = os.path.join(cargo_path,
                                     lib_name).replace(os.path.sep, '.')
            extension = setuptools_rust.RustExtension(namespace, cargo_file,
                                                      **kwargs)
            setuptools.setup(script_args=[
                'build_ext', '--build-temp={}'.format(tmp_path), '--force',
                '--inplace'
            ],
                             rust_extensions=[extension],
                             zip_safe=False)

            return result
Exemplo n.º 3
0
            build_rust.debug = self.debug
            os.environ['CARGO_TARGET_DIR'] = (str(
                pathlib.Path(self.build_temp) / 'rust'))
            build_rust.run()

            for src, dst in copy_list:
                shutil.copyfile(src, dst)

        super().run()


if setuptools_rust is not None:
    rust_extensions = [
        setuptools_rust.RustExtension(
            "edb._edgeql_rust",
            path="edgedb-rust/edgeql-python/Cargo.toml",
            binding=setuptools_rust.Binding.RustCPython),
    ]
else:
    rust_extensions = []

setuptools.setup(
    setup_requires=RUNTIME_DEPS + BUILD_DEPS,
    use_scm_version=True,
    name='edgedb-server',
    description='EdgeDB Server',
    author='MagicStack Inc.',
    author_email='*****@*****.**',
    packages=['edb'],
    include_package_data=True,
    cmdclass={
Exemplo n.º 4
0
#!/usr/bin/env python
# coding: utf-8
import setuptools
import setuptools_rust as rust

setuptools.setup(name="hello",
                 author="Martin Larralde",
                 author_email="*****@*****.**",
                 description="Example Python module using pyo3-built",
                 setup_requires=[
                     "setuptools",
                     "setuptools-rust ~=0.9",
                 ],
                 rust_extensions=[
                     rust.RustExtension(
                         "hello",
                         "hello/Cargo.toml",
                         binding=rust.Binding.PyO3,
                         strip=rust.Strip.Debug,
                     )
                 ])
Exemplo n.º 5
0
                shutil.copyfileobj(res, dst)

        self.announce("installing Rust compiler to {}".format(self.build_temp),
                      level=INFO)
        subprocess.call([
            "sh", rustup_sh, "-y", "--default-toolchain", toolchain,
            "--profile", profile, "--no-modify-path"
        ])

        self.announce("updating $PATH variable to use local Rust compiler",
                      level=INFO)
        os.environ["PATH"] = ":".join([
            os.path.abspath(os.path.join(os.environ["CARGO_HOME"], "bin")),
            os.environ["PATH"]
        ])


setuptools.setup(
    setup_requires=["setuptools", "setuptools_rust"],
    cmdclass=dict(sdist=sdist, build_rust=build_rust),
    rust_extensions=[
        rust.RustExtension(
            "fastobo",
            path="Cargo.toml",
            binding=rust.Binding.PyO3,
            strip=rust.Strip.Debug,
            features=["extension-module"],
        )
    ],
)
Exemplo n.º 6
0
#!/usr/bin/env python3

import os

import setuptools
import setuptools_rust as rust

setuptools.setup(
    setup_requires=["setuptools", "setuptools_rust"],
    rust_extensions=[
        rust.RustExtension("fastobo",
                           path="fastobo-py/Cargo.toml",
                           binding=rust.Binding.PyO3,
                           strip=rust.Strip.Debug)
    ],
)
Exemplo n.º 7
0
from pathlib import Path

p = Path(__file__)

setup_requires = ['setuptools', 'setuptools_rust', 'pytest-runner']

install_requires = []

test_require = ['pytest-cov', 'pytest-html', 'pytest']

setuptools.setup(
    name="frontier_graph",
    version="0.1.0",
    python_requires='>3.5',
    author="Koji Ono",
    author_email="*****@*****.**",
    description="Graph Proximity Search Library based on Frontiaer Algorithm.",
    url='https://github.com/0h-n0/frontier_subgraph',
    long_description=(p.parent / 'README.md').open(encoding='utf-8').read(),
    packages=["src", "frontier_graph"],
    install_requires=install_requires,
    setup_requires=setup_requires,
    rust_extensions=[rust.RustExtension("frontier_graph.frontier")],
    tests_require=test_require,
    extras_require={'docs': ['sphinx >= 1.4', 'sphinx_rtd_theme']},
    classifiers=[
        'Programming Language :: Python :: 3.6',
    ],
    zip_safe=False,
)
Exemplo n.º 8
0
                shutil.copyfileobj(res, dst)

        self.announce("installing Rust compiler to {}".format(self.build_temp),
                      level=INFO)
        subprocess.call([
            "/bin/sh", rustup_sh, "-y", "--default-toolchain", toolchain,
            "--profile", profile, "--no-modify-path"
        ])

        self.announce("updating $PATH variable to use local Rust compiler",
                      level=INFO)
        os.environ["PATH"] = ":".join([
            os.path.abspath(os.path.join(os.environ["CARGO_HOME"], "bin")),
            os.environ["PATH"]
        ])


setuptools.setup(
    cmdclass=dict(build_rust=build_rust, sdist=sdist),
    rust_extensions=[
        setuptools_rust.RustExtension(
            "sphinxcontrib.svgbob._svgbob",
            path=os.path.join("sphinxcontrib", "svgbob", "_svgbob",
                              "Cargo.toml"),
            binding=setuptools_rust.Binding.PyO3,
            strip=setuptools_rust.Strip.Debug,
            features=["extension-module"],
        )
    ],
)