[Python-checkins] distutils2: Finally get back to from_url as a classmethod, as it's seems to be
tarek.ziade
python-checkins at python.org
Thu Jul 15 01:38:05 CEST 2010
tarek.ziade pushed cbe93cce3ae7 to distutils2:
http://hg.python.org/distutils2/rev/cbe93cce3ae7
changeset: 358:cbe93cce3ae7
user: Alexis Metaireau <ametaireau at gmail.com>
date: Wed Jul 07 14:53:16 2010 +0200
summary: Finally get back to from_url as a classmethod, as it's seems to be
files: src/distutils2/pypi/dist.py, src/distutils2/pypi/simple.py, src/distutils2/tests/test_pypi_dist.py
diff --git a/src/distutils2/pypi/dist.py b/src/distutils2/pypi/dist.py
--- a/src/distutils2/pypi/dist.py
+++ b/src/distutils2/pypi/dist.py
@@ -31,6 +31,38 @@
information about distributions.
"""
+ @classmethod
+ def from_url(cls, url, probable_dist_name=None, is_external=True):
+ """Build a Distribution from a url archive (egg or zip or tgz).
+
+ :param url: complete url of the distribution
+ :param probable_dist_name: A probable name of the distribution.
+ :param is_external: Tell if the url commes from an index or from
+ an external URL.
+ """
+ # if the url contains a md5 hash, get it.
+ md5_hash = None
+ match = MD5_HASH.match(url)
+ if match is not None:
+ md5_hash = match.group(1)
+ # remove the hash
+ url = url.replace("#md5=%s" % md5_hash, "")
+
+ # parse the archive name to find dist name and version
+ archive_name = urlparse.urlparse(url)[2].split('/')[-1]
+ extension_matched = False
+ # remove the extension from the name
+ for ext in EXTENSIONS:
+ if archive_name.endswith(ext):
+ archive_name = archive_name[:-len(ext)]
+ extension_matched = True
+
+ name, version = split_archive_name(archive_name)
+ if extension_matched is True:
+ return PyPIDistribution(name, version, url=url, url_hashname="md5",
+ url_hashval=md5_hash,
+ url_is_external=is_external)
+
def __init__(self, name, version, type=None, url=None, url_hashname=None,
url_hashval=None, url_is_external=True):
"""Create a new instance of PyPIDistribution.
@@ -245,36 +277,6 @@
key=lambda i: [getattr(i, arg) for arg in sort_by],
reverse=reverse, *args, **kwargs)
-def create_from_url(url, probable_dist_name=None,
- is_external=True):
- """Build a Distribution from a url archive (egg or zip or tgz).
-
- :param url: complete url of the distribution
- :param probable_dist_name: A probable name of the distribution.
- :param is_external: Tell if the url commes from an index or from
- an external URL.
- """
- # if the url contains a md5 hash, get it.
- md5_hash = None
- match = MD5_HASH.match(url)
- if match is not None:
- md5_hash = match.group(1)
- # remove the hash
- url = url.replace("#md5=%s" % md5_hash, "")
-
- # parse the archive name to find dist name and version
- archive_name = urlparse.urlparse(url)[2].split('/')[-1]
- extension_matched = False
- # remove the extension from the name
- for ext in EXTENSIONS:
- if archive_name.endswith(ext):
- archive_name = archive_name[:-len(ext)]
- extension_matched = True
-
- name, version = split_archive_name(archive_name)
- if extension_matched is True:
- return PyPIDistribution(name, version, url=url, url_hashname="md5",
- url_hashval=md5_hash, url_is_external=is_external)
def split_archive_name(archive_name, probable_name=None):
"""Split an archive name into two parts: name and version.
diff --git a/src/distutils2/pypi/simple.py b/src/distutils2/pypi/simple.py
--- a/src/distutils2/pypi/simple.py
+++ b/src/distutils2/pypi/simple.py
@@ -14,7 +14,7 @@
from distutils2.version import VersionPredicate
from distutils2.pypi.dist import (PyPIDistribution, PyPIDistributions,
- create_from_url, EXTENSIONS)
+ EXTENSIONS)
from distutils2.pypi.errors import (PyPIError, DistributionNotFound,
DownloadError, UnableToDownload)
from distutils2 import __version__ as __distutils2_version__
@@ -264,7 +264,7 @@
if self._is_distribution(link) or is_download:
self._processed_urls.append(link)
# it's a distribution, so create a dist object
- dist = create_from_url(link, project_name,
+ dist = PyPIDistribution.from_url(link, project_name,
is_external=not self.index_url in url)
self._register_dist(dist)
else:
diff --git a/src/distutils2/tests/test_pypi_dist.py b/src/distutils2/tests/test_pypi_dist.py
--- a/src/distutils2/tests/test_pypi_dist.py
+++ b/src/distutils2/tests/test_pypi_dist.py
@@ -11,7 +11,7 @@
from distutils2.pypi.errors import HashDoesNotMatch, UnsupportedHashName
from distutils2.pypi.dist import (PyPIDistribution as Dist,
PyPIDistributions as Dists,
- split_archive_name, create_from_url)
+ split_archive_name)
class TestPyPIDistribution(support.TempdirManager,
@@ -55,7 +55,7 @@
}
for url, attributes in url_list.items():
- dist = create_from_url("http://test.tld/" + url)
+ dist = Dist.from_url("http://test.tld/" + url)
for attribute, value in attributes.items():
if isinstance(value, dict):
mylist = getattr(dist, attribute)
--
Repository URL: http://hg.python.org/distutils2
More information about the Python-checkins
mailing list