Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for setup.cfg-only projects #1675

Merged
merged 2 commits into from Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions 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.
16 changes: 13 additions & 3 deletions setuptools/build_meta.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
23 changes: 21 additions & 2 deletions setuptools/tests/test_build_meta.py
Expand Up @@ -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')
""")
},
]


Expand Down Expand Up @@ -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'"))

Expand Down