diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2015-11-24 11:32:45 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-11-24 11:32:45 -0500 |
commit | f4576e373b51fab07eec7f6f2cde3ffa2e04f6c0 (patch) | |
tree | 5398102561bdae60b6ba018023d8d55dabcfb622 /setuptools/command/develop.py | |
parent | 998ceceaeb3dfce1b2b05a82aaf356db54f46de6 (diff) | |
download | python-setuptools-git-f4576e373b51fab07eec7f6f2cde3ffa2e04f6c0.tar.gz |
Add VersionlessRequirement adapter to suppress the version number in a Distribution. Ref #439.
Diffstat (limited to 'setuptools/command/develop.py')
-rwxr-xr-x | setuptools/command/develop.py | 23 |
1 files changed, 23 insertions, 0 deletions
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 |