summaryrefslogtreecommitdiff
path: root/setuptools/build_meta.py
diff options
context:
space:
mode:
authorPaul Ganssle <paul@ganssle.io>2019-01-31 08:29:36 -0500
committerPaul Ganssle <paul@ganssle.io>2019-02-07 08:08:14 -0500
commit179115b198387a21202433ea61cc53f2efd383fc (patch)
tree7689eb8f018a3e8c91a2714419d47e8a9e9ef43e /setuptools/build_meta.py
parentc1243e96f05d3b13392a792144c97d9471581550 (diff)
downloadpython-setuptools-git-179115b198387a21202433ea61cc53f2efd383fc.tar.gz
Add support for setup.cfg-only projects
Many projects can get away with an empty `setup.py` and use *only* the declarative `setup.cfg`. With the new PEP 517 backend, we can supply a default empty `setup.py` if one is not provided.
Diffstat (limited to 'setuptools/build_meta.py')
-rw-r--r--setuptools/build_meta.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py
index 70b7ab23..047cc07b 100644
--- a/setuptools/build_meta.py
+++ b/setuptools/build_meta.py
@@ -26,6 +26,7 @@ bug reports or API stability):
Again, this is not a formal definition! Just a "taste" of the module.
"""
+import io
import os
import sys
import tokenize
@@ -95,6 +96,14 @@ def _file_with_extension(directory, extension):
return file
+def _open_setup_script(setup_script):
+ if not os.path.exists(setup_script):
+ # Supply a default setup.py
+ return io.StringIO(u"from setuptools import setup; setup()")
+
+ return getattr(tokenize, 'open', open)(setup_script)
+
+
class _BuildMetaBackend(object):
def _fix_config(self, config_settings):
@@ -120,9 +129,10 @@ class _BuildMetaBackend(object):
# Correctness comes first, then optimization later
__file__ = setup_script
__name__ = '__main__'
- f = getattr(tokenize, 'open', open)(__file__)
- code = f.read().replace('\\r\\n', '\\n')
- f.close()
+
+ with _open_setup_script(__file__) as f:
+ code = f.read().replace(r'\r\n', r'\n')
+
exec(compile(code, __file__, 'exec'), locals())
def get_requires_for_build_wheel(self, config_settings=None):