是否可以公开从pantsbuild导入pex的模块?

2024-05-16 10:21:37 发布

您现在位置:Python中文网/ 问答频道 /正文

https://github.com/pantsbuild/pex/issues/1181交叉发布,因为我真的不知道在哪里问这个问题

我正在使用Nginx单元,它为我的FastAPI应用程序提供了ASGI配置。它工作得很好,但我不知道如何与PEX一起使用

我在下面附上了它,但最突出的一点是,有一个针对Nginx单元的Python插件,它正在寻找一个“模块”和一个“可调用的”

现在看起来像是“apigateway.main:app”,类似于uvicorn或您正在使用的任何其他服务器实现。与uvicorn、gunicorn或其他任何工具不同,我认为我无法在我的pex文件中打包任何其他工具并使用pex_脚本

对于是否/如何在pex之外公开模块和变量,是否有任何建议

{
    "listeners": {
        "*:80": {
            "pass": "routes"
        }
    },
    "routes": [
        {
            "action": {
                "pass": "applications/api"
            }
        }
    ],
    "applications": {
        "api": {
            "type": "python 3.9",
            "path": "/app",
            "module": "apigateway.main",
            "callable": "app",
            "limits": {
                "requests": 100
            },
            "processes": {}
        }
    },
    "access_log": "/var/log/access.log"
}

Tags: 模块工具logapiappaccessmainnginx
1条回答
网友
1楼 · 发布于 2024-05-16 10:21:37

这在Github票证(https://github.com/pantsbuild/pex/issues/1181)中得到了回答:

All the traditional language here is meant to segue to the recent venv pex tool feature released with Pex 2.1.22. If you build your PEX file with venv support (add include-tools to the Pex command line) then you gain the ability to create a venv from your PEX file. Doing so is a one-time manual step on the target machine or image:

PEX_TOOLS=1 ./my.pex venv /app That will create a virtual environment containing your app and its dependencies under /app. You can point Nginx Unit there with home. I've done all this over at https://github.com/jsirois/pex-issues-1181 to prove it works.

相关问题 更多 >