LoginSignup
0
0

More than 1 year has passed since last update.

Pipfile と Pipfile.lock から同等なrequirements.txtを出力する

Last updated at Posted at 2022-08-21
requirements.py
import os
import json


def get_path(filename):
    return os.path.join(os.path.dirname(os.path.realpath(__file__)), filename)


def main():
    with \
            open(get_path('Pipfile'), "r") as fp, \
            open(get_path('Pipfile.lock'), "r") as fl, \
            open(get_path("requirements.txt"), "w") as fr:
        json_fl = json.load(fl)
        text_fp = fp.read()
        for name, pkg in json_fl["default"].items():
            if name in text_fp:
                print(name, pkg["version"], file=fr, sep="")


if __name__ == "__main__":
    main()

Pipfile.lockと実用上支障ない程度には同等なrequirements.txtが出力される、本当はhashまで比較した方が良いが多くの場合は差異がない。

Google App Engine はサービスが依存するライブラリをrequirements.txtでしか受け付けないので上記requirements.pyPipfileと同じディレクトリに入れてrequirements.txtに変換している。早く改善してほしい。

0
0
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
0
0