9
9
import distutils .errors
10
10
import itertools
11
11
import stat
12
- import warnings
13
12
from pathlib import Path
14
13
from typing import Dict , Iterable , Iterator , List , Optional , Tuple
15
14
16
- from setuptools . _deprecation_warning import SetuptoolsDeprecationWarning
17
- from setuptools . extern . more_itertools import unique_everseen
15
+ from .. extern . more_itertools import unique_everseen
16
+ from .. warnings import SetuptoolsDeprecationWarning
18
17
19
18
20
19
def make_writable (target ):
@@ -325,28 +324,48 @@ def assert_relative(path):
325
324
class _IncludePackageDataAbuse :
326
325
"""Inform users that package or module is included as 'data file'"""
327
326
328
- MESSAGE = """\
329
- Installing {importable!r} as data is deprecated, please list it in `packages`.
330
- !!\n \n
331
- ############################
332
- # Package would be ignored #
333
- ############################
334
- Python recognizes {importable!r} as an importable package,
335
- but it is not listed in the `packages` configuration of setuptools.
336
-
337
- {importable!r} has been automatically added to the distribution only
338
- because it may contain data files, but this behavior is likely to change
339
- in future versions of setuptools (and therefore is considered deprecated).
340
-
341
- Please make sure that {importable!r} is included as a package by using
342
- the `packages` configuration field or the proper discovery methods
343
- (for example by using `find_namespace_packages(...)`/`find_namespace:`
344
- instead of `find_packages(...)`/`find:`).
345
-
346
- You can read more about "package discovery" and "data files" on setuptools
347
- documentation page.
348
- \n \n !!
349
- """
327
+ class _Warning (SetuptoolsDeprecationWarning ):
328
+ _SUMMARY = """
329
+ Package {importable!r} is absent from the `packages` configuration.
330
+ """
331
+
332
+ _DETAILS = """
333
+ ############################
334
+ # Package would be ignored #
335
+ ############################
336
+ Python recognizes {importable!r} as an importable package[^1],
337
+ but it is absent from setuptools' `packages` configuration.
338
+
339
+ This leads to an ambiguous overall configuration. If you want to distribute this
340
+ package, please make sure that {importable!r} is explicitly added
341
+ to the `packages` configuration field.
342
+
343
+ Alternatively, you can also rely on setuptools' discovery methods
344
+ (for example by using `find_namespace_packages(...)`/`find_namespace:`
345
+ instead of `find_packages(...)`/`find:`).
346
+
347
+ You can read more about "package discovery" on setuptools documentation page:
348
+
349
+ - https://setuptools.pypa.io/en/latest/userguide/package_discovery.html
350
+
351
+ If you don't want {importable!r} to be distributed and are
352
+ already explicitly excluding {importable!r} via
353
+ `find_namespace_packages(...)/find_namespace` or `find_packages(...)/find`,
354
+ you can try to use `exclude_package_data`, or `include-package-data=False` in
355
+ combination with a more fine grained `package-data` configuration.
356
+
357
+ You can read more about "package data files" on setuptools documentation page:
358
+
359
+ - https://setuptools.pypa.io/en/latest/userguide/datafiles.html
360
+
361
+
362
+ [^1]: For Python, any directory (with suitable naming) can be imported,
363
+ even if it does not contain any `.py` files.
364
+ On the other hand, currently there is no concept of package data
365
+ directory, all directories are treated like packages.
366
+ """
367
+ # _DUE_DATE: still not defined as this is particularly controversial.
368
+ # Warning initially introduced in May 2022. See issue #3340 for discussion.
350
369
351
370
def __init__ (self ):
352
371
self ._already_warned = set ()
@@ -363,6 +382,5 @@ def importable_subpackage(self, parent, file):
363
382
364
383
def warn (self , importable ):
365
384
if importable not in self ._already_warned :
366
- msg = textwrap .dedent (self .MESSAGE ).format (importable = importable )
367
- warnings .warn (msg , SetuptoolsDeprecationWarning , stacklevel = 2 )
385
+ self ._Warning .emit (importable = importable )
368
386
self ._already_warned .add (importable )
0 commit comments