From 179115b198387a21202433ea61cc53f2efd383fc Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Thu, 31 Jan 2019 08:29:36 -0500 Subject: [PATCH 1/2] 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. --- setuptools/build_meta.py | 16 +++++++++++++--- setuptools/tests/test_build_meta.py | 23 +++++++++++++++++++++-- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/setuptools/build_meta.py b/setuptools/build_meta.py index 70b7ab230e..047cc07b69 100644 --- a/setuptools/build_meta.py +++ b/setuptools/build_meta.py @@ -26,6 +26,7 @@ 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 @@ def run_setup(self, setup_script='setup.py'): # 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 6236b9f42b..74969322c1 100644 --- a/setuptools/tests/test_build_meta.py +++ b/setuptools/tests/test_build_meta.py @@ -110,6 +110,21 @@ def run(): 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 @@ def test_build_sdist_version_change(self, build_backend): # 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'")) From 6bda3d5f1814b28a5a493363ca16228a4e37cd26 Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Thu, 7 Feb 2019 08:12:48 -0500 Subject: [PATCH 2/2] Add changelog for PR #1675 --- changelog.d/1675.change.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/1675.change.rst diff --git a/changelog.d/1675.change.rst b/changelog.d/1675.change.rst new file mode 100644 index 0000000000..e90676283f --- /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.