summaryrefslogtreecommitdiff
path: root/setuptools
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2017-09-03 13:39:20 -0400
committerGitHub <noreply@github.com>2017-09-03 13:39:20 -0400
commit7944b2b156cc49e6aeec83a8179bc4ce23496c82 (patch)
treeccfa29eeb92e4afb2368c4a5eca9e97e744b18d9 /setuptools
parent500bb9a161e810523c48825491b853c5fbe595cc (diff)
parentf7e27cc04a9db9952dd1cdeee7e9b0a8b779f0d0 (diff)
downloadpython-setuptools-git-7944b2b156cc49e6aeec83a8179bc4ce23496c82.tar.gz
Merge branch 'master' into add_markdown_to_possible_readmes
Diffstat (limited to 'setuptools')
-rw-r--r--setuptools/command/bdist_egg.py16
-rwxr-xr-xsetuptools/command/egg_info.py4
-rw-r--r--setuptools/dist.py64
-rw-r--r--setuptools/tests/test_dist.py46
-rw-r--r--setuptools/tests/test_egg_info.py25
5 files changed, 121 insertions, 34 deletions
diff --git a/setuptools/command/bdist_egg.py b/setuptools/command/bdist_egg.py
index 8cd9dfef..51755d52 100644
--- a/setuptools/command/bdist_egg.py
+++ b/setuptools/command/bdist_egg.py
@@ -38,6 +38,14 @@ def strip_module(filename):
filename = filename[:-6]
return filename
+def sorted_walk(dir):
+ """Do os.walk in a reproducible way,
+ independent of indeterministic filesystem readdir order
+ """
+ for base, dirs, files in os.walk(dir):
+ dirs.sort()
+ files.sort()
+ yield base, dirs, files
def write_stub(resource, pyfile):
_stub_template = textwrap.dedent("""
@@ -302,7 +310,7 @@ class bdist_egg(Command):
ext_outputs = []
paths = {self.bdist_dir: ''}
- for base, dirs, files in os.walk(self.bdist_dir):
+ for base, dirs, files in sorted_walk(self.bdist_dir):
for filename in files:
if os.path.splitext(filename)[1].lower() in NATIVE_EXTENSIONS:
all_outputs.append(paths[base] + filename)
@@ -329,7 +337,7 @@ NATIVE_EXTENSIONS = dict.fromkeys('.dll .so .dylib .pyd'.split())
def walk_egg(egg_dir):
"""Walk an unpacked egg's contents, skipping the metadata directory"""
- walker = os.walk(egg_dir)
+ walker = sorted_walk(egg_dir)
base, dirs, files = next(walker)
if 'EGG-INFO' in dirs:
dirs.remove('EGG-INFO')
@@ -463,10 +471,10 @@ def make_zipfile(zip_filename, base_dir, verbose=0, dry_run=0, compress=True,
compression = zipfile.ZIP_DEFLATED if compress else zipfile.ZIP_STORED
if not dry_run:
z = zipfile.ZipFile(zip_filename, mode, compression=compression)
- for dirname, dirs, files in os.walk(base_dir):
+ for dirname, dirs, files in sorted_walk(base_dir):
visit(z, dirname, files)
z.close()
else:
- for dirname, dirs, files in os.walk(base_dir):
+ for dirname, dirs, files in sorted_walk(base_dir):
visit(None, dirname, files)
return zip_filename
diff --git a/setuptools/command/egg_info.py b/setuptools/command/egg_info.py
index 6c00b0b7..a183d15d 100755
--- a/setuptools/command/egg_info.py
+++ b/setuptools/command/egg_info.py
@@ -599,6 +599,10 @@ def write_pkg_info(cmd, basename, filename):
metadata = cmd.distribution.metadata
metadata.version, oldver = cmd.egg_version, metadata.version
metadata.name, oldname = cmd.egg_name, metadata.name
+ metadata.long_description_content_type = getattr(
+ cmd.distribution,
+ 'long_description_content_type'
+ )
try:
# write unescaped data to PKG-INFO, so older pkg_resources
# can still parse it
diff --git a/setuptools/dist.py b/setuptools/dist.py
index 21730f22..a2ca8795 100644
--- a/setuptools/dist.py
+++ b/setuptools/dist.py
@@ -58,6 +58,13 @@ def write_pkg_file(self, file):
if self.download_url:
file.write('Download-URL: %s\n' % self.download_url)
+ long_desc_content_type = getattr(
+ self,
+ 'long_description_content_type',
+ None
+ ) or 'UNKNOWN'
+ file.write('Description-Content-Type: %s\n' % long_desc_content_type)
+
long_desc = rfc822_escape(self.get_long_description())
file.write('Description: %s\n' % long_desc)
@@ -317,6 +324,9 @@ class Distribution(Distribution_parse_config_files, _Distribution):
self.dist_files = []
self.src_root = attrs and attrs.pop("src_root", None)
self.patch_missing_pkg_info(attrs)
+ self.long_description_content_type = _attrs_dict.get(
+ 'long_description_content_type'
+ )
# Make sure we have any eggs needed to interpret 'attrs'
if attrs is not None:
self.dependency_links = attrs.pop('dependency_links', [])
@@ -485,36 +495,30 @@ class Distribution(Distribution_parse_config_files, _Distribution):
def fetch_build_egg(self, req):
"""Fetch an egg needed for building"""
-
- try:
- cmd = self._egg_fetcher
- cmd.package_index.to_scan = []
- except AttributeError:
- from setuptools.command.easy_install import easy_install
- dist = self.__class__({'script_args': ['easy_install']})
- dist.parse_config_files()
- opts = dist.get_option_dict('easy_install')
- keep = (
- 'find_links', 'site_dirs', 'index_url', 'optimize',
- 'site_dirs', 'allow_hosts'
- )
- for key in list(opts):
- if key not in keep:
- del opts[key] # don't use any other settings
- if self.dependency_links:
- links = self.dependency_links[:]
- if 'find_links' in opts:
- links = opts['find_links'][1].split() + links
- opts['find_links'] = ('setup', links)
- install_dir = self.get_egg_cache_dir()
- cmd = easy_install(
- dist, args=["x"], install_dir=install_dir,
- exclude_scripts=True,
- always_copy=False, build_directory=None, editable=False,
- upgrade=False, multi_version=True, no_report=True, user=False
- )
- cmd.ensure_finalized()
- self._egg_fetcher = cmd
+ from setuptools.command.easy_install import easy_install
+ dist = self.__class__({'script_args': ['easy_install']})
+ dist.parse_config_files()
+ opts = dist.get_option_dict('easy_install')
+ keep = (
+ 'find_links', 'site_dirs', 'index_url', 'optimize',
+ 'site_dirs', 'allow_hosts'
+ )
+ for key in list(opts):
+ if key not in keep:
+ del opts[key] # don't use any other settings
+ if self.dependency_links:
+ links = self.dependency_links[:]
+ if 'find_links' in opts:
+ links = opts['find_links'][1].split() + links
+ opts['find_links'] = ('setup', links)
+ install_dir = self.get_egg_cache_dir()
+ cmd = easy_install(
+ dist, args=["x"], install_dir=install_dir,
+ exclude_scripts=True,
+ always_copy=False, build_directory=None, editable=False,
+ upgrade=False, multi_version=True, no_report=True, user=False
+ )
+ cmd.ensure_finalized()
return cmd.easy_install(req)
def _set_global_opts_from_features(self):
diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py
new file mode 100644
index 00000000..435ffec0
--- /dev/null
+++ b/setuptools/tests/test_dist.py
@@ -0,0 +1,46 @@
+from setuptools import Distribution
+from setuptools.extern.six.moves.urllib.request import pathname2url
+from setuptools.extern.six.moves.urllib_parse import urljoin
+
+from .textwrap import DALS
+from .test_easy_install import make_nspkg_sdist
+
+
+def test_dist_fetch_build_egg(tmpdir):
+ """
+ Check multiple calls to `Distribution.fetch_build_egg` work as expected.
+ """
+ index = tmpdir.mkdir('index')
+ index_url = urljoin('file://', pathname2url(str(index)))
+ def sdist_with_index(distname, version):
+ dist_dir = index.mkdir(distname)
+ dist_sdist = '%s-%s.tar.gz' % (distname, version)
+ make_nspkg_sdist(str(dist_dir.join(dist_sdist)), distname, version)
+ with dist_dir.join('index.html').open('w') as fp:
+ fp.write(DALS(
+ '''
+ <!DOCTYPE html><html><body>
+ <a href="{dist_sdist}" rel="internal">{dist_sdist}</a><br/>
+ </body></html>
+ '''
+ ).format(dist_sdist=dist_sdist))
+ sdist_with_index('barbazquux', '3.2.0')
+ sdist_with_index('barbazquux-runner', '2.11.1')
+ with tmpdir.join('setup.cfg').open('w') as fp:
+ fp.write(DALS(
+ '''
+ [easy_install]
+ index_url = {index_url}
+ '''
+ ).format(index_url=index_url))
+ reqs = '''
+ barbazquux-runner
+ barbazquux
+ '''.split()
+ with tmpdir.as_cwd():
+ dist = Distribution()
+ resolved_dists = [
+ dist.fetch_build_egg(r)
+ for r in reqs
+ ]
+ assert [dist.key for dist in resolved_dists if dist] == reqs
diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py
index 33d6cc52..e454694d 100644
--- a/setuptools/tests/test_egg_info.py
+++ b/setuptools/tests/test_egg_info.py
@@ -398,6 +398,31 @@ class TestEggInfo(object):
self._run_install_command(tmpdir_cwd, env)
assert glob.glob(os.path.join(env.paths['lib'], 'barbazquux*')) == []
+ def test_long_description_content_type(self, tmpdir_cwd, env):
+ # Test that specifying a `long_description_content_type` keyword arg to
+ # the `setup` function results in writing a `Description-Content-Type`
+ # line to the `PKG-INFO` file in the `<distribution>.egg-info`
+ # directory.
+ # `Description-Content-Type` is described at
+ # https://github.com/pypa/python-packaging-user-guide/pull/258
+
+ self._setup_script_with_requires(
+ """long_description_content_type='text/markdown',""")
+ environ = os.environ.copy().update(
+ HOME=env.paths['home'],
+ )
+ code, data = environment.run_setup_py(
+ cmd=['egg_info'],
+ pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]),
+ data_stream=1,
+ env=environ,
+ )
+ egg_info_dir = os.path.join('.', 'foo.egg-info')
+ with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file:
+ pkg_info_lines = pkginfo_file.read().split('\n')
+ expected_line = 'Description-Content-Type: text/markdown'
+ assert expected_line in pkg_info_lines
+
def test_python_requires_egg_info(self, tmpdir_cwd, env):
self._setup_script_with_requires(
"""python_requires='>=2.7.12',""")