贡献代码#

本地设置#

要贡献代码,需要基本的git知识,如果你不熟悉git工作流程,请查看GitHub的教程。以下步骤允许你为DoWhy贡献代码。

  1. 分叉 dowhy 主仓库

  2. 使用以下命令将此仓库克隆到您的本地机器

    git clone https://github.com//dowhy
    
  3. 安装 DoWhy 及其依赖项。Poetry 会自动创建一个虚拟环境, 但如果愿意,也可以以其他方式创建。 默认情况下,Poetry 将以交互模式安装 DoWhy。 这样,您可以立即测试对代码库的更改。

    cd dowhy
    pip install --upgrade pip
    poetry install -E "plotting"
    

    注意

    在某些平台上安装 pygraphviz 可能会出现问题。 适用于大多数 Linux 发行版的一种方法是 首先安装 graphviz,然后安装 pygraphviz,如下所示。 否则,请查阅 pygraphviz 的文档。

    sudo apt install graphviz libgraphviz-dev graphviz-dev pkg-config
    pip install --global-option=build_ext \
    --global-option="-I/usr/local/include/graphviz/" \
    --global-option="-L/usr/local/lib/graphviz" pygraphviz
    
  4. (可选)将 dowhy 添加为上游远程仓库,以保持你的 fork 与 DoWhy 的主分支同步。

    git remote add upstream http://www.github.com/py-why/dowhy
    

    你现在可以开始在本地对代码库进行更改了。

拉取请求清单#

  1. 执行flake8 linter以查找破坏性警告并修复所有报告的问题。

    poetry run poe lint
    
  2. 确保新添加的代码符合blackisort的格式要求。

    poetry run poe format_check
    

    您可以使用以下命令自动修复格式问题

    poetry run poe format
    
  3. 为你的新代码添加测试并执行单元测试,以确保你没有引入任何破坏性更改或错误。

    poetry run poe test
    

    请注意,你也可以一起执行这些任务

    poetry run poe verify
    

    可以使用以下命令获取可用任务的完整列表

    poetry run poe -h
    

    DoWhy 的完整测试套件需要相当长的时间。为了加快开发周期,你可以限制执行的测试,如下例所示。

    poetry run pytest -v tests/causal_refuters
    
  4. Once your code is finished and it passes all checks successfully, commit your changes. Make sure to add an informative commit message and to sign off your commits:

    git commit --signoff -m "informative commit message"
    

    By including this sign-off step, a commit is enriched with a Developer Certificate of Origin (DCO), containing the author’s name and email address. The DCO is a lightweight alternative to a CLA and affirms that the author is the source of the committed code and has the right to contribute it to the project. For the full text, see DCO.

    Note

    Note the “–signoff” or shorthand “-s” is obligatory and commits without cannot be merged. By default, most IDEs won’t include this step within their git integration, so an additional setup may be required.

    In case you made a single commit without adding the required DCO, you can do

    git commit --amend --no-edit --signoff
    git push -f origin <BRANCH_NAME>
    

    In case of more commits, one way is to squash them together (example for 3 commits)

    git reset --soft HEAD~3
    git commit -s -m "new informative commit message of squashed commit"
    

    or use a rebase with as many “^” as commits to be changed.

    git rebase --signoff HEAD^^^
    
  5. (高级) Poetry 使用 poetry.lock 文件来固定其依赖项及其版本。维护者应定期通过以下命令更新 Poetry 的依赖项:

    poetry update
    

    对于大多数 PR 来说,这是不必要的。如果 PR 需要更改 lockfile,我们要求您提供为什么需要更新依赖项的理由。