Giter VIP home page Giter VIP logo

Comments (8)

jsirois avatar jsirois commented on September 16, 2024

Pex is only supported as a binary, not a library. Can you explain your use case?

from pex.

NiklasRosenstein avatar NiklasRosenstein commented on September 16, 2024

Ah! I've been using PEX.resolve() to find all the console_scripts entry points and export them as shell wrappers after building the PEX, to allow the PEX to subprocess.run() console_scripts from other requirements.

I'm using the CLI to build the PEX, but have not found a way to enable this use case with the PEX cli.

        console_scripts = _get_console_scripts(PEX(str(self.output_file.get())))
        if console_scripts:
            console_scripts_dir.mkdir(parents=True, exist_ok=True)
            self.logger.info("Exporting %d console_scripts in PEX to %s", len(console_scripts), console_scripts_dir)
            for script in console_scripts:
                file = console_scripts_dir / script
                file.write_text(
                    f'#!/bin/sh\nPEX_SCRIPT={script} PATH="{console_scripts_dir.absolute()}:$PATH" '
                    f'"{self.output_file.get().absolute()}" "$@"\n'
                    "exit $?\n"
                )
                file.chmod(0o777)
        else:
            self.logger.info("note: PEX has no console_scripts")

# ...

def _get_console_scripts(pex: PEX) -> set[str]:
    """Return all entry points registered under `console_script` for this PEX."""

    result = set()
    for dist in pex.resolve():
        result.update(dist.get_entry_map().get("console_scripts", {}).keys())
    return result

There is the --venv option and PEX_VENV=true PEX_VENV_BIN_PATH=prepend variables, but I could not find a way to "embed" those variables in the PEX (--inject-var doesn't seem to work with these PEX_ variables).

from pex.

jsirois avatar jsirois commented on September 16, 2024

You found the right answer, build the PEX with --venv prepend. Or maybe you missed that --venv optionally takes {prepend,append} args?

from pex.

NiklasRosenstein avatar NiklasRosenstein commented on September 16, 2024

Oh, I did miss that! I'll try this right away, thank you. Are there any performance implications for enabling the --venv mode?

from pex.

NiklasRosenstein avatar NiklasRosenstein commented on September 16, 2024

It works, unfortunately it has one drawback in my particular case in that the python executable also resolve to that of the environment that the PEX is unpacked into. So when I run Mypy as a PEX, and pass --python-executable python, it doesn't find any type hints for the project I actually want to type-check.

I've tried passing shutil.which("python") to --python-executable to get the full path to the Python interpreter that I actually want it to use. On my system that resolves to a Pyenv shim though, which later on when Mypy accesses it still resolves to the Python of the PEX's unpacked venv. 🤦

from pex.

jsirois avatar jsirois commented on September 16, 2024

@NiklasRosenstein if you can provide a working example using Pip / venv, I'm sure I can translate that to a working Pex example for you.

from pex.

jsirois avatar jsirois commented on September 16, 2024

@NiklasRosenstein I'll close this as an answered question unless you can provide an example set up repro steps that lead to a situation the CLI can't handle but your existing API use can.

from pex.

jsirois avatar jsirois commented on September 16, 2024

Alright @NiklasRosenstein you've been silent; so I'll close this as answered, but please speak up if you do find a situation the CLI can't handle that you expect it could / should / the (unsupported) APIs do.

from pex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.