From a3c8751adb9f44f8c7414d31665a3f2e1c60ed3e Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl Date: Sun, 1 Sep 2024 11:48:31 +0200 Subject: [PATCH 1/8] - add ``pyproject.toml`` to the list of managed files --- config/README.rst | 7 ++++--- config/config-package.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/config/README.rst b/config/README.rst index af036ae..3018454 100644 --- a/config/README.rst +++ b/config/README.rst @@ -113,12 +113,13 @@ The script does the following steps: if it is not yet added. 2. 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 +3. Create or update a ``pyproject.toml`` project configuration file. +4. 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 +5. 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 +6. 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``.) diff --git a/config/config-package.py b/config/config-package.py index a525747..23c17cd 100755 --- a/config/config-package.py +++ b/config/config-package.py @@ -550,6 +550,38 @@ 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')] + if not setuptools_requirement: + requires.append(f'setuptools{SETUPTOOLS_VERSION_SPEC}') + buildsystem_cfg['requires'] = 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) + def copy_with_meta( self, template_name, destination, config_type, meta_hint=META_HINT, **kw): @@ -580,6 +612,7 @@ def configure(self): if self.with_docs: self.readthedocs() + self.pyproject_toml() self.setup_cfg() self.gitignore() self.pre_commit_config_yaml() From fc0a7b199ba717b93a926f955ff35a477e93816b Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl Date: Mon, 2 Sep 2024 08:33:38 +0200 Subject: [PATCH 2/8] - sort pyproject.toml keys, this file will be larger in the future --- config/config-package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config-package.py b/config/config-package.py index 23c17cd..9013741 100755 --- a/config/config-package.py +++ b/config/config-package.py @@ -580,7 +580,7 @@ def pyproject_toml(self): 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) + tomlkit.dump(pyproject_toml, fp, sort_keys=True) def copy_with_meta( self, template_name, destination, config_type, From a085e159b97f0e0a23eea054effb28822aa8bafa Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl Date: Mon, 2 Sep 2024 09:54:15 +0200 Subject: [PATCH 3/8] - always overwrite existing setuptools requirement spec --- config/config-package.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/config/config-package.py b/config/config-package.py index 9013741..bbeb27e 100755 --- a/config/config-package.py +++ b/config/config-package.py @@ -566,9 +566,10 @@ def pyproject_toml(self): requires = buildsystem_cfg.get('requires', []) setuptools_requirement = [ x for x in requires if x.startswith('setuptools')] - if not setuptools_requirement: - requires.append(f'setuptools{SETUPTOOLS_VERSION_SPEC}') - buildsystem_cfg['requires'] = requires + 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', '') From 04d70aaa02368ac31d8445f9176daec0143942d5 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl Date: Mon, 2 Sep 2024 12:44:27 +0200 Subject: [PATCH 4/8] - make sure to `git add` pyproject.toml as well if so desired --- config/config-package.py | 1 + 1 file changed, 1 insertion(+) diff --git a/config/config-package.py b/config/config-package.py index bbeb27e..6481c33 100755 --- a/config/config-package.py +++ b/config/config-package.py @@ -680,6 +680,7 @@ def configure(self): ".github/workflows/pre-commit.yml", ".gitignore", ".meta.toml", + "pyproject.toml", "setup.cfg", "tox.ini", ] From e46a864a01603cc53939dc7bd098a0ffee1bae2f Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl Date: Tue, 3 Sep 2024 09:53:00 +0200 Subject: [PATCH 5/8] - `git add` pyproject.toml earlier during script run --- config/config-package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config-package.py b/config/config-package.py index 6481c33..ad54aa7 100755 --- a/config/config-package.py +++ b/config/config-package.py @@ -629,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) @@ -680,7 +681,6 @@ def configure(self): ".github/workflows/pre-commit.yml", ".gitignore", ".meta.toml", - "pyproject.toml", "setup.cfg", "tox.ini", ] From d0c9c1bebcdfb2fefded435ec74bb649ad875598 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl Date: Tue, 3 Sep 2024 10:41:29 +0200 Subject: [PATCH 6/8] - rely on automatic numbered lists --- config/README.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/config/README.rst b/config/README.rst index 3018454..32b7128 100644 --- a/config/README.rst +++ b/config/README.rst @@ -111,15 +111,15 @@ The script does the following steps: 1. 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``, +1. Copy ``setup.cfg``, ``tox.ini``, ``tests.yml``, ``MANIFEST.in``, ``.readthedocs.yaml`` (if needed), and ``.gitignore`` to the repository. -3. Create or update a ``pyproject.toml`` project configuration file. -4. Remove a possibly existing ``.coveragerc`` and ``bootstrap.py``. (Coverage +1. Create or update a ``pyproject.toml`` project configuration file. +1. Remove a possibly existing ``.coveragerc`` and ``bootstrap.py``. (Coverage is now configured in ``tox.ini`` for packages which are no buildout recipes.) -5. Run the tests via: ``tox``. The ``tox`` script may be either on the current +1. 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. -6. Create a branch and a pull request. (Prevent an automatic commit of all +1. 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``.) @@ -127,9 +127,9 @@ 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 entry over there. -2. Make sure the package is activated on https://coveralls.io by trying to add +1. 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. +1. Check in possible changes in the zopefoundation/meta repository. CLI arguments @@ -696,10 +696,10 @@ The script does the following steps: 1. 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 +1. 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. +1. Call the given script with the package name and arguments for the script. .. caution:: From b54766f8f8b03bc446bb4a8e62306c9c3672e1e1 Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl Date: Tue, 3 Sep 2024 10:42:29 +0200 Subject: [PATCH 7/8] Revert "- rely on automatic numbered lists" This reverts commit d0c9c1bebcdfb2fefded435ec74bb649ad875598. --- config/README.rst | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/config/README.rst b/config/README.rst index 32b7128..3018454 100644 --- a/config/README.rst +++ b/config/README.rst @@ -111,15 +111,15 @@ The script does the following steps: 1. Add the package name to ``packages.txt`` of the selected configuration type if it is not yet added. -1. Copy ``setup.cfg``, ``tox.ini``, ``tests.yml``, ``MANIFEST.in``, +2. Copy ``setup.cfg``, ``tox.ini``, ``tests.yml``, ``MANIFEST.in``, ``.readthedocs.yaml`` (if needed), and ``.gitignore`` to the repository. -1. Create or update a ``pyproject.toml`` project configuration file. -1. Remove a possibly existing ``.coveragerc`` and ``bootstrap.py``. (Coverage +3. Create or update a ``pyproject.toml`` project configuration file. +4. Remove a possibly existing ``.coveragerc`` and ``bootstrap.py``. (Coverage is now configured in ``tox.ini`` for packages which are no buildout recipes.) -1. Run the tests via: ``tox``. The ``tox`` script may be either on the current +5. 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. -1. Create a branch and a pull request. (Prevent an automatic commit of all +6. 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``.) @@ -127,9 +127,9 @@ 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 entry over there. -1. Make sure the package is activated on https://coveralls.io by trying to add +2. Make sure the package is activated on https://coveralls.io by trying to add the repository name and making it active. -1. Check in possible changes in the zopefoundation/meta repository. +3. Check in possible changes in the zopefoundation/meta repository. CLI arguments @@ -696,10 +696,10 @@ The script does the following steps: 1. It does the following steps for each line in the given ``packages.txt`` which does not start with ``#``. -1. Check if there is a repository in ```` with the name of the +2. 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. -1. Call the given script with the package name and arguments for the script. +3. Call the given script with the package name and arguments for the script. .. caution:: From 1453d98cec9d463540111801515a8e1a3dfe062d Mon Sep 17 00:00:00 2001 From: Jens Vagelpohl Date: Tue, 3 Sep 2024 15:44:32 +0200 Subject: [PATCH 8/8] - try auto-numbering again --- config/README.rst | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/config/README.rst b/config/README.rst index 3018454..db5c579 100644 --- a/config/README.rst +++ b/config/README.rst @@ -109,27 +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. Create or update a ``pyproject.toml`` project configuration file. -4. 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.) -5. 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. -6. 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 @@ -694,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::