Poetry로 개발에서publish까지

16700 단어 Pythonpypipoetrytech
Poetry를 이용한 포장 개발부터 공개된 비망록까지.
pypi와 관련된 계정 설정 등이 없습니다.끝부분의 참고 사이트를 참조하세요.

새로 만들다


poetry new --src project_name
cd project_name
poetry install
pycharm .
# vscodeの場合
# code .
이렇게 하면 새로운 항목은pycharm에서 열리고 다음은pycharm 내 단말기에서 실행됩니다.

기본 설정


단말기

  • 의존성 패키지 추가
  • git init
  • README, LICENSE, gitignore의 제작
  • poetry add -D pytest-watch pytest-mock pytest-cov
    poetry shell
    mv README.rst README.md
    # git init -> デフォルトのブランチ名をdevにする場合
    git init -b dev
    # LICENSEファイルの作成
    license -n atu4403 -o LICENSE mit
    # .gitignoreの作成
    gibo dump python >> .gitignore
    
    LICENSE와gitignore의 제작은 CLI 도구를 사용하면 매우 편리하다
    License: Command line license generator
    simonwhitaker/gibo: Easy access to gitignore boilerplates
    local의 자체 제작 모듈을 사용하려면 상대 경로로 지정하십시오.절대 패스는 실패할 것이다.
    poetry add ../moncoll/dist/moncoll-0.1.0.tar.gz
    

    pycharm 설정

  • 열기 도구-저장할 때의 동작-코드의 성형
  • 프로젝트-pythhon 해석기 - 가상 환경을 설정하는python
  • pytest가 설치되어 있으면 자동으로 사용하기 때문에 특별한 설정이 없습니다.
    이렇게 되면 환경이 정돈되고 그 다음은 가시가시가시 개발이다.

    개발 중


  • 함수 이름이 test_에서 시작되면 코드 블록의 왼쪽에 테스트에 사용할 재현 단추가 자동으로 표시되기 때문에 간단한 TDD/BDD
  • doctest를 쓰면 함수명을 오른쪽 단추로 눌러서 테스트
  • 를 할 수 있습니다
  • docstring은 나중에 문서를 만들기 위해 최소한 미리 쓰기
  • 금형에 mypy를 사용하면 번거롭기 때문에 사용하지 않는 것이 좋다
  • pytest-watch
    poetry run ptw --ignore tests/test_download.py
    
    pytest-cov
    poetry run pytest --cov-report term-missing --cov=src/adash tests/
    

    완성


    TODO 확인


    나머지 파일이 없는지 확인하려면 모든 파일을 검색TODO:하십시오.

    ci(github actions)


    github actions로 ptest를 조작하는 예.github/workflows/test.yml.
    name: Test
    on:
      push:
      pull_request:
    jobs:
      ci:
        runs-on: ${{ matrix.os }}
        strategy:
          matrix:
            os:
              - macos-11.0
              - macos-latest
              - windows-latest
              - ubuntu-20.04
              - ubuntu-latest
            python-version: [ 3.8, 3.9 ]
        steps:
          - uses: actions/checkout@v2
          - uses: actions/setup-python@v2
            with:
              python-version: ${{ matrix.python-version }}
          - uses: atu4403/poetry-setup-multi-platform@v1
          - run: |
              poetry install
              poetry run pytest
            shell: bash
    
    name의 부분은 그대로 배지의 타이틀이 되기 때문에 해당하는 부분을 설정해야 한다.

    만들다


    프로젝트 원본 바로 아래__init__.py의 시작에 주석을 추가합니다.
    """
    .. include:: ../../README.md
    """
    # 以下普通に実装
    from foo import bar
    
    적절한 디렉터리에 생성하고 확인합니다.
    pdoc --html --output-dir tmp --force src/{project-name}
    
    여기 tmp 디렉터리를 만들지만git 관리가 필요하지 않기 때문에 .gitignore에 미리 추가해야 합니다.
    github에서push시 자동 디버깅을 위해 제작.github/workflows/deploy.yml.{project-name}의 부분은 매번 설정해야 합니다.
    name: GitHub Pages
    
    on:
      push:
        branches:
          - main
      pull_request:
    
    jobs:
      deploy:
        runs-on: ubuntu-20.04
        concurrency:
          group: ${{ github.workflow }}-${{ github.ref }}
        steps:
          - uses: actions/checkout@v2
          - uses: actions/setup-python@v2
            with:
              python-version: 3.9
          - name: Build
            run: |
              pip install pdoc3
              pdoc --html --output-dir tmp --force src/{project-name}
    
          - name: Deploy
            uses: peaceiris/actions-gh-pages@v3
            if: ${{ github.ref == 'refs/heads/main' }}
            with:
              github_token: ${{ secrets.GITHUB_TOKEN }}
              publish_dir: ./tmp
    
    https://zenn.dev/atu4403/articles/python-githubpages

    git 연결


    dev 분기 상태에서 push를 진행하여 CI(GiitHubAction)의 동작을 확인합니다.
    hub create
    git push -u origin dev
    
    CI 통과 후 지금까지의 역사 기록을 삭제하고main 지점으로 정리한다.
    git checkout --orphan main # 履歴のない状態でmainブランチを切る
    git commit -m "Initial Commit" # ステージングされた状態になるのでaddせずにcommitする
    git push -u origin main
    git branch --delete --force dev
    git push --delete origin dev
    # deleteできない場合は GitHubのsettings → branches からDefault branchをmainに変更し、再度`push —delete`する。
    
    github actions 동작 실패 후 여러 번commiit &push 리셋 이력서 를 위해 위 의 일 을 하고 신경 쓰지 않으면 main 으로 바로 들어가도 OK

    공개적인 준비


    pyproject.수정toml.
  • description
  • 작성
  • 홈 페이지와 Repository의 URL
  • 을 작성합니다
  • readme를 기입하세요.이렇게 하지 않으면 PyPI에 README를 반영할 수 없습니다.
  • version의 확인.이미 공개되면 버전이 업그레이드됩니다.
  • [tool.poetry]
    name = "{project-name}"
    version = "0.1.0"
    description = "{project description}"
    authors = ["atu4403 <[email protected]>"]
    homepage = "https://github.com/atu4403"
    repository = "https://github.com/atu4403/{project-name}"
    readme = "README.md" 
    
    project.toml 제출 후 탭 만들기
    git tag v0.1.0 # 最新のコミットに対してtagを作成
    git push origin --tags
    

    testpypi에서 임시 공개


    testPyPI에 대해 publish를 수행합니다.계정 생성 및 poetry config에 대해서는 참조 링크 참조
    > poetry publish --build -r testpypi
    
    https://test.pypi.org/manage/projects/에 가서 제작된 프로젝트의 페이지를 엽니다.
    설치용 URL이 있기 때문에 복사 후 실제 설치 & 동작 확인
    > pip3 install -i https://test.pypi.org/simple/ remind-task
    # 一部のpackageがインストールできない時は--extra-index-urlを設定する
    > pip3 install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.python.org/pypi remind-task
    
    Poetry install을 사용하려는 경우poetry add {url}에도 오류가 발생할 수 있습니다.poetry run 머리에 쓰고 하면 OK.
    poetry run pip3 install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.python.org/pypi {project-name}
    
    테스트PyPI로 향상된 제품에 문제가 있으면 수정 버전은 버전을 높여야 한다.pyproject.toml의version을 수정합니다.
    [tool.poetry]
    name = "project_name"
    version = "0.2.0"
    
    GiitHub에서 CI 통과를 최종 확인한 뒤 이를 공식적으로 사용하는 PyPI로 공공연하게 종료한다.
    신중을 기하기 위한 동작 확인용이기 때문에 CI 통과에 문제가 없다고 판단되면 건너뛸 수 있다.

    공개한다


    poetry publish --build
    
    개봉 후 pypihttps://pypi.org/project/{project-name}/가 검색되지 않을 수 있으니 확인하세요.

    페이지 가져오기


    github actions


    actions 탭에서 최신 탭을 열고 오른쪽 ... 에서 "create status badge"를 선택하면 mardown의 링크를 복사할 수 있습니다
    alt

    pypi version


    https://badge.fury.io/

    사이트 축소판 그림


    명령 - Poetry documentation(일본어 번역)
    Poetry를 사용한 파이썬 패키지 개발부터 PyPI 공개까지 - PYTHONIC BOOM BOOM HEAD

    좋은 웹페이지 즐겨찾기