Skip to content
Snippets Groups Projects
Commit d4cbe4cb authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

Merge branch 'issue-4' into 'main'

Improves dependence pinning on release with a specific flag

Closes #4

See merge request !9
parents 99737938 10c86f39
No related branches found
No related tags found
1 merge request!9Improves dependence pinning on release with a specific flag
Pipeline #75052 passed
# Copyright © 2022 Idiap Research Institute <contact@idiap.ch> # SPDX-FileCopyrightText: Copyright © 2022 Idiap Research Institute <contact@idiap.ch>
# #
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
include: include:
- project: software/dev-profile - project: software/dev-profile
file: /gitlab/python.yml file: /gitlab/python+rtd.yml
documentation:
image: quay.io/condaforge/linux-anvil-cos7-x86_64
before_script:
- rm -f /home/conda/.condarc
- mamba update --override-channels -c conda-forge -n base --all
- eval "$(/opt/conda/bin/conda shell.bash hook)"
- conda activate base
- pip install --pre --index-url https://gitlab.idiap.ch/api/v4/groups/software/-/packages/pypi/simple --extra-index-url https://pypi.org/simple '.[doc]' sphinx
...@@ -41,6 +41,7 @@ requirements: ...@@ -41,6 +41,7 @@ requirements:
- gitpython - gitpython
- python-gitlab - python-gitlab
- python-dateutil - python-dateutil
- pytz
- setuptools - setuptools
- xdg - xdg
......
...@@ -31,6 +31,7 @@ dependencies = [ ...@@ -31,6 +31,7 @@ dependencies = [
"packaging", "packaging",
"python-dateutil", "python-dateutil",
"python-gitlab", "python-gitlab",
"pytz",
"pyyaml", "pyyaml",
"setuptools", "setuptools",
"tomli", "tomli",
......
...@@ -9,7 +9,7 @@ import typing ...@@ -9,7 +9,7 @@ import typing
import click import click
from idiap_devtools.click import validate_profile from idiap_devtools.click import validate_profile
from idiap_devtools.profile import Profile from idiap_devtools.profile import Profile, get_profile_path
from ...click import PreserveIndentCommand, verbosity_option from ...click import PreserveIndentCommand, verbosity_option
from ...logging import setup from ...logging import setup
...@@ -26,7 +26,7 @@ Examples: ...@@ -26,7 +26,7 @@ Examples:
.. code:: sh .. code:: sh
devtool gitlab release --profile=default -vv changelog.md devtool gitlab release -vv changelog.md
.. tip:: .. tip::
...@@ -38,7 +38,21 @@ Examples: ...@@ -38,7 +38,21 @@ Examples:
.. code:: sh .. code:: sh
devtool gitlab release --profile=default -vv --dry-run changelog.md devtool gitlab release -vv --dry-run changelog.md
3. You may also pin package dependencies upon the release, so that the
shipped package respects a particular development profile set of pins:
.. code:: sh
devtool gitlab release -vv --pin-dependencies changelog.md
The `default` profile is used, if set on your configuration file.
Otherwise, you may specify it explicitly like:
.. code:: sh
devtool gitlab release -vv --profile=specific --pin-dependencies changelog.md
""", """,
) )
...@@ -46,12 +60,21 @@ Examples: ...@@ -46,12 +60,21 @@ Examples:
@click.option( @click.option(
"-P", "-P",
"--profile", "--profile",
default=None, default="default",
show_default=True, show_default=True,
callback=validate_profile,
help="Directory containing the development profile (and a file named " help="Directory containing the development profile (and a file named "
"profile.toml), or the name of a configuration key pointing to the " "profile.toml), or the name of a configuration key pointing to the "
"development profile to use", "development profile to use",
) )
@click.option(
"-p",
"--pin-dependencies/--no-pin-dependencies",
default=False,
help="If set, then pin dependencies from the dev-profile on the package "
"to be released. By default your default dev-profile is used. You may "
"override this using the --profile option",
)
@click.option( @click.option(
"-d", "-d",
"--dry-run/--no-dry-run", "--dry-run/--no-dry-run",
...@@ -63,8 +86,9 @@ Examples: ...@@ -63,8 +86,9 @@ Examples:
@verbosity_option(logger=logger) @verbosity_option(logger=logger)
def release( def release(
changelog: typing.TextIO, changelog: typing.TextIO,
dry_run: bool,
profile: str, profile: str,
pin_dependencies: bool,
dry_run: bool,
**_, **_,
) -> None: ) -> None:
"""Tags packages on GitLab from an input CHANGELOG in markdown format. """Tags packages on GitLab from an input CHANGELOG in markdown format.
...@@ -74,7 +98,8 @@ def release( ...@@ -74,7 +98,8 @@ def release(
in order): in order):
* Modifies ``pyproject.toml`` with the new release number and pins the * Modifies ``pyproject.toml`` with the new release number and pins the
dependencies according to the specified profile's constraints dependencies according to the specified profile's constraints (if one
was specified)
* Sets-up the README links to point to the correct pipeline and * Sets-up the README links to point to the correct pipeline and
documentation for the package documentation for the package
* Commits, tags and pushes the git project adding the changelog * Commits, tags and pushes the git project adding the changelog
...@@ -85,8 +110,10 @@ def release( ...@@ -85,8 +110,10 @@ def release(
pipeline versions pipeline versions
* Re-commits and pushes the whole with the option ``[ci skip]``. * Re-commits and pushes the whole with the option ``[ci skip]``.
When a dev-profile is given (with ``--profile``), the versions of the dependencies N.B.: When the option ``pin-dependencies`` is set, the versions of the
in ``pyproject.toml`` will be pinned to those of the ``constraints.txt`` file. dependencies in ``pyproject.toml`` will be pinned to those of the Python
``constraints.txt`` file available in the select development profile
(choose using option ``--profile``).
The changelog is expected to have the following structure: The changelog is expected to have the following structure:
...@@ -128,18 +155,6 @@ def release( ...@@ -128,18 +155,6 @@ def release(
gl = get_gitlab_instance() gl = get_gitlab_instance()
if profile is None:
logger.warning(
"No dev-profile given. There will be no dependencies version pinning. "
"To enable pinning, set the --profile option."
)
else:
profile = validate_profile(None, None, profile)
logger.info(
"Loading profile '%s' for dependencies version pinning.", profile
)
loaded_profile = Profile(profile)
# traverse all packages in the changelog, edit older tags with updated # traverse all packages in the changelog, edit older tags with updated
# comments, tag them with a suggested version, then try to release, and # comments, tag them with a suggested version, then try to release, and
# wait until done to proceed to the next package # wait until done to proceed to the next package
...@@ -155,9 +170,22 @@ def release( ...@@ -155,9 +170,22 @@ def release(
] ]
if dry_run: if dry_run:
click.secho("!!!! DRY RUN MODE !!!!", fg="yellow", bold=True)
click.secho( click.secho(
"No changes will be committed to GitLab.", fg="yellow", bold=True "DRY RUN MODE: No changes will be committed to GitLab.",
fg="yellow",
bold=True,
)
# loads profile data
if pin_dependencies:
the_profile = Profile(profile)
logger.info(
f"Pinning dependencies from profile `{get_profile_path(profile)}'...",
)
else:
the_profile = None
logger.warning(
"Not pinning dependencies (use --pin-dependencies to change this).",
) )
for pkg_number, (header, line) in enumerate(pkgs): for pkg_number, (header, line) in enumerate(pkgs):
...@@ -223,7 +251,7 @@ def release( ...@@ -223,7 +251,7 @@ def release(
tag_name=vtag, tag_name=vtag,
tag_comments=description_text, tag_comments=description_text,
dry_run=dry_run, dry_run=dry_run,
profile=loaded_profile, profile=the_profile,
) )
if not dry_run: if not dry_run:
# now, wait for the pipeline to finish, before we can release the # now, wait for the pipeline to finish, before we can release the
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment