taketakeyyy / piptest

pip install via GitHub

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

piptest

自作パッケージ(モジュール)を GitHub 経由で pip install するサンプルプログラム。

PyPi に公開したくない自作モジュールを作ることはよくあります。

この piptest をGitHub経由でインストールして、モジュール呼び出しするサンプルプログラムです。

動作確認済み:Python3.8

使い方

適当な作業フォルダ sandbox を作成します。

この sandbox フォルダ直下で、以下のどれかのコマンドを実行してインストールします。

  • pip install git+https://github.com/taketakeyyy/piptest.git -t mylib

    • sandbox 直下に mylib というフォルダが作成され、そこに piptest パッケージがインストールされます。
  • pip install git+https://github.com/taketakeyyy/piptest.git

    • システムに piptest パッケージがインストールされます。

piptestを使ってみる

sandbox 直下に、以下のrun.pyを作成します。

# -*- coding: utf-8 -*-

# mylib フォルダにインストールした場合、パスを通す
import sys
sys.path.append('mylib')

# piptest パッケージ内のモジュールを import する
from piptest import call
from piptest import Dog
from piptest import __author__
from piptest import __url__
from piptest import __version__

if __name__ == "__main__":
    call()  # Hello, here is pip test.

    dog = Dog("Taro")
    dog.bark()  # Bow! Bow name is Taro!

    print("===[piptest info]===")
    print(f"author:{__author__}")
    print(f"url:{__url__}")
    print(f"version:{__version__}")

これを実行してみます。

> python run.py
Hello, here is pip test.
Bow! Bow name is Taro!
===[piptest info]===
author:taketakeyyy
url:https://github.com/taketakeyyy/piptest
version:0.1.0

piptestcall(), dog.bark() のモジュールや、パッケージ情報が呼び出せました。

piptestのアップデート

piptest に変更を加えてアップデートしたとします。

一般に、パッケージのアップデートは以下のコマンドで行います。

> pip install --upgrade [パッケージ名]

なので、 piptest をアップデートしたい場合は以下のコマンドを使います。

# mylib にインストールした場合
> pip install --upgrade git+https://github.com/taketakeyyy/piptest.git -t mylib
# システムにインストールした場合
> pip install --upgrade git+https://github.com/taketakeyyy/piptest.git

参考

About

pip install via GitHub


Languages

Language:Python 100.0%