Skip to content

Commit

Permalink
Merge pull request #415 from elisallenens/master
Browse files Browse the repository at this point in the history
Add support for pyproject.toml
  • Loading branch information
reinout committed Jul 12, 2023
2 parents 9ae9b79 + 7f20a28 commit ac641d7
Show file tree
Hide file tree
Showing 24 changed files with 401 additions and 293 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Changelog for zest.releaser
8.0.1 (unreleased)
------------------

- Nothing changed yet.
- Changed build system to pypa/build instead of explicitly using setuptools.

- Zest.releaser's settings can now also be placed in ``pyproject.toml``.


8.0.0 (2023-05-05)
Expand Down
7 changes: 4 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ of ``zest.releaser`` users:

- wheel_ for creating a Python wheel that we upload to PyPI next to
the standard source distribution. Wheels are the new Python package
format. Create or edit ``setup.cfg`` in your project (or globally
in your ``~/.pypirc``) and create a section ``[zest.releaser]`` with
``create-wheel = yes`` to create a wheel to upload to PyPI. See
format. Create or edit ``setup.cfg`` or ``pyproject.toml`` in your
project (or globally in your ``~/.pypirc``) and create a section
``[zest.releaser]`` (``[tool.zest-releaser]`` in ``pyproject.toml``)
with ``create-wheel = true`` to create a wheel to upload to PyPI. See
http://pythonwheels.com for deciding whether this is a good idea for
your package. Briefly, if it is a pure Python 2 *or* pure Python 3
package: just do it. If it is a pure Python 2 *and* a pure Python 3
Expand Down
19 changes: 11 additions & 8 deletions doc/source/assumptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ are some assumptions built-in that might or might not fit you. Lots of people
are using it in various companies and open source projects, so it'll probably
fit :-)

- We absolutely need a version. There's a ``version.txt`` or ``setup.py`` in
your project. The ``version.txt`` has a single line with the version number
(newline optional). The ``setup.py`` should have a single ``version =
'0.3'`` line somewhere. You can also have it in the actual ``setup()`` call,
on its own line still, as `` version = '0.3',``. Indentation and comma are
preserved. If your ``setup.py`` actually reads the version from your
``setup.cfg`` (as `it does automatically
- We absolutely need a version. There's a ``version.txt``, ``setup.py``, or
``pyproject.toml`` in your project. The ``version.txt`` has a single line
with the version number (newline optional). The ``setup.py`` should have a
single ``version = '0.3'`` line somewhere. You can also have it in the
actual ``setup()`` call, on its own line still, as `` version = '0.3',``.
Indentation and comma are preserved. If your ``setup.py`` actually reads
the version from your ``setup.cfg`` (as `it does automatically
<https://setuptools.readthedocs.io/en/latest/setuptools.html#configuring-
setup-using-setup-cfg-files>`_ using ``setuptools`` since version 30.3.0),
then the version will be modified there too. If you need something special,
you can always do a ``version=version`` and put the actual version statement
in a zest.releaser- friendly format near the top of the file. Reading (in
Plone products) a version.txt into setup.py works great, too.
Plone products) a version.txt into setup.py works great, too. If you use
``pyproject.toml``, you should put the version under the ``project``
metadata section, which also contains the package name, as a single line like
``version = "0.3"``.

- The history/changes file restriction is probably the most severe at the
moment. zest.releaser searches for a restructuredtext header with
Expand Down
13 changes: 0 additions & 13 deletions doc/source/developing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,6 @@ In the past, ``git`` commands would give slightly different output.
If the output of a command changes again, we may need extra compatibility code in ``test_setup.py``


Setuptools is needed
--------------------

You also need ``setuptools`` in your system path. This is because
we basically call 'sys.executable setup.py egg_info' directly (in the tests
and in the actual code), which will give an import error on setuptools
otherwise. There is a branch with a hack that solves this but it sounds too
hacky.

TODO: calling ``setup.py`` from the command line is not recommended anymore.
We should upgrade the code to no longer do that.


Building the documentation locally
-------------------------------------

Expand Down
14 changes: 14 additions & 0 deletions doc/source/entrypoints.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ An entry point is configured like this in your setup.py::
'dosomething = my.package.some:some_entrypoint',
]},

or like this in your pyproject.toml::

[project.entry-points."zest.releaser.prereleaser.middle"]
dosomething = "my.package.some:some_entrypoint"

Entry-points can also be specified in the setup.cfg file like this
(The options will be split by white-space and processed in the given
order.)::
Expand All @@ -84,6 +89,15 @@ and ``middle`` with the respective hook name (`before`, `middle`, `after`,
`after_checkout`, etc.)
as needed.

Similarly, they can also be placed in the ``tool.zest-releaser`` config section of
pyproject.toml like this::

[tool.zest-releaser]
prereleaser.middle = [
"my.package.some.some_entrypoint",
"our.package.other_module.other_function"
]

See the ``setup.py`` of ``zest.releaser`` itself for some real world examples.

You'll have to make sure that the zest.releaser scripts know about your entry
Expand Down
47 changes: 29 additions & 18 deletions doc/source/options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Lots of things may be in this file, but zest.releaser looks for a
[zest.releaser]
some-option = some value

For yes/no options, you can use no/false/off/0 or yes/true/on/1 as
For true/false options, you can use no/false/off/0 or yes/true/on/1 as
answers; upper, lower or mixed case are all fine.

Various options change the default answer of a question.
Expand All @@ -78,42 +78,42 @@ see if you can tweak the default answers by setting one of these options

We have these options:

release = yes / no
Default: yes. When this is false, zest.releaser sets ``no`` as
release = true / false
Default: true. When this is false, zest.releaser sets ``false`` as
default answer for the question if you want to create a checkout
of the tag.

create-wheel = yes / no
Default: no. Set to yes if you want zest.releaser to create
create-wheel = true / false
Default: false. Set to true if you want zest.releaser to create
Python wheels. You need to install the ``wheel`` package for this
to work.

If the package is a universal wheel, indicated by having
``universal = 1`` in the ``[bdist_wheel]`` section of
``setup.cfg``, then the default for this value is yes.
``setup.cfg``, then the default for this value is true.

extra-message = [ci skip]
Extra message to add to each commit (prerelease, postrelease).

prefix-message = [TAG]
Prefix message to add at the beginning of each commit (prerelease, postrelease).

no-input = yes / no
Default: no. Set this to yes to accept default answers for all
no-input = true / false
Default: false. Set this to true to accept default answers for all
questions.

register = yes / no
Default: no. Set this to yes to register a package before uploading.
register = true / false
Default: false. Set this to true to register a package before uploading.
On the official Python Package Index registering a package is no longer needed,
and may even fail.

push-changes = yes / no
Default: yes. When this is false, zest.releaser sets ``no`` as
push-changes = true / false
Default: true. When this is false, zest.releaser sets ``false`` as
default answer for the question if you want to push the changes to
the remote.

less-zeroes = yes / no
Default: no.
less-zeroes = true / false
Default: false.
This influences the version suggested by the bumpversion command.
When set to true:

Expand Down Expand Up @@ -153,8 +153,8 @@ tag-message = a string
command of the VCS.
It must contain ``{version}``.

tag-signing = yes / no
Default: no.
tag-signing = true / false
Default: false.
When set to true, tags are signed using the signing feature of the
respective vcs. Currently tag-signing is only supported for git.
Note: When you enable it, everyone releasing the project is
Expand Down Expand Up @@ -183,8 +183,8 @@ history_format = a string
Default: empty.
Set this to ``md`` to handle changelog entries in Markdown.

run-pre-commit = yes / no
Default: no.
run-pre-commit = true / false
Default: false.
New in version 7.3.0.
When set to true, pre commit hooks are run.
This may interfere with releasing when they fail.
Expand All @@ -199,3 +199,14 @@ Python package.

These are the same options as the global ones. If you set an option
locally in a project, this will override the global option.

You can also set these options in a ``pyproject.toml`` file. If you do
so, instead of having a ``[zest.releaser]`` section, you should use a
``[tool.zest-releaser]`` section. For true/false options in a
``pyproject.toml``, you must use lowercase true or false; for string
options like ``extra-message`` or ``prefix-message``, you should put
the value between double quotes, like this::

[tool.zest-releaser]
create-wheel = true
extra-message = "[ci skip]"
8 changes: 7 additions & 1 deletion doc/source/versions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,15 @@ A version number can come from various different locations:

[zest.releaser]
python-file-with-version = mypackage/__init__.py
Alternatively, in ``pyproject.toml``, you can use the following::

[tool.zest-releaser]
python-file-with-version = "mypackage/__init__.py"

Because you need to configure this explicitly, this option takes precedence
over any ``setup.py`` or ``version.txt`` file.
over any ``setup.py``, ``setup.cfg`` or ``pyproject.toml`` package version,
or ``version.txt`` file.


Where is the version number being set?
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ dependencies = [
"colorama",
"requests",
"twine >= 1.6.0",
"build >= 0.6.0.post1", # 0.6.0 wasn't compatible with Python 3.7
"tomli; python_version<'3.11'",
"setuptools >= 61.0.0", # older versions can't read pyproject.toml configurations
]
requires-python = ">=3.7"
classifiers = [
Expand Down
23 changes: 12 additions & 11 deletions zest/releaser/baserelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,17 @@ def __init__(self, vcs=None):
"zest.releaser.tests", "pypirc_old.txt"
)
self.pypiconfig = pypi.PypiConfig(pypirc_old)
self.zest_releaser_config = pypi.ZestReleaserConfig(pypirc_config_filename=pypirc_old)
else:
self.pypiconfig = pypi.PypiConfig()
if self.pypiconfig.no_input():
self.zest_releaser_config = pypi.ZestReleaserConfig()
if self.zest_releaser_config.no_input():
utils.AUTO_RESPONSE = True

@property
def history_format(self):
default = "rst"
config_value = self.pypiconfig.history_format()
config_value = self.zest_releaser_config.history_format()
history_file = self.data.get("history_file") or ""
return utils.history_format(config_value, history_file)

Expand Down Expand Up @@ -124,8 +126,8 @@ def _grab_history(self):
self.data["headings"] = []
self.data["history_last_release"] = ""
self.data["history_insert_line_here"] = 0
default_location = self.pypiconfig.history_file()
fallback_encoding = self.pypiconfig.encoding()
default_location = self.zest_releaser_config.history_file()
fallback_encoding = self.zest_releaser_config.encoding()
history_file = self.vcs.history_file(location=default_location)
self.data["history_file"] = history_file
if not history_file:
Expand Down Expand Up @@ -277,10 +279,9 @@ def _insert_changelog_entry(self, message):
"the existing file. This might give problems.",
orig_encoding,
)
config = self.setup_cfg.config
fallback_encodings = []
if config.has_option("zest.releaser", "encoding"):
encoding = config.get("zest.releaser", "encoding")
if "encoding" in self.zest_releaser_config:
encoding = self.zest_releaser_config["encoding"]
if encoding != orig_encoding:
fallback_encodings.append(encoding)
encoding = "utf-8"
Expand Down Expand Up @@ -416,15 +417,15 @@ def _push(self):
push_cmds = self.vcs.push_commands()
if not push_cmds:
return
default_anwer = self.pypiconfig.push_changes()
default_anwer = self.zest_releaser_config.push_changes()
if utils.ask("OK to push commits to the server?", default=default_anwer):
for push_cmd in push_cmds:
output = execute_command(push_cmd)
logger.info(output)

def _run_hooks(self, when):
which_releaser = self.__class__.__name__.lower()
utils.run_hooks(self.setup_cfg, which_releaser, when, self.data)
utils.run_hooks(self.zest_releaser_config, which_releaser, when, self.data)

def run(self):
self._run_hooks("before")
Expand All @@ -440,8 +441,8 @@ def execute(self):
raise NotImplementedError()

def update_commit_message(self, msg):
prefix_message = self.pypiconfig.prefix_message()
extra_message = self.pypiconfig.extra_message()
prefix_message = self.zest_releaser_config.prefix_message()
extra_message = self.zest_releaser_config.extra_message()
if prefix_message:
msg = "%s %s" % (prefix_message, msg)
if extra_message:
Expand Down
6 changes: 3 additions & 3 deletions zest/releaser/bumpversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ def _grab_version(self, initial=False):
feature=feature,
breaking=breaking,
final=final,
less_zeroes=self.pypiconfig.less_zeroes(),
levels=self.pypiconfig.version_levels(),
dev_marker=self.pypiconfig.development_marker(),
less_zeroes=self.zest_releaser_config.less_zeroes(),
levels=self.zest_releaser_config.version_levels(),
dev_marker=self.zest_releaser_config.development_marker(),
)
if final:
minimum_version = utils.suggest_version(original_version, **params)
Expand Down
6 changes: 3 additions & 3 deletions zest/releaser/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def is_setuptools_helper_package_installed(self):

@property
def name(self):
package_name = self.get_setup_py_name()
package_name = self._extract_name()
if package_name:
return package_name
# No setup.py? With git we can probably only fall back to the directory
# No python package name? With git we can probably only fall back to the directory
# name as there's no svn-url with a usable name in it.
dir_name = os.path.basename(os.getcwd())
dir_name = fs_to_text(dir_name)
Expand Down Expand Up @@ -68,7 +68,7 @@ def cmd_diff(self):

def cmd_commit(self, message):
parts = ["git", "commit", "-a", "-m", message]
if not self.pypi_cfg.run_pre_commit():
if not self.zest_releaser_config.run_pre_commit():
parts.append("-n")
return parts

Expand Down
8 changes: 4 additions & 4 deletions zest/releaser/postrelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, vcs=None, breaking=False, feature=False, final=False):
feature=feature,
final=final,
dev_version_template=DEV_VERSION_TEMPLATE,
development_marker=self.pypiconfig.development_marker(),
development_marker=self.zest_releaser_config.development_marker(),
history_header=HISTORY_HEADER,
update_history=True,
)
Expand Down Expand Up @@ -82,9 +82,9 @@ def _ask_for_new_dev_version(self):
breaking=self.data["breaking"],
feature=self.data["feature"],
final=self.data["final"],
less_zeroes=self.pypiconfig.less_zeroes(),
levels=self.pypiconfig.version_levels(),
dev_marker=self.pypiconfig.development_marker(),
less_zeroes=self.zest_releaser_config.less_zeroes(),
levels=self.zest_releaser_config.version_levels(),
dev_marker=self.zest_releaser_config.development_marker(),
)
suggestion = utils.suggest_version(current, **params)
print("Current version is %s" % current)
Expand Down
2 changes: 1 addition & 1 deletion zest/releaser/prerelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Prereleaser(baserelease.Basereleaser):
def __init__(self, vcs=None):
baserelease.Basereleaser.__init__(self, vcs=vcs)
# Prepare some defaults for potential overriding.
date_format = self.pypiconfig.date_format()
date_format = self.zest_releaser_config.date_format()
self.data.update(
dict(
commit_msg=PRERELEASE_COMMIT_MSG,
Expand Down
Loading

0 comments on commit ac641d7

Please sign in to comment.