From f4576e373b51fab07eec7f6f2cde3ffa2e04f6c0 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Tue, 24 Nov 2015 11:32:45 -0500 Subject: Add VersionlessRequirement adapter to suppress the version number in a Distribution. Ref #439. --- setuptools/command/develop.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'setuptools/command/develop.py') diff --git a/setuptools/command/develop.py b/setuptools/command/develop.py index 368b64fe..0959d937 100755 --- a/setuptools/command/develop.py +++ b/setuptools/command/develop.py @@ -167,3 +167,26 @@ class develop(easy_install): script_text = f.read() f.close() self.install_script(dist, script_name, script_text, script_path) + + +class VersionlessRequirement(object): + """ + Adapt a pkg_resources.Distribution to simply return the project + name as the 'requirement' so that scripts will work across + multiple versions. + + >>> dist = Distribution(project_name='foo', version='1.0') + >>> str(dist.as_requirement()) + 'foo==1.0' + >>> adapted_dist = VersionlessRequirement(dist) + >>> str(adapted_dist.as_requirement()) + 'foo' + """ + def __init__(self, dist): + self.__dist = dist + + def __getattr__(self, name): + return getattr(self.__dist, name) + + def as_requirement(self): + return self.project_name -- cgit v1.2.3