Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d139b99

Browse files
committed
Fix writing of the RESOURCES file by packaging (#12386)
1 parent f598d60 commit d139b99

4 files changed

Lines changed: 62 additions & 6 deletions

File tree

Lib/packaging/command/install_distinfo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def run(self):
104104
'RESOURCES')
105105
logger.info('creating %s', resources_path)
106106
if not self.dry_run:
107-
with open(resources_path, 'wb') as f:
107+
with open(resources_path, 'w') as f:
108108
writer = csv.writer(f, delimiter=',',
109109
lineterminator='\n',
110110
quotechar='"')

Lib/packaging/tests/test_command_install_data.py

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
11
"""Tests for packaging.command.install_data."""
22
import os
3+
import sys
34
import sysconfig
5+
import packaging.database
46
from sysconfig import _get_default_scheme
57
from packaging.tests import unittest, support
68
from packaging.command.install_data import install_data
9+
from packaging.command.install_dist import install_dist
10+
from packaging.command.install_distinfo import install_distinfo
711

812

913
class InstallDataTestCase(support.TempdirManager,
1014
support.LoggingCatcher,
1115
unittest.TestCase):
1216

13-
def test_simple_run(self):
17+
def setUp(self):
18+
super(InstallDataTestCase, self).setUp()
1419
scheme = _get_default_scheme()
1520
old_items = sysconfig._SCHEMES.items(scheme)
21+
1622
def restore():
1723
sysconfig._SCHEMES.remove_section(scheme)
1824
sysconfig._SCHEMES.add_section(scheme)
1925
for option, value in old_items:
2026
sysconfig._SCHEMES.set(scheme, option, value)
27+
2128
self.addCleanup(restore)
2229

30+
def test_simple_run(self):
2331
pkg_dir, dist = self.create_dist()
2432
cmd = install_data(dist)
2533
cmd.install_dir = inst = os.path.join(pkg_dir, 'inst')
34+
scheme = _get_default_scheme()
2635

2736
sysconfig._SCHEMES.set(scheme, 'inst',
2837
os.path.join(pkg_dir, 'inst'))
@@ -67,8 +76,7 @@ def restore():
6776
three = os.path.join(cmd.install_dir, 'three')
6877
self.write_file(three, 'xx')
6978

70-
sysconfig._SCHEMES.set(scheme, 'inst3',
71-
cmd.install_dir)
79+
sysconfig._SCHEMES.set(scheme, 'inst3', cmd.install_dir)
7280

7381
cmd.data_files = {one: '{inst}/one', two: '{inst2}/two',
7482
three: '{inst3}/three'}
@@ -80,6 +88,49 @@ def restore():
8088
self.assertTrue(os.path.exists(os.path.join(inst2, rtwo)))
8189
self.assertTrue(os.path.exists(os.path.join(inst, rone)))
8290

91+
def test_resources(self):
92+
install_dir = self.mkdtemp()
93+
scripts_dir = self.mkdtemp()
94+
project_dir, dist = self.create_dist(
95+
name='Spamlib', version='0.1',
96+
data_files={'spamd': '{scripts}/spamd'})
97+
98+
os.chdir(project_dir)
99+
self.write_file('spamd', '# Python script')
100+
sysconfig._SCHEMES.set(_get_default_scheme(), 'scripts', scripts_dir)
101+
sys.path.insert(0, install_dir)
102+
self.addCleanup(sys.path.remove, install_dir)
103+
104+
cmd = install_dist(dist)
105+
cmd.outputs = ['spamd']
106+
cmd.install_lib = install_dir
107+
dist.command_obj['install_dist'] = cmd
108+
109+
cmd = install_data(dist)
110+
cmd.install_dir = install_dir
111+
cmd.ensure_finalized()
112+
dist.command_obj['install_data'] = cmd
113+
cmd.run()
114+
115+
cmd = install_distinfo(dist)
116+
cmd.ensure_finalized()
117+
dist.command_obj['install_distinfo'] = cmd
118+
cmd.run()
119+
120+
fn = os.path.join(install_dir, 'Spamlib-0.1.dist-info', 'RESOURCES')
121+
with open(fn, encoding='utf-8') as fp:
122+
content = fp.read().strip()
123+
124+
expected = 'spamd,%s' % os.path.join(scripts_dir, 'spamd')
125+
self.assertEqual(content, expected)
126+
127+
# just to be sure, we also test that get_file works here, even though
128+
# packaging.database has its own test file
129+
with packaging.database.get_file('Spamlib', 'spamd') as fp:
130+
content = fp.read()
131+
132+
self.assertEqual('# Python script', content)
133+
83134

84135
def test_suite():
85136
return unittest.makeSuite(InstallDataTestCase)

Lib/packaging/tests/test_command_install_distinfo.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
"""Tests for ``packaging.command.install_distinfo``. """
1+
"""Tests for ``packaging.command.install_distinfo``.
2+
3+
Writing of the RESOURCES file is tested in test_command_install_data.
4+
"""
25

36
import os
47
import csv

Misc/NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Core and Builtins
1212

1313
- PEP 3151 / issue #12555: reworking the OS and IO exception hierarchy.
1414

15-
- Add internal API for static strings (_Py_identifier et.al.).
15+
- Add internal API for static strings (_Py_identifier et al.).
1616

1717
- Issue #13063: the Windows error ERROR_NO_DATA (numbered 232 and described
1818
as "The pipe is being closed") is now mapped to POSIX errno EPIPE
@@ -304,6 +304,8 @@ Core and Builtins
304304

305305
Library
306306
-------
307+
- Issue #12386: packaging does not fail anymore when writing the RESOURCES
308+
file.
307309

308310
- Issue #13158: Fix decoding and encoding of GNU tar specific base-256 number
309311
fields in tarfile.

0 commit comments

Comments
 (0)