21

ユーザーが元のソフトウェアをインストールするコマンドを発行したときに、GitHub のソースから、GitHub にある依存関係を pip でインストールしたいと思います。これらのパッケージはどちらも PyPi にはありません (今後もありません)。

ユーザーは次のコマンドを発行します。

pip -e git+https://github.com/Lewisham/cvsanaly@develop#egg=cvsanaly

このリポジトリにはrequirements.txtファイルがあり、GitHub に別の依存関係があります。

-e git+https://github.com/Lewisham/repositoryhandler#egg=repositoryhandler

私が望むのは、ユーザーが元のパッケージをインストールするために発行できる単一のコマンドであり、pip で要件ファイルを見つけてから、依存関係もインストールします。

4

3 に答える 3

36

この回答は、あなたが話しているのと同じ問題を解決するのに役立ちました。

setup.py が要件ファイルを直接使用してその依存関係を定義する簡単な方法はないようですが、同じ情報を setup.py 自体に入れることができます。

私はこのrequirements.txtを持っています:

PIL
-e git://github.com/gabrielgrant/django-ckeditor.git#egg=django-ckeditor

しかし、requirements.txt を含むパッケージをインストールすると、要件は pip によって無視されます。

この setup.py は、依存関係をインストールするように pip を強制しているようです (django-ckeditor の私の github バージョンを含む):

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以下のコメントのように、バージョンとして使用することはお勧めできません。

于 2010-12-19T12:56:55.430 に答える
13

これは、要件ファイルから生成するため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)
于 2012-02-03T07:55:32.813 に答える
1

これはあなたの質問に答えていますか?

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(),
  )
于 2012-06-18T19:35:47.817 に答える