贡献给SkyPilot#
感谢您对贡献SkyPilot的兴趣!我们欢迎并重视对该项目的所有贡献,包括但不限于:
Pull requests 用于修复错误和添加新功能
测试用例以使代码库更加健壮
示例
文档
关于SkyPilot的教程、博客文章和演讲
贡献代码#
我们使用GitHub来跟踪问题和功能。对于新贡献者,我们建议查看标记为“good first issue”的问题。
安装SkyPilot进行开发#
# SkyPilot requires python >= 3.7.
# You can just install the dependencies for
# certain clouds, e.g., ".[aws,azure,gcp,lambda]"
pip install -e ".[all]"
pip install -r requirements-dev.txt
测试#
运行冒烟测试(注意:运行所有冒烟测试会启动约20个集群):
# Run all tests on AWS and Azure (default smoke test clouds)
pytest tests/test_smoke.py
# Terminate a test's cluster even if the test failed (default is to keep it around for debugging)
pytest tests/test_smoke.py --terminate-on-failure
# Re-run last failed tests
pytest --lf
# Run one of the smoke tests
pytest tests/test_smoke.py::test_minimal
# Only run managed spot tests
pytest tests/test_smoke.py --managed-spot
# Only run test for GCP + generic tests
pytest tests/test_smoke.py --gcp
# Change cloud for generic tests to Azure
pytest tests/test_smoke.py --generic-cloud azure
对于代码分析,请使用:
pip install tuna # Tuna is used for visualization of profiling data.
python3 -m cProfile -o sky.prof -m sky.cli status # Or some other command
tuna sky.prof
在容器中进行测试#
在一个从头开始设置的干净环境中测试你的更改通常很有用。使用容器是实现这一点的好方法。
我们有一个开发容器镜像 berkeleyskypilot/skypilot-debug,我们用它来在容器内调试 skypilot。通过运行以下命令使用此镜像:
docker run -it --rm --name skypilot-debug berkeleyskypilot/skypilot-debug /bin/bash
# On Apple silicon Macs:
docker run --platform linux/amd64 -it --rm --name skypilot-debug berkeleyskypilot/skypilot-debug /bin/bash
它有一些便利功能,你可能会觉得有用(参见 Dockerfile):
常见的依赖和一些实用工具(rsync、screen、vim、nano 等)已预安装
requirements-dev.txt 已预安装
开发/调试的环境变量已正确设置
当容器启动时,自动将最新的主分支克隆到
/sky_repo/skypilot。请注意,您仍然需要手动运行
pip install -e ".[all]"来安装 skypilot,它不是预装的。如果你的分支在SkyPilot仓库上,你可以运行
git checkout来切换到你的分支。
提交拉取请求#
分叉 SkyPilot 仓库并为您的更改创建一个新分支。
如果相关,请为您的更改添加测试。对于涉及核心系统的更改,请运行冒烟测试并确保它们通过。
遵循Google风格指南。
通过运行
format.sh确保代码格式正确。[可选] 你也可以通过运行
pre-commit install来安装预提交钩子,以在提交时自动格式化你的代码。
将您的更改推送到您的分支,并在SkyPilot仓库中打开一个拉取请求。
在PR描述中,编写一个
Tested:部分来描述执行的相关测试。
一些通用的工程实践建议#
这些是建议,而不是必须遵循的严格规则。如有疑问,请遵循风格指南。
使用
TODO(author_name)/FIXME(author_name)而不是空白的TODO/FIXME。这对于追踪问题至关重要。你可以用你的名字写TODOs,并将其分配给其他人(在github上),如果这是别人的问题。合并后删除你的分支。这可以保持仓库的清洁并加快同步速度。
如果这是一个错误,请使用异常。仅将
assert用于调试或验证目的。这是因为异常消息通常包含更多信息。使用现代Python特性和风格来提高代码质量。
对于简短的表达式,使用f-string而不是
.format()以提高可读性。使用
class MyClass:而不是class MyClass(object):。后者是python2.x的变通方法。使用
abc模块来确保所有抽象方法都被实现。使用python类型注解。但你不应该仅仅为了类型注解而导入外部对象。相反,应在
if typing.TYPE_CHECKING:下导入仅用于类型注解的外部对象。
开发者的环境变量#
export SKYPILOT_DISABLE_USAGE_COLLECTION=1以禁用使用日志记录。export SKYPILOT_DEBUG=1以显示调试日志(使用 logging.DEBUG 级别)。export SKYPILOT_MINIMIZE_LOGGING=1以减少日志记录。在尝试避免多行输出时非常有用,例如用于演示。