summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Ganssle <pganssle@users.noreply.github.com>2019-02-08 14:55:14 -0500
committerGitHub <noreply@github.com>2019-02-08 14:55:14 -0500
commitcdb5eeae678d8ccc90bf7d4348013a294f11be75 (patch)
tree71d84879527c63b9d4f40b8e039bb4123dc7ca7b
parentc1243e96f05d3b13392a792144c97d9471581550 (diff)
parent6bda3d5f1814b28a5a493363ca16228a4e37cd26 (diff)
downloadpython-setuptools-git-cdb5eeae678d8ccc90bf7d4348013a294f11be75.tar.gz
Merge pull request #1675 from pganssle/optional_setup_py
Add support for setup.cfg-only projects
-rw-r--r--changelog.d/1675.change.rst1
-rw-r--r--setuptools/build_meta.py16
-rw-r--r--setuptools/tests/test_build_meta.py23
3 files changed, 35 insertions, 5 deletions
diff --git a/changelog.d/1675.change.rst b/changelog.d/1675.change.rst
new file mode 100644
index 00000000..e9067628
--- /dev/null
+++ b/changelog.d/1675.change.rst
@@ -0,0 +1 @@
+Added support for ``setup.cfg``-only projects when using the ``setuptools.build_meta`` backend. Projects that have enabled PEP 517 no longer need to have a ``setup.py`` and can use the purely declarative ``setup.cfg`` configuration file instead.
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):
diff --git a/setuptools/tests/test_build_meta.py b/setuptools/tests/test_build_meta.py
index 6236b9f4..74969322 100644
--- a/setuptools/tests/test_build_meta.py
+++ b/setuptools/tests/test_build_meta.py
@@ -110,6 +110,21 @@ defns = [
print('hello')
"""),
},
+ {
+ 'setup.cfg': DALS("""
+ [metadata]
+ name = foo
+ version='0.0.0'
+
+ [options]
+ py_modules=hello
+ setup_requires=six
+ """),
+ 'hello.py': DALS("""
+ def run():
+ print('hello')
+ """)
+ },
]
@@ -183,9 +198,13 @@ class TestBuildMetaBackend:
# if the setup.py changes subsequent call of the build meta
# should still succeed, given the
# sdist_directory the frontend specifies is empty
- with open(os.path.abspath("setup.py"), 'rt') as file_handler:
+ setup_loc = os.path.abspath("setup.py")
+ if not os.path.exists(setup_loc):
+ setup_loc = os.path.abspath("setup.cfg")
+
+ with open(setup_loc, 'rt') as file_handler:
content = file_handler.read()
- with open(os.path.abspath("setup.py"), 'wt') as file_handler:
+ with open(setup_loc, 'wt') as file_handler:
file_handler.write(
content.replace("version='0.0.0'", "version='0.0.1'"))