3
2

More than 1 year has passed since last update.

pythonのdebパッケージを作る

Posted at

覚書です

手順

  1. requirements.txtを作る
  2. requirementsで依存関係のwhlファイルを取得する
  3. setup.pyを作る
  4. whlを作成する
  5. debを作るためのファイルを用意する
  6. debパッケージを作る

1.requirements.txtを作る

  • 依存関係にあるpipパッケージを記載する
  • 要求するバージョンも記載する
requirements.txt
coloredlogs>=9.0
websocket-client==1.1.0

2.requirementsで依存関係のwhlファイルを取得する

  • 以下のコマンドで依存関係のwhlファイルを取得する
  • wheelhose/配下にダウンロードされる
python3 -m pip wheel -r requirements.txt -w wheelhouse --no-build-isolation

3.setup.pyを作る

  • whlを作るためのsetup.pyを作る
  • package_dir配下のpy_modulesのファイルをパッケージに含める
    • この場合/src/test.pyがパッケージに含まれる
setup.py
pkg_name = 'test-tools'
version = '0.0.1'
install_requires = [
    'coloredlogs>=9.0',
    'websocket-client',
]

setup(
    name=pkg_name,
    version=version,
    author="user",
    author_email="user@test.com",
    description="test tools package",
    url='https://github.com/hogehoge/test-tools',
    py_modules=["test"],
    package_dir={'': 'src'},
    install_requires=install_requires,
)

4.whlを作成する

  • 以下のコマンドでwhlを作る
    • /dist/test-tools-0.0.1-py3-none-any.whlな感じにできる
python3 setup.py bdist_wheel

5.debを作るためのファイルを用意する

必要なのは3つ
- dev.json
- debian/postinst
- debian/prerm

dev.json
{
  "name": "test-tools",
  "maintainer": "user <user@test.com>",
  "description": "test-tools",
  "changelog-cmd": "git log --pretty='format:%cd %h %s %d [%an]' --date=iso --merges",
  "homepage": "https://github.com/hogehoge/test-tools",
  "files": [
    {
      "from": "dist/test_tools-*.whl",
      "to": "/tmp",
      "base": "build/",
      "fperm": "0644"
    }
  ],
  "postinst-file": "debian/postinst",
  "prerm-file": "debian/prerm",
  "copyrights": [
    {
      "files": "*",
      "copyright": "Copyright (c) 2022, hogehoge, Inc. All rights reserved.",
      "license": "",
      "file": ""
    }
  ]
}
debian/postinst
#!/bin/bash -e

pip3 install /tmp/test_tools-*.whl
debian/prerm
#!/bin/bash -e

pip3 uninstall -y test_tools

6.debパッケージを作る

  • 以下のコマンドでdebパッケージが作られる
go-bin-deb generate --arch amd64 --version 0.0.1 --file ./deb.json --wd pkg-build

中間ファイルが大量に発生するので、makefileで一気に処理して、debができたら綺麗にするのが良いと思うけど、とりあえず覚書

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2