我有一个由裤子管理的单一仓库。对于其中的所有服务,构建文件和应用程序结构都是相同的。但在所有服务中,只有一个未启动:files_service。当调用
pants run
时,files_service 成功启动,但是当为 pants package
调用 files_service-bin 时,会发生以下错误:
Engine traceback:
in `package` goal
BinaryNotFoundError: Cannot find `unzip` on `['/bin', '/opt/homebrew/bin', '/usr/bin', '/usr/local/bin']`. Please ensure that it is installed so that Pants can download the tools Pants needs to run.
此外,它是唯一实现 proto 接口作为服务器的服务。所有原型都通过其中的目标在包含 BUILD 文件的文件夹中定义:
protobuf_sources(
name="protos",
sources=[
"files/v1/chat.proto",
"files/v1/backups.proto",
],
grpc=True,
)
服务构建文件
python_sources(
name="files_service",
sources=["**/*.py"],
dependencies=[
":files_service-reqs"
]
)
python_requirements(
name="files_service-reqs"
)
pex_binary(
name="files_service-bin",
output_path="files_service/package/binary.pex",
execution_mode="venv",
entry_point="files_service.main",
include_sources=True,
include_tools = True,
dependencies=[
":files_service"
]
)
docker_image(
name = "sherlock-ai-files_service-image",
dependencies=[
":files_service-bin"
]
)
python_test_utils(
name="files_service-test-utils",
sources=[
"**/conftest.py",
],
dependencies=[
":files_service"
]
)
python_requirements(
name="files_service-test-reqs",
source="pytest-requirements.txt",
resolve="pytest"
)
python_tests(
name="files_service-tests",
sources=[
"tests/**/test_*.py",
"!**/conftest.py",
],
dependencies=[
":files_service-test-utils",
":files_service"
]
)
裤子.toml
[GLOBAL]
pants_version = "2.22.0"
colors = true
backend_packages = [
"pants.core",
"pants.backend.python",
"pants.backend.codegen.protobuf.python",
"pants.backend.build_files.fmt.ruff",
"pants.backend.experimental.python.lint.ruff.check",
"pants.backend.experimental.python.typecheck.pyright",
"pants.backend.docker"
]
concurrent = true
[source]
root_patterns = [
"src",
"libs"
]
[environments-preview.names]
local_linux = "//:local_linux"
local_osx = "//:local_osx"
docker = "//:docker"
[python]
interpreter_constraints = [
">=3.11,<3.13"
]
enable_resolves = true
[python.resolves]
python-default = "python-default.lock"
pytest = "pytest-default.lock"
[python-protobuf]
mypy_plugin = true
[test]
output = "all"
report = false
use_coverage = true
[coverage-py]
global_report = true
[pytest]
install_from_resolve = "pytest"
args = ["-vv", "-s", "-W ignore::DeprecationWarning", "--no-header"]
构建(在根目录中)
__defaults__({
pex_binary: dict(
environment="local_linux",
tags=["binary"]
),
docker_image: dict(
build_platform=["linux/amd64"],
tags=["docker"]
),
})
local_environment(
name="local_linux",
compatible_platforms=["linux_x86_64"],
fallback_environment="docker"
)
local_environment(
name="local_osx",
compatible_platforms=["macos_arm64"],
)
docker_environment(
name="docker",
platform="linux_x86_64",
image="python:3.12-slim"
)
系统信息:
~ % sw_vers
ProductName: macOS
ProductVersion: 14.0
BuildVersion: 23A344
环境中有
unzip
。到达它的路径:
~ % which unzip
/usr/bin/unzip
在一定条件下(Linux)构建时问题得到解决。为此,我在根构建中定义了工作环境和目标环境,然后在运行时使用它们。
local_environment(
name="linux",
compatible_platforms=["linux_x86_64"],
fallback_environment="docker"
)
docker_environment(
name="docker",
platform="linux_x86_64",
image="python:3.12",
)