Exemplo n.º 1
0
    def run_install_scripts(self):
        import configparser
        from setuptools.command.install_scripts import install_scripts
        from setuptools.dist import Distribution

        config = configparser.ConfigParser()
        config.read_string(self.wheel.entrypoints)

        entrypoints = {}
        for section in config:
            x = ["%s=%s" % k for k in config.items(section)]
            if x:
                entrypoints[section] = x

        settings = dict(
            name=self.wheel.name,
            entry_points=entrypoints,
            version=self.wheel.version,
        )

        dist = Distribution(settings)
        dist.script_name = "setup.py"
        cmd = install_scripts(dist)
        cmd.install_dir = str((self.root / "entrypoints").absolute())
        bs = cmd.get_finalized_command("build_scripts")
        bs.executable = "/usr/bin/python" + str(self.pyvers.major)
        cmd.ensure_finalized()

        # cmd.run() creates some files that we don't want in python cwd
        oldcwd = os.getcwd()
        os.chdir("/tmp")
        try:
            cmd.run()
        finally:
            os.chdir(oldcwd)
Exemplo n.º 2
0
 def _run_install_scripts(self, install_dir, executable=None):
     dist = Distribution(self.settings)
     dist.script_name = 'setup.py'
     cmd = install_scripts(dist)
     cmd.install_dir = install_dir
     if executable is not None:
         bs = cmd.get_finalized_command('build_scripts')
         bs.executable = executable
     cmd.ensure_finalized()
     with contexts.quiet():
         cmd.run()
 def _run_install_scripts(self, install_dir, executable=None):
     dist = Distribution(self.settings)
     dist.script_name = 'setup.py'
     cmd = install_scripts(dist)
     cmd.install_dir = install_dir
     if executable is not None:
         bs = cmd.get_finalized_command('build_scripts')
         bs.executable = executable
     cmd.ensure_finalized()
     with contexts.quiet():
         cmd.run()
Exemplo n.º 4
0
    def run_install_scripts(self):
        import configparser
        from setuptools.command.install_scripts import install_scripts
        from setuptools.dist import Distribution

        config = configparser.ConfigParser()
        config.read_string(self.wheel.entrypoints)

        # Some python debian packages have separate python2 and python3
        # Debian packages released. If a package has a `console_scripts`
        # entry, and the python2 version of a debian package is already
        # installed, when we attempt to install a python3 package created
        # by wheel2deb, it will fail because apt will not let it overwrite
        # an existing file.
        # An example of this is the `pyjwt` package: for the officially
        # released Debian packages, this creates `/usr/bin/pyjwt` (apt install
        # python-jwt) and `/usr/bin/pyjwt3` (apt install python3-jwt).
        # The code below follows a similar pattern, by appending the python
        # major version to `console_scripts` entries for versions greater
        # than three.
        endpoint_python_version = ""
        if self.pyvers.major >= 3:
            endpoint_python_version = str(self.pyvers.major)

        entrypoints = {}
        for section in config:
            x = [
                '%s%s=%s' % (k[0], endpoint_python_version, k[1])
                for k in config.items(section)
            ]
            if x:
                entrypoints[section] = x

        settings = dict(
            name=self.wheel.name,
            entry_points=entrypoints,
            version=self.wheel.version,
        )

        dist = Distribution(settings)
        dist.script_name = 'setup.py'
        cmd = install_scripts(dist)
        cmd.install_dir = str((self.root / 'entrypoints').absolute())
        bs = cmd.get_finalized_command('build_scripts')
        bs.executable = '/usr/bin/python' + str(self.pyvers.major)
        cmd.ensure_finalized()

        # cmd.run() creates some files that we don't want in python cwd
        oldcwd = os.getcwd()
        os.chdir('/tmp')
        try:
            cmd.run()
        finally:
            os.chdir(oldcwd)
Exemplo n.º 5
0
    def _generate_bin_build_file(self):
        contents = "".join([
            textwrap.dedent("""
            py_binary(
                name = "{rule}",
                srcs = ["bin/{entry_point}.py"],
                main = "bin/{entry_point}.py",
                deps = [":{library_name}"],
                visibility = ["//visibility:public"],
            )
            """).lstrip().format(
                rule="bin-" + ep if ep == self.library_name else ep,
                entry_point=ep,
                package_name=self.base_package_name,
                library_name=self.library_name,
            ) for ep in self.console_entry_points
        ])

        # Create bin directory
        dirname = os.path.join(self.base_package_path, "bin")
        os.makedirs(dirname, exist_ok=True)

        # Generate scripts
        from setuptools.command.install_scripts import install_scripts
        from setuptools.dist import Distribution
        dist = Distribution({
            "name": self.distribution.key,
            "version": self.distribution.version,
            "entry_points": {
                'console_scripts': [
                    str(val) for _, val in self.distribution.get_entry_map(
                        "console_scripts").items()
                ]
            }
        })
        dist.script_name = "setup.py"
        cmd = install_scripts(dist)
        cmd.install_dir = dirname
        cmd.ensure_finalized()
        cmd.run()

        # Add .py suffix. Bazel py_binary rule requires it
        for f in os.listdir(dirname):
            if not f.endswith(".py"):
                fullname = os.path.join(dirname, f)
                os.rename(fullname, fullname + ".py")

        # Generate build file
        with open(self.base_package_build_file_path, mode="a") as build_file:
            build_file.write(contents)