注:該文的原文是 Quickstart: uploading, testing, pushing releases,來自於 devpi 的官方文檔。html
該快速入門文檔將引導你爲你的 Python 包設置完成一個獨立的 pypi 發佈上傳,測試和 staging 系統。python
我想在個人筆記本上運行完整的 devpi 系統:linux
pip install -U devpi
這將安裝 devpi-client
和 devpi-server
這兩個 pypi 包。json
devpi quickstart
命令在你本地機器上執行一些基礎的初始化步驟:服務器
http://localhost:3141
訪問devpi
來鏈接最新啓動的 devpi 服務讓咱們運行 quickstart 命令來觸發一系列的其餘 devpi 命令:網絡
$ devpi quickstart --> $ devpi-server --start 2014-09-04 15:12:19,311 INFO NOCTX DB: Creating schema 2014-09-04 15:12:19,353 INFO [Wtx-1] setting password for user u'root' 2014-09-04 15:12:19,353 INFO [Wtx-1] created user u'root' with email None 2014-09-04 15:12:19,353 INFO [Wtx-1] created root user 2014-09-04 15:12:19,353 INFO [Wtx-1] created root/pypi index 2014-09-04 15:12:19,367 INFO [Wtx-1] fswriter0: committed: keys: u'.config',u'root/.config' starting background devpi-server at http://localhost:3141 /tmp/home/.devpi/server/.xproc/devpi-server$ /home/hpk/venv/0/bin/devpi-server process u'devpi-server' started pid=841 devpi-server process startup detected logfile is at /tmp/home/.devpi/server/.xproc/devpi-server/xprocess.log --> $ devpi use http://localhost:3141 using server: http://localhost:3141/ (not logged in) no current index: type 'devpi use -l' to discover indices ~/.pydistutils.cfg : no config file exists ~/.pip/pip.conf : no config file exists ~/.buildout/default.cfg: no config file exists always-set-cfg: no --> $ devpi user -c testuser password= user created: testuser --> $ devpi login testuser --password= logged in 'testuser', credentials valid for 10.00 hours --> $ devpi index -c dev http://localhost:3141/testuser/dev: type=stage bases=root/pypi volatile=True uploadtrigger_jenkins=None acl_upload=testuser pypi_whitelist= --> $ devpi use dev current devpi index: http://localhost:3141/testuser/dev (logged in as testuser) ~/.pydistutils.cfg : no config file exists ~/.pip/pip.conf : no config file exists ~/.buildout/default.cfg: no config file exists always-set-cfg: no COMPLETED! you can now work with your 'dev' index devpi install PKG # install a pkg from pypi devpi upload # upload a setup.py based project devpi test PKG # download and test a tox-based project devpi PUSH ... # to copy releases between indexes devpi index ... # to manipulate/create indexes devpi use ... # to change current index devpi user ... # to manipulate/create users devpi CMD -h # help for a specific command devpi -h # general help docs at http://doc.devpi.net
顯示版本:python2.7
$ devpi --version 2.0.2
咱們如今可使用 devpi
命令行客戶端來觸發一個從已經運行的服務器上使用索引的 pypi 包的 pip install
。ide
$ devpi install pytest --> $ /tmp/docenv/bin/pip install -U -i http://localhost:3141/testuser/dev/+simple/ pytest [PIP_USE_WHEEL=1,PIP_PRE=1] Downloading/unpacking pytest http://localhost:3141/testuser/dev/+simple/pytest/ uses an insecure transport scheme (http). Consider using https if localhost:3141 has it available Running setup.py (path:/tmp/docenv/build/pytest/setup.py) egg_info for package pytest http://localhost:3141/testuser/dev/+simple/py/ uses an insecure transport scheme (http). Consider using https if localhost:3141 has it available Requirement already up-to-date: py>=1.4.22 in /tmp/docenv/lib/python2.7/site-packages (from pytest) Installing collected packages: pytest Running setup.py install for pytest Installing py.test-2.7 script to /tmp/docenv/bin Installing py.test script to /tmp/docenv/bin Successfully installed pytest Cleaning up...
devpi install
命令配置一個 pip 調用,使用在 testuser/dev
索引上的與 pypi 兼容的 +simple/
頁來尋找和下載包。pip
執行的是在 PATH
搜索和在 docenv/bin/pip
尋找。工具
讓咱們檢查 pytest
是否被正確安裝:post
$ py.test --version This is pytest version 2.6.1, imported from /tmp/docenv/local/lib/python2.7/site-packages/pytest.pyc
你能夠第二次調用 devpi install
命令,即便在沒有網絡的狀況下,它也能正常工做。
咱們將使用 devpi
命令行工具來執行上傳(你也可使用 plain setup.py)。
讓咱們檢查咱們已經登陸進了正確的索引:
$ devpi use current devpi index: http://localhost:3141/testuser/dev (logged in as testuser) ~/.pydistutils.cfg : no config file exists ~/.pip/pip.conf : no config file exists ~/.buildout/default.cfg: no config file exists always-set-cfg: no
如今進入你其中一個項目的 setup.py
文件的目錄(咱們假設名字爲 example
) 來構建和上傳你的包到 testuser/dev
索引。
example $ devpi upload using workdir /tmp/devpi0 --> $ /usr/bin/hg st -nmac . hg-exported project to /tmp/devpi0/upload/example -> new CWD --> $ /tmp/docenv/bin/python setup.py sdist --formats gztar built: /home/hpk/p/devpi/doc/example/dist/example-1.0.tar.gz [SDIST.TGZ] 0kb register example-1.0 to http://localhost:3141/testuser/dev/ file_upload of example-1.0.tar.gz to http://localhost:3141/testuser/dev/
這裏有三個觸發動做:
setup.py
中定義的,把 example
版本註冊進咱們當前的索引gztar
格式的文件到當前索引(使用一個在鉤子下面的 setup.py
調用)咱們如今能夠安裝剛上傳好的包:
$ devpi install example --> $ /tmp/docenv/bin/pip install -U -i http://localhost:3141/testuser/dev/+simple/ example [PIP_USE_WHEEL=1,PIP_PRE=1] Downloading/unpacking example http://localhost:3141/testuser/dev/+simple/example/ uses an insecure transport scheme (http). Consider using https if localhost:3141 has it available Downloading example-1.0.tar.gz Running setup.py (path:/tmp/docenv/build/example/setup.py) egg_info for package example Installing collected packages: example Running setup.py install for example Successfully installed example Cleaning up...
這個你剛剛從 testuser/dev
索引安裝的上傳包是咱們開始上傳好的包。
注意:devpi upload 容許同時上傳你的發行文件的多個不一樣格式,好比:
sdist.zip
或是bdist_egg
,默認是sdist.tgz
。
若是你有一個包使用 tox 作測試,你或許要調用:
$ devpi test example # package needs to contain tox.ini received http://localhost:3141/testuser/dev/+f/5bc/44b5ac34ff65b/example-1.0.tar.gz#md5=5bc44b5ac34ff65b6b16b332f9ccc22c unpacking /tmp/devpi-test0/downloads/example-1.0.tar.gz to /tmp/devpi-test0 /tmp/devpi-test0/example-1.0$ tox --installpkg /tmp/devpi-test0/downloads/example-1.0.tar.gz -i ALL=http://localhost:3141/testuser/dev/+simple/ --result-json /tmp/devpi-test0/toxreport.json -c /tmp/devpi-test0/example-1.0/tox.ini python create: /tmp/devpi-test0/example-1.0/.tox/python python installdeps: pytest python inst: /tmp/devpi-test0/downloads/example-1.0.tar.gz python runtests: PYTHONHASHSEED='2866296898' python runtests: commands[0] | py.test ___________________________________ summary ____________________________________ python: commands succeeded congratulations :) wrote json report at: /tmp/devpi-test0/toxreport.json posting tox result data to http://localhost:3141/testuser/dev/+f/5bc/44b5ac34ff65b/example-1.0.tar.gz successfully posted tox result data
以上操做發生了這些事:
example
的最新可用版本tox.ini
而且調用 tox,把它指向咱們的 example-1.0.tar.gz
。強迫全部的安裝都經過咱們當前的 testuser/dev/+simple/
索引和命令它建立一個 json
格式的報告toxreport.json
到 devpi 服務器去,它將被精確的鏈接到咱們的發行文件咱們能夠校驗測試狀態是否被記錄:
$ devpi list example http://localhost:3141/testuser/dev/+f/5bc/44b5ac34ff65b/example-1.0.tar.gz cobra linux2 python 2.7.6 tests passed
一旦你以爲發行文件沒有問題,你能夠把它推送到一個 devpi-managed 索引和一個外部的 pypi 索引服務器。
讓咱們建立另一個 staging
索引:
$ devpi index -c staging volatile=False http://localhost:3141/testuser/staging: type=stage bases=root/pypi volatile=False uploadtrigger_jenkins=None acl_upload=testuser pypi_whitelist=
咱們建立了一個非易失性的索引,這意味着不能覆蓋和刪除發行文件,看 Non Volatile Indexes 來獲取更多信息。
咱們如今能夠把 example-1.0.tar.gz
從上面的全部推送到 staging
索引:
$ devpi push example-1.0 testuser/staging 200 register example 1.0 -> testuser/staging 200 store_releasefile testuser/staging/+f/5bc/44b5ac34ff65b/example-1.0.tar.gz 200 store_toxresult testuser/staging/+f/5bc/44b5ac34ff65b/example-1.0.tar.gz.toxresult0
這將決定全部在 testuser/dev
索引上的文件屬於指定的 example-1.0
發行版而且把它們拷貝進 testuser/staging
索引。
讓咱們檢查咱們當前的索引:
$ devpi use current devpi index: http://localhost:3141/testuser/dev (logged in as testuser) ~/.pydistutils.cfg : no config file exists ~/.pip/pip.conf : no config file exists ~/.buildout/default.cfg: no config file exists always-set-cfg: no
讓咱們使用 testuser/staging
索引:
$ devpi use testuser/staging current devpi index: http://localhost:3141/testuser/staging (logged in as testuser) ~/.pydistutils.cfg : no config file exists ~/.pip/pip.conf : no config file exists ~/.buildout/default.cfg: no config file exists always-set-cfg: no
而且再次檢查測試結果:
$ devpi list example http://localhost:3141/testuser/staging/+f/5bc/44b5ac34ff65b/example-1.0.tar.gz cobra linux2 python 2.7.6 tests passed
從最後一步推送後,測試狀態依然是可用的。
咱們如今能夠決定推送這個發行版到外部的 pypi 索引,咱們已經在 .pypirc
文件中配置了:
$ devpi push example-1.0 pypi:testrun no pypirc file found at: /tmp/home/.pypirc
這將推送 example-1.0
發行版的全部的文件到一個外部的 testrun
索引服務器。使用資格證書和 發如今 pypi
章節 .pypirc
文件中的 URL。
如今,咱們已經有 example-1.0
發行版和發行版文件在 testuser/dev
和 testuser/staging
索引,若是咱們想在咱們的開發索引上一直使用 staging 包,咱們能夠從新配置 testuser/dev
的繼承基線。
$ devpi index testuser/dev bases=testuser/staging /testuser/dev changing bases: ['testuser/staging'] http://localhost:3141/testuser/dev: type=stage bases=testuser/staging volatile=True uploadtrigger_jenkins=None acl_upload=testuser pypi_whitelist=
如今咱們切回 testuser/dev
:
$ devpi use testuser/dev current devpi index: http://localhost:3141/testuser/dev (logged in as testuser) ~/.pydistutils.cfg : no config file exists ~/.pip/pip.conf : no config file exists ~/.buildout/default.cfg: no config file exists always-set-cfg: no
而後尋找咱們的 example 發行文件:
$ devpi list example http://localhost:3141/testuser/dev/+f/5bc/44b5ac34ff65b/example-1.0.tar.gz cobra linux2 python 2.7.6 tests passed http://localhost:3141/testuser/staging/+f/5bc/44b5ac34ff65b/example-1.0.tar.gz cobra linux2 python 2.7.6 tests passed
咱們看到 example-1.0.tar.gz
被包含在兩個索引中,讓咱們移除 testuser/dev
的 example
發行版:
$ devpi remove -y example About to remove the following releases and distributions version: 1.0 - http://localhost:3141/testuser/dev/+f/5bc/44b5ac34ff65b/example-1.0.tar.gz - http://localhost:3141/testuser/dev/+f/5bc/44b5ac34ff65b/example-1.0.tar.gz.toxresult0 Are you sure (yes/no)? yes (autoset from -y option) deleting release 1.0 of example
若是你沒有指定 -y
選項,你將被詢問確認刪除的交互式操做。
example-1.0
發行版本仍然能夠經過 testuser/dev
訪問,由於他從 testuser/staging
基線繼承了全部的發行版。
$ devpi list example http://localhost:3141/testuser/staging/+f/5bc/44b5ac34ff65b/example-1.0.tar.gz cobra linux2 python 2.7.6 tests passed
$ devpi-server --stop killed server pid=841
若是你想配置安裝一個永久的 devpi-server
。你也能夠經過 Quickstart: permanent install on server/laptop 獲取一些幫助。