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

Skip to content

Commit 313570a

Browse files
committed
Branch merge: packaging fixes
2 parents 1752468 + 69cdf92 commit 313570a

6 files changed

Lines changed: 107 additions & 88 deletions

File tree

Doc/packaging/setupcfg.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,9 @@ obsoletes-dist
265265
Same format than *requires-dist*. *optional*, *multi*, *environ*
266266

267267
requires-python
268-
Specifies the Python version the distribution requires.
269-
The value is a version number, as described in PEP 345.
270-
*optional*, *multi*, *environ*
268+
Specifies the Python version the distribution requires. The value is a
269+
comma-separated list of version predicates, as described in PEP 345.
270+
*optional*, *environ*
271271

272272
requires-externals
273273
a dependency in the system. This field is free-form,

Lib/packaging/command/sdist.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,20 @@ def get_file_list(self):
201201
self.filelist.write(self.manifest)
202202

203203
def add_defaults(self):
204-
"""Add all the default files to self.filelist:
205-
- all pure Python modules mentioned in setup script
206-
- all files pointed by package_data (build_py)
207-
- all files defined in data_files.
208-
- all files defined as scripts.
209-
- all C sources listed as part of extensions or C libraries
210-
in the setup script (doesn't catch C headers!)
211-
Everything is optional.
204+
"""Add all default files to self.filelist.
205+
206+
In addition to the setup.cfg file, this will include all files returned
207+
by the get_source_files of every registered command. This will find
208+
Python modules and packages, data files listed in package_data_,
209+
data_files and extra_files, scripts, C sources of extension modules or
210+
C libraries (headers are missing).
212211
"""
212+
if os.path.exists('setup.cfg'):
213+
self.filelist.append('setup.cfg')
214+
else:
215+
logger.warning("%s: standard 'setup.cfg' file not found",
216+
self.get_command_name())
217+
213218
for cmd_name in get_command_names():
214219
try:
215220
cmd_obj = self.get_finalized_command(cmd_name)

Lib/packaging/tests/test_command_sdist.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
MANIFEST = """\
3535
# file GENERATED by packaging, do NOT edit
3636
inroot.txt
37+
setup.cfg
3738
data%(sep)sdata.dt
3839
scripts%(sep)sscript.py
3940
some%(sep)sfile.txt
@@ -173,6 +174,7 @@ def test_add_defaults(self):
173174
# in package_data
174175
dist.package_data = {'': ['*.cfg', '*.dat'],
175176
'somecode': ['*.txt']}
177+
self.write_file((self.tmp_dir, 'setup.cfg'), '#')
176178
self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#')
177179
self.write_file((self.tmp_dir, 'somecode', 'doc.dat'), '#')
178180

@@ -211,9 +213,9 @@ def test_add_defaults(self):
211213
with zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip')) as zip_file:
212214
content = zip_file.namelist()
213215

214-
# Making sure everything was added. This includes 9 code and data
215-
# files in addition to PKG-INFO.
216-
self.assertEqual(len(content), 9)
216+
# Making sure everything was added. This includes 8 code and data
217+
# files in addition to PKG-INFO and setup.cfg
218+
self.assertEqual(len(content), 10)
217219

218220
# Checking the MANIFEST
219221
with open(join(self.tmp_dir, 'MANIFEST')) as fp:
@@ -230,7 +232,7 @@ def test_metadata_check_option(self):
230232
cmd.ensure_finalized()
231233
cmd.run()
232234
warnings = self.get_logs(logging.WARN)
233-
self.assertEqual(len(warnings), 3)
235+
self.assertEqual(len(warnings), 4)
234236

235237
# trying with a complete set of metadata
236238
self.loghandler.flush()
@@ -242,8 +244,9 @@ def test_metadata_check_option(self):
242244
# removing manifest generated warnings
243245
warnings = [warn for warn in warnings if
244246
not warn.endswith('-- skipping')]
245-
# the remaining warning is about the use of the default file list
246-
self.assertEqual(len(warnings), 1)
247+
# the remaining warnings are about the use of the default file list and
248+
# the absence of setup.cfg
249+
self.assertEqual(len(warnings), 2)
247250

248251
def test_show_formats(self):
249252
__, stdout = captured_stdout(show_formats)

Lib/packaging/tests/test_command_upload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ def test_upload_docs(self):
140140
cmd.upload_docs = True
141141
cmd.ensure_finalized()
142142
cmd.repository = self.pypi.full_address
143+
prev_dir = os.getcwd()
143144
try:
144-
prev_dir = os.getcwd()
145145
os.chdir(self.tmp_dir)
146146
cmd.run()
147147
finally:

Lib/packaging/tests/test_create.py

Lines changed: 74 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class CreateTestCase(support.TempdirManager,
1313
support.EnvironRestorer,
1414
unittest.TestCase):
1515

16+
maxDiff = None
1617
restore_environ = ['PLAT']
1718

1819
def setUp(self):
@@ -65,10 +66,15 @@ def test_find_files(self):
6566
# building the structure
6667
tempdir = self.wdir
6768
dirs = ['pkg1', 'data', 'pkg2', 'pkg2/sub']
68-
files = ['README', 'setup.cfg', 'foo.py',
69-
'pkg1/__init__.py', 'pkg1/bar.py',
70-
'data/data1', 'pkg2/__init__.py',
71-
'pkg2/sub/__init__.py']
69+
files = [
70+
'README',
71+
'data/data1',
72+
'foo.py',
73+
'pkg1/__init__.py',
74+
'pkg1/bar.py',
75+
'pkg2/__init__.py',
76+
'pkg2/sub/__init__.py',
77+
]
7278

7379
for dir_ in dirs:
7480
os.mkdir(os.path.join(tempdir, dir_))
@@ -85,8 +91,8 @@ def test_find_files(self):
8591
['pkg1', 'pkg2', 'pkg2.sub'])
8692
self.assertEqual(mainprogram.data['modules'], ['foo'])
8793
data_fn = os.path.join('data', 'data1')
88-
self.assertEqual(set(mainprogram.data['extra_files']),
89-
set(['setup.cfg', 'README', data_fn]))
94+
self.assertEqual(mainprogram.data['extra_files'],
95+
['README', data_fn])
9096

9197
def test_convert_setup_py_to_cfg(self):
9298
self.write_file((self.wdir, 'setup.py'),
@@ -130,43 +136,45 @@ def test_convert_setup_py_to_cfg(self):
130136
main()
131137

132138
with open(os.path.join(self.wdir, 'setup.cfg'), encoding='utf-8') as fp:
133-
lines = set(line.rstrip() for line in fp)
134-
135-
# FIXME don't use sets
136-
self.assertEqual(lines, set(['',
137-
'[metadata]',
138-
'version = 0.2',
139-
'name = pyxfoil',
140-
'maintainer = André Espaze',
141-
'description = My super Death-scription',
142-
' |barbar is now on the public domain,',
143-
' |ho, baby !',
144-
'maintainer_email = [email protected]',
145-
'home_page = http://www.python-science.org/project/pyxfoil',
146-
'download_url = UNKNOWN',
147-
'summary = Python bindings for the Xfoil engine',
148-
'[files]',
149-
'modules = my_lib',
150-
' mymodule',
151-
'packages = pyxfoil',
152-
' babar',
153-
' me',
154-
'extra_files = Martinique/Lamentin/dady',
155-
' Martinique/Lamentin/mumy',
156-
' Martinique/Lamentin/sys',
157-
' Martinique/Lamentin/bro',
158-
' Pom',
159-
' Flora',
160-
' Alexander',
161-
' setup.py',
162-
' README',
163-
' pyxfoil/fengine.so',
164-
'scripts = my_script',
165-
' bin/run',
166-
'resources =',
167-
' README.rst = {doc}',
168-
' pyxfoil.1 = {man}',
169-
]))
139+
contents = fp.read()
140+
141+
self.assertEqual(contents, dedent("""\
142+
[metadata]
143+
name = pyxfoil
144+
version = 0.2
145+
summary = Python bindings for the Xfoil engine
146+
download_url = UNKNOWN
147+
home_page = http://www.python-science.org/project/pyxfoil
148+
maintainer = André Espaze
149+
maintainer_email = [email protected]
150+
description = My super Death-scription
151+
|barbar is now on the public domain,
152+
|ho, baby !
153+
154+
[files]
155+
packages = pyxfoil
156+
babar
157+
me
158+
modules = my_lib
159+
mymodule
160+
scripts = my_script
161+
bin/run
162+
extra_files = Martinique/Lamentin/dady
163+
Martinique/Lamentin/mumy
164+
Martinique/Lamentin/sys
165+
Martinique/Lamentin/bro
166+
setup.py
167+
README
168+
Pom
169+
Flora
170+
Alexander
171+
pyxfoil/fengine.so
172+
173+
resources =
174+
README.rst = {doc}
175+
pyxfoil.1 = {man}
176+
177+
"""))
170178

171179
def test_convert_setup_py_to_cfg_with_description_in_readme(self):
172180
self.write_file((self.wdir, 'setup.py'),
@@ -203,26 +211,29 @@ def test_convert_setup_py_to_cfg_with_description_in_readme(self):
203211
# FIXME Out of memory error.
204212
main()
205213
with open(os.path.join(self.wdir, 'setup.cfg'), encoding='utf-8') as fp:
206-
lines = set(line.rstrip() for line in fp)
207-
208-
self.assertEqual(lines, set(['',
209-
'[metadata]',
210-
'version = 0.2',
211-
'name = pyxfoil',
212-
'maintainer = André Espaze',
213-
'maintainer_email = [email protected]',
214-
'home_page = http://www.python-science.org/project/pyxfoil',
215-
'download_url = UNKNOWN',
216-
'summary = Python bindings for the Xfoil engine',
217-
'description-file = README.txt',
218-
'[files]',
219-
'packages = pyxfoil',
220-
'extra_files = pyxfoil/fengine.so',
221-
' pyxfoil/babar.so',
222-
'resources =',
223-
' README.rst = {doc}',
224-
' pyxfoil.1 = {man}',
225-
]))
214+
contents = fp.read()
215+
216+
self.assertEqual(contents, dedent("""\
217+
[metadata]
218+
name = pyxfoil
219+
version = 0.2
220+
summary = Python bindings for the Xfoil engine
221+
download_url = UNKNOWN
222+
home_page = http://www.python-science.org/project/pyxfoil
223+
maintainer = André Espaze
224+
maintainer_email = [email protected]
225+
description-file = README.txt
226+
227+
[files]
228+
packages = pyxfoil
229+
extra_files = pyxfoil/fengine.so
230+
pyxfoil/babar.so
231+
232+
resources =
233+
README.rst = {doc}
234+
pyxfoil.1 = {man}
235+
236+
"""))
226237

227238

228239
def test_suite():

Lib/sysconfig.cfg

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
[globals]
2-
# These are the useful categories that are sometimes referenced at runtime,
3-
# using packaging.resources.get_file:
2+
# These are useful categories that can be referenced at run time,
3+
# using packaging.database.get_file.
44
# Configuration files
55
config = {confdir}/{distribution.name}
66
# Non-writable data that is independent of architecture (images, many xml/text files)
77
appdata = {datadir}/{distribution.name}
88
# Non-writable data that is architecture-dependent (some binary data formats)
99
appdata.arch = {libdir}/{distribution.name}
10-
# Data, written by the package, that must be preserved (databases)
10+
# Data, written by the app/lib, that must be preserved (databases)
1111
appdata.persistent = {statedir}/lib/{distribution.name}
12-
# Data, written by the package, that can be safely discarded (cache)
12+
# Data, written by the app/lib, that can be safely discarded (cache)
1313
appdata.disposable = {statedir}/cache/{distribution.name}
14-
# Help or documentation files referenced at runtime
14+
# Help or documentation files
1515
help = {datadir}/{distribution.name}
1616
icon = {datadir}/pixmaps
1717
scripts = {base}/bin
1818

1919
# Non-runtime files. These are valid categories for marking files for
20-
# install, but they should not be referenced by the app at runtime:
21-
# Help or documentation files not referenced by the package at runtime
20+
# install, but they should not be referenced by the app/lib at run time.
21+
# Help or documentation files
2222
doc = {datadir}/doc/{distribution.name}
2323
# GNU info documentation files
2424
info = {datadir}/info

0 commit comments

Comments
 (0)