PIPは、インストール時にsetup.pyで指定されていない依存関係をインストールできますか?
-
08-10-2019 - |
質問
ユーザーがコマンドを発行して元のソフトウェアをインストールしたときに、GitHubのソースからも、GitHubに依存関係をインストールしてもらいたいと思います。これらのパッケージはどちらもPypi上にありません(そして決してそうなることはありません)。
ユーザーはコマンドを発行します。
pip -e git+https://github.com/Lewisham/cvsanaly@develop#egg=cvsanaly
このレポはを持っています requirements.txt
ファイル、githubへの別の依存関係:
-e git+https://github.com/Lewisham/repositoryhandler#egg=repositoryhandler
私が欲しいのはaです 単一コマンド ユーザーが元のパッケージをインストールするために発行し、PIPに要件ファイルを見つけてもらい、依存関係もインストールできることです。
解決
この答え あなたが話しているのと同じ問題を解決するのを助けてくれました。
Setup.pyが要件ファイルを直接使用してその依存関係を定義する簡単な方法はないようですが、同じ情報をSetup.py自体に配置できます。
私はこの要件を持っています.txt:
PIL
-e git://github.com/gabrielgrant/django-ckeditor.git#egg=django-ckeditor
ただし、その要件をインストールする場合、txtのコンテンディングパッケージをインストールすると、要件はPIPによって無視されます。
このsetup.pyは、pipを依存関係のインストールに強制しているようです(githubバージョンのdjango-ckeditorを含む):
from setuptools import setup
setup(
name='django-articles',
...,
install_requires=[
'PIL',
'django-ckeditor>=0.9.3',
],
dependency_links = [
'http://github.com/gabrielgrant/django-ckeditor/tarball/master#egg=django-ckeditor-0.9.3',
]
)
編集:
この答え また、いくつかの有用な情報が含まれています。
「#egg = ...」の一部としてバージョンを指定することは、リンクで使用可能なパッケージのバージョンを識別するために必要です。 ただし、最新バージョンに常に依存したい場合は、バージョンをに設定できることに注意してください。 dev
Install_Requires、Dependency_Linksおよびその他のパッケージのsetup.py
編集: 使用 dev
以下のコメントに従って、バージョンは良いアイデアではないためです。
他のヒント
これが私が生成していた小さなスクリプトです install_requires
と dependency_links
要件ファイルから。
import os
import re
def which(program):
"""
Detect whether or not a program is installed.
Thanks to http://stackoverflow.com/a/377028/70191
"""
def is_exe(fpath):
return os.path.exists(fpath) and os.access(fpath, os.X_OK)
fpath, _ = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ['PATH'].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
EDITABLE_REQUIREMENT = re.compile(r'^-e (?P<link>(?P<vcs>git|svn|hg|bzr).+#egg=(?P<package>.+)-(?P<version>\d(?:\.\d)*))$')
install_requires = []
dependency_links = []
for requirement in (l.strip() for l in open('requirements')):
match = EDITABLE_REQUIREMENT.match(requirement)
if match:
assert which(match.group('vcs')) is not None, \
"VCS '%(vcs)s' must be installed in order to install %(link)s" % match.groupdict()
install_requires.append("%(package)s==%(version)s" % match.groupdict())
dependency_links.append(match.group('link'))
else:
install_requires.append(requirement)
これはあなたの質問に答えますか?
setup(name='application-xpto',
version='1.0',
author='me,me,me',
author_email='xpto@mail.com',
packages=find_packages(),
include_package_data=True,
description='web app',
install_requires=open('app/requirements.txt').readlines(),
)