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

Misc. refactoring and enhancements to bootstrap_history #19

Merged
merged 9 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ dist: clean ## create and check packages
$(IN_VENV) python -m build
$(IN_VENV) twine check dist/*
ls -l dist

format: ## Format Python code base
$(IN_VENV) isort .
$(IN_VENV) black .
2 changes: 2 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
mypy
ruff
black
flake8
isort

# For release
build
Expand Down
512 changes: 280 additions & 232 deletions galaxy_release_util/bootstrap_history.py

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion galaxy_release_util/cli/options.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
import pathlib
from typing import (
Any,
Expand All @@ -15,6 +16,7 @@
"--galaxy-root",
type=click.Path(exists=True, file_okay=False, resolve_path=True, path_type=pathlib.Path),
default=".",
help="Path to galaxy root.",
)


Expand All @@ -33,5 +35,15 @@ class ClickVersion(click.ParamType):
def convert(self, value: Any, param: Optional[Parameter], ctx: Optional[Context]) -> Version:
try:
return Version(value)
except Exception as e:
except ValueError as e:
self.fail(f"{value!r} is not a valid PEP440 version number: {str(e)}", param, ctx)


class ClickDate(click.ParamType):
name = "date"

def convert(self, value: Any, param: Optional[Parameter], ctx: Optional[Context]) -> datetime.date:
try:
return datetime.datetime.strptime(value, "%Y-%m-%d").date()
except ValueError as e:
self.fail(f"{value!r} is not a valid date: {str(e)}", param, ctx)
16 changes: 15 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@ requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.black]
target-version = ['py37']
target-version = ['py38']
line-length = 120

[tool.ruff]
target-version = "py38"
line-length = 120
# Never enforce `E501`, enforced by black
lint.ignore = ["E501"]

[tool.isort]
combine_as_imports = true
force_alphabetical_sort_within_sections = true
# Override force_grid_wrap value from profile=black, but black is still happy
force_grid_wrap = 2
# Same line length as for black
line_length = 120
no_lines_before = "LOCALFOLDER"
profile = "black"
reverse_relative = true
skip_gitignore = true
src_paths = ["galaxy_release_util", "tests"]
5 changes: 3 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ classifiers =
Natural Language :: English
Operating System :: POSIX
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Topic :: Software Development
Topic :: Software Development :: Code Generators
Topic :: Software Development :: Testing
Expand All @@ -34,13 +34,14 @@ include_package_data = True
install_requires =
build
click
python-dateutil
docutils
packaging
PyGithub
requests
twine
packages = find:
python_requires = >=3.7
python_requires = >=3.8

[options.packages.find]
exclude =
Expand Down
115 changes: 115 additions & 0 deletions tests/test_bootstrap_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import os
from pathlib import Path

import pytest
from click.testing import CliRunner
from packaging.version import Version

from galaxy_release_util import bootstrap_history
from galaxy_release_util.bootstrap_history import ( # _get_release_date,
_get_next_release_version,
_get_previous_release_version,
_get_release_version_strings,
create_changelog,
)


@pytest.fixture
def release_files_dir():
return Path(".") / "tests" / "test_data"


@pytest.fixture
def release_file(release_files_dir):
with open(release_files_dir / "98.2.rst") as f:
return f.read()


@pytest.fixture
def announcement_file(release_files_dir):
with open(release_files_dir / "98.2_announce.rst") as f:
return f.read()


@pytest.fixture
def user_announcement_file(release_files_dir):
with open(release_files_dir / "98.2_announce_user.rst") as f:
return f.read()


@pytest.fixture
def next_release_announcement_file(release_files_dir):
with open(release_files_dir / "99.0_announce.rst") as f:
return f.read()


@pytest.fixture
def prs_file(release_files_dir):
with open(release_files_dir / "98.2_prs.rst") as f:
return f.read()


def test_get_previous_release_version(monkeypatch):
monkeypatch.setattr(
bootstrap_history, "_get_release_version_strings", lambda x: sorted(["22.01", "22.05", "23.0", "23.1"])
)

assert _get_previous_release_version(None, Version("15.1")) is None
assert _get_previous_release_version(None, Version("22.01")) is None
assert _get_previous_release_version(None, Version("22.05")) == Version("22.01")
assert _get_previous_release_version(None, Version("23.0")) == Version("22.05")
assert _get_previous_release_version(None, Version("23.1")) == Version("23.0")
assert _get_previous_release_version(None, Version("23.2")) == Version("23.1")
assert _get_previous_release_version(None, Version("99.99")) == Version("23.1")


def test_get_next_release_version():
assert _get_next_release_version(Version("25.0")) == Version("25.1")
assert _get_next_release_version(Version("26.1")) == Version("26.2")


def test_get_release_version_strings(monkeypatch):
filenames = [
"15.0.not_rst",
"22.01.rst",
"22.05.rst",
"23.0.rst",
"23.1.rst",
"23.not_a_release.rst",
"not_a_release.23.rst",
]
monkeypatch.setattr(bootstrap_history, "_get_release_documentation_filenames", lambda x: sorted(filenames))
assert _get_release_version_strings(None) == ["22.01", "22.05", "23.0", "23.1"]


def test_create_changelog(
monkeypatch,
release_file,
announcement_file,
user_announcement_file,
prs_file,
next_release_announcement_file,
):
monkeypatch.setattr(
bootstrap_history, "_load_prs", lambda x, y, z: None
) # We don't want to call github's API on test data.
runner = CliRunner()
with runner.isolated_filesystem():
os.makedirs("doc/source/releases")
result = runner.invoke(
create_changelog, ["98.2", "--galaxy-root", ".", "--release-date", "2099-1-15", "--next-version", "99.0"]
) # version 98.2 to be released on January 15, 2099
assert result.exit_code == 0

releases_path = Path("doc") / "source" / "releases"

with open(releases_path / "98.2.rst") as f:
assert f.read() == release_file
with open(releases_path / "98.2_announce.rst") as f:
assert f.read() == announcement_file
with open(releases_path / "98.2_announce_user.rst") as f:
assert f.read() == user_announcement_file
with open(releases_path / "98.2_prs.rst") as f:
assert f.read() == prs_file
with open(releases_path / "99.0_announce.rst") as f:
assert f.read() == next_release_announcement_file
61 changes: 61 additions & 0 deletions tests/test_data/98.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

.. to_doc

98.2
===============================

.. announce_start

Enhancements
-------------------------------

.. major_feature


.. feature

.. enhancement_tag_viz

.. enhancement_tag_datatypes

.. enhancement_tag_tools

.. enhancement_tag_workflows

.. enhancement_tag_ui

.. enhancement_tag_jobs

.. enhancement_tag_admin

.. enhancement

.. small_enhancement



Fixes
-------------------------------

.. major_bug


.. bug_tag_viz

.. bug_tag_datatypes

.. bug_tag_tools

.. bug_tag_workflows

.. bug_tag_ui

.. bug_tag_jobs

.. bug_tag_admin

.. bug


.. include:: 98.2_prs.rst

65 changes: 65 additions & 0 deletions tests/test_data/98.2_announce.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@

===========================================================
98.2 Galaxy Release (January 2099)
===========================================================

.. include:: _header.rst

Highlights
===========================================================

Feature1
--------

Feature description.

Feature2
--------

Feature description.

Feature3
--------

Feature description.

Also check out the `98.2 user release notes <98.2_announce_user.html>`__.
Are you an admin? Check out `some admin relevant PRs <https://github.com/galaxyproject/galaxy/pulls?q=label%3Ahighlight%2Fadmin+milestone%3A98.2+is%3Aclosed+is%3Apr>`__.

Get Galaxy
===========================================================

The code lives at `GitHub <https://github.com/galaxyproject/galaxy>`__ and you should have `Git <https://git-scm.com/>`__ to obtain it.

To get a new Galaxy repository run:
.. code-block:: shell

$ git clone -b release_98.2 https://github.com/galaxyproject/galaxy.git

To update an existing Galaxy repository run:
.. code-block:: shell

$ git fetch origin && git checkout release_98.2 && git pull --ff-only origin release_98.2

See the `community hub <https://galaxyproject.org/develop/source-code/>`__ for additional details on source code locations.


Administration Notes
===========================================================
Add content or drop section.

Configuration Changes
===========================================================
Add content or drop section.

Deprecation Notices
===========================================================
Add content or drop section.

Release Notes
===========================================================

.. include:: 98.2.rst
:start-after: announce_start

.. include:: _thanks.rst
Loading
Loading