diff --git a/config/README.rst b/config/README.rst index af036ae..db5c579 100644 --- a/config/README.rst +++ b/config/README.rst @@ -109,26 +109,27 @@ See ``--help`` for details. The script does the following steps: -1. Add the package name to ``packages.txt`` of the selected configuration type +#. Add the package name to ``packages.txt`` of the selected configuration type if it is not yet added. -2. Copy ``setup.cfg``, ``tox.ini``, ``tests.yml``, ``MANIFEST.in``, +#. Copy ``setup.cfg``, ``tox.ini``, ``tests.yml``, ``MANIFEST.in``, ``.readthedocs.yaml`` (if needed), and ``.gitignore`` to the repository. -3. Remove a possibly existing ``.coveragerc`` and ``bootstrap.py``. (Coverage +#. Create or update a ``pyproject.toml`` project configuration file. +#. Remove a possibly existing ``.coveragerc`` and ``bootstrap.py``. (Coverage is now configured in ``tox.ini`` for packages which are no buildout recipes.) -4. Run the tests via: ``tox``. The ``tox`` script may be either on the current +#. Run the tests via: ``tox``. The ``tox`` script may be either on the current ``$PATH`` or in the ``bin`` subfolder of the current working directory. -5. Create a branch and a pull request. (Prevent an automatic commit of all +#. Create a branch and a pull request. (Prevent an automatic commit of all changes with the command line switch ``--no-commit``, or an automatic push to GitHub using the command line switch ``--no-push``.) After running the script you should manually do the following steps: -1. Check for changes in the updated repository and for the need of a change log +#. Check for changes in the updated repository and for the need of a change log entry over there. -2. Make sure the package is activated on https://coveralls.io by trying to add +#. Make sure the package is activated on https://coveralls.io by trying to add the repository name and making it active. -3. Check in possible changes in the zopefoundation/meta repository. +#. Check in possible changes in the zopefoundation/meta repository. CLI arguments @@ -693,12 +694,12 @@ See ``--help`` for details. The script does the following steps: -1. It does the following steps for each line in the given ``packages.txt`` +#. It does the following steps for each line in the given ``packages.txt`` which does not start with ``#``. -2. Check if there is a repository in ```` with the name of the +#. Check if there is a repository in ```` with the name of the repository. If it does not exist: clone it. If it exists: clean the clone from changes, switch to ``master`` branch and pull from origin. -3. Call the given script with the package name and arguments for the script. +#. Call the given script with the package name and arguments for the script. .. caution:: diff --git a/config/config-package.py b/config/config-package.py index a525747..ad54aa7 100755 --- a/config/config-package.py +++ b/config/config-package.py @@ -550,6 +550,39 @@ def manifest_in(self): manifest_additional_rules=manifest_additional_rules, with_docs=self.with_docs) + def pyproject_toml(self): + """Modify pyproject.toml with meta options.""" + pyproject_toml_path = self.path / 'pyproject.toml' + if pyproject_toml_path.exists(): + with open(pyproject_toml_path, 'rb') as fp: + pyproject_data = tomlkit.load(fp) + pyproject_toml = collections.defaultdict(dict, **pyproject_data) + else: + pyproject_toml = collections.defaultdict(dict) + + buildsystem_cfg = pyproject_toml['build-system'] + + # Insert sane default for build-system:requires + requires = buildsystem_cfg.get('requires', []) + setuptools_requirement = [ + x for x in requires if x.startswith('setuptools')] + for setuptools_req in setuptools_requirement: + requires.remove(setuptools_req) + requires.append(f'setuptools{SETUPTOOLS_VERSION_SPEC}') + buildsystem_cfg['requires'] = sorted(requires) + + # Insert sane default for build-system:build-backend + build_backend = buildsystem_cfg.get('build-backend', '') + if not build_backend: + buildsystem_cfg['build-backend'] = 'setuptools.build_meta' + + # Remove empty sections before writing to disk + pyproject_toml = {k: v for k, v in pyproject_toml.items() if v} + with open(pyproject_toml_path, 'w') as fp: + fp.write(META_HINT.format(config_type=self.config_type)) + fp.write('\n') + tomlkit.dump(pyproject_toml, fp, sort_keys=True) + def copy_with_meta( self, template_name, destination, config_type, meta_hint=META_HINT, **kw): @@ -580,6 +613,7 @@ def configure(self): if self.with_docs: self.readthedocs() + self.pyproject_toml() self.setup_cfg() self.gitignore() self.pre_commit_config_yaml() @@ -595,6 +629,7 @@ def configure(self): early_add = [ '.pre-commit-config.yaml', 'CONTRIBUTING.md', + 'pyproject.toml', ] if self.args.commit: call('git', 'add', *early_add)