Github 작업으로 Jupyter Notebook diff 가져오기
노트북으로 작업할 때 알려진 문제 중 하나는 버전 제어가 이상적이지 않으며 실제로 이를 처리할 수 있는 도구가 거의 없다는 것입니다. 이로 인해 저는 ndime이라는 기존 오픈 소스 도구를 활용하여 Github Actions를 사용하여 이러한 파일로 작업하는 일부 엔지니어의 부담을 줄이고자 노력했습니다.
내 워크플로우
일반적인 아이디어는 대상 브랜치와 관련하여 모든 노트북에 대한 변경 사항을 포함하는 PR에 대한 코멘트를 Github Action 포스트로 만드는 것입니다.
이를 위해 다음과 같은 기존 조치를 사용할 것입니다.
checkout@v2
, 코드 가져오기용actions/setup-python@v1
, Python 설치용peter-evans/create-or-update-comment@v1
, nbdiff
의 출력으로 PR에 댓글을 작성합니다. 제출 카테고리:
이것은 노트북이 공유 저장소에 제출될 때(예: 연구 또는 지속 실험을 위해) 훨씬 더 나은 컨텍스트를 제공하기 때문에 유지 관리자 필수 항목에 속할 것이라고 생각합니다.
Yaml 파일 또는 코드 링크
this repository 에서 작동하는 구현을 볼 수 있습니다.
name: Generate notebook diff
on: ["pull_request"]
jobs:
check-diff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Fetch target branch
run: git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }}
- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: "3.6"
- name: Install requirements
run: pip3 install nbdime
- name: Run and store diff
run: |
nbdiff ${{ github.event.pull_request.base.ref }} --no-color > diff.log
sed -i '1s/^/\`\`\`diff\n&/' diff.log
sed -i '$s/$/\n&\`\`\`/' diff.log
- name: Get comment body
id: get-comment-body
run: |
body=$(cat diff.log)
body="${body//'%'/'%25'}"
body="${body//$'\n'/'%0A'}"
body="${body//$'\r'/'%0D'}"
echo ::set-output name=body::$body
- name: Create comment
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body: ${{ steps.get-comment-body.outputs.body }}
간단히 말해서
nbdiff
를 사용하여 diff.log
라는 파일을 생성합니다. 그런 다음 sed
를 사용하여 마크다운 둘러싸는 문자를 추가하고 앞에 추가합니다. 다음 단계에서는 diff.log
를 가져오고 PR 주석will not truncate newlines이 body
변수에 저장되도록 추가 교체를 수행합니다. 마지막으로 body
변수를 create-or-update-comment
작업에 전달하여 형식이 지정된 출력을 PR에 게시합니다.카나스 / 테스트-nbdiff-github-액션
이 리포지토리는 사용 가능한 경우 Jupyter Notebook diff(vía nbdime)로 PR에 주석을 다는 Github 작업을 시도하기 위한 것입니다. 샘플은 공개 PR에서만 제공됩니다.
nbdiff.yaml
name: Generate notebook diff on: ["pull_request"] jobs check-diff runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 with: fetch-depth: 0 - name: Fetch target branch run: git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }} - name: Setup Python uses: actions/setup-python@v1 with: python-version: "3.6" - name: Install requirements run: pip3 install nbdime - name: Run and store diff run: | nbdiff ${{ github.event.pull_request.base.ref }} --no-color > diff.log sed -i '1s/^/```diff\n&/' diff.log sed -i '$s/$/\n&```/' diff.log - name: Get comment body id: get-comment-body run: | body=$(cat diff.log) body="${body//'%'/'%25'}" body="${body//$'\n'/'%0A'}" body="${body//$'\r'/'%0D'}" echo ::set-output name=body::$body - name: Create comment uses: peter-evans/create-or-update-comment@v1…
View on GitHub
*실제 파일을 보고 싶다면
change
브랜치로 체크아웃하세요!추가 리소스/정보
사용한 작업:
사용한 라이브러리:
가능한 향후 작업:
nbdiff-web
Reference
이 문제에 관하여(Github 작업으로 Jupyter Notebook diff 가져오기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/canas/get-jupyter-notebook-diff-with-github-actions-4b90텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)