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

BLD: use pyproject extras to match new ci-helpers #556

Merged
merged 6 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ jinja2<3.1
line_profiler
pytest
pytest-benchmark
pytest-cov
pytest-qt
pytest-timeout
simplejson
4 changes: 2 additions & 2 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#

# You can set these variables from the command line.
SPHINXOPTS = -W
SPHINXBUILD = python -msphinx
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = Typhos
SOURCEDIR = source
BUILDDIR = build
Expand Down
37 changes: 37 additions & 0 deletions docs/pre-release-notes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

ISSUE=$1
shift
DESCRIPTION=$*

if [[ -z "$ISSUE" || -z "$DESCRIPTION" ]]; then
echo "Usage: $0 (ISSUE NUMBER) (DESCRIPTION)"
exit 1
fi

re_issue_number='^[1-9][0-9]*$'

if ! [[ "$ISSUE" =~ $re_issue_number ]]; then
echo "Error: Issue number is not a number: $ISSUE"
echo
echo "This should preferably be the issue number that this pull request solves."
echo "We may also accept the Pull Request number in place of the issue."
exit 1
fi

echo "Issue: $ISSUE"
echo "Description: $DESCRIPTION"

FILENAME=source/upcoming_release_notes/${ISSUE}-${DESCRIPTION// /_}.rst

pushd "$(dirname "$0")" || exit 1

sed -e "s/IssueNumber Title/${ISSUE} ${DESCRIPTION}/" \
"source/upcoming_release_notes/template-short.rst" > "${FILENAME}"

if ${EDITOR} "${FILENAME}"; then
echo "Adding ${FILENAME} to the git repository..."
git add "${FILENAME}"
fi

popd || exit 0
114 changes: 114 additions & 0 deletions docs/release_notes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import sys
import time
from collections import defaultdict
from pathlib import Path

# find the pre-release directory and release notes file
THIS_DIR = Path(__file__).resolve().parent
PRE_RELEASE = THIS_DIR / 'source' / 'upcoming_release_notes'
TEMPLATE = PRE_RELEASE / 'template-short.rst'
RELEASE_NOTES = THIS_DIR / 'source' / 'release_notes.rst'

# Set up underline constants
TITLE_UNDER = '#'
RELEASE_UNDER = '='
SECTION_UNDER = '-'


def parse_pre_release_file(path):
"""
Return dict mapping of release notes section to lines.

Uses empty list when no info was entered for the section.
"""
print(f'Checking {path} for release notes.')
with path.open('r') as fd:
lines = fd.readlines()

section_dict = defaultdict(list)
prev = None
section = None

for line in lines:
if prev is not None:
if line.startswith(SECTION_UNDER * 2):
section = prev.strip()
continue
if section is not None and line[0] in ' -':
notes = section_dict[section]
if len(line) > 6:
notes.append(line)
section_dict[section] = notes
prev = line

return section_dict


def extend_release_notes(path, version, release_notes):
"""
Given dict mapping of section to lines, extend the release notes file.
"""
with path.open('r') as fd:
lines = fd.readlines()

new_lines = ['\n', '\n']
date = time.strftime('%Y-%m-%d')
release_title = f'{version} ({date})'
new_lines.append(release_title + '\n')
new_lines.append(len(release_title) * RELEASE_UNDER + '\n')
new_lines.append('\n')
for section, section_lines in release_notes.items():
if section == 'Contributors':
section_lines = sorted(list(set(section_lines)))
if len(section_lines) > 0:
new_lines.append(section + '\n')
new_lines.append(SECTION_UNDER * len(section) + '\n')
new_lines.extend(section_lines)
new_lines.append('\n')

output_lines = lines[:2] + new_lines + lines[2:]

print('Writing out release notes file')
for line in new_lines:
print(line.strip('\n'))
with path.open('w') as fd:
fd.writelines(output_lines)


def main(version_number: str):
section_notes = parse_pre_release_file(TEMPLATE)
to_delete = []
for path in PRE_RELEASE.iterdir():
if path.name[0] in '1234567890':
to_delete.append(path)
extra_notes = parse_pre_release_file(path)
for section, notes in section_notes.items():
notes.extend(extra_notes[section])
section_notes[section] = notes

extend_release_notes(RELEASE_NOTES, version_number, section_notes)

print(
"* Wrote release notes. Please perform the following manually:",
file=sys.stderr,
)
for path in to_delete:
print(f" git rm {path}", file=sys.stderr)
print(f" git add {RELEASE_NOTES}", file=sys.stderr)


if __name__ == '__main__':
if len(sys.argv) != 2:
print(f"Usage: {sys.argv[0]} VERSION_NUMBER", file=sys.stderr)
sys.exit(1)

version_number = sys.argv[1]

if not version_number.startswith("v"):
print(
f"Version number should start with 'v': {version_number}",
file=sys.stderr
)
sys.exit(1)

main(version_number)
5 changes: 2 additions & 3 deletions docs/source/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
=================
Release History
=================
Release History
###############

v2.4.1 (2023-4-4)
=================
Expand Down
8 changes: 8 additions & 0 deletions docs/source/upcoming_changes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Upcoming Changes
################

.. toctree::
:maxdepth: 1
:glob:

upcoming_release_notes/[0-9]*
23 changes: 23 additions & 0 deletions docs/source/upcoming_release_notes/556-bld_pyproj_extras.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
556 bld_pyproj_extras
#####################

API Changes
-----------
- N/A

Features
--------
- N/A

Bugfixes
--------
- N/A

Maintenance
-----------
- Add pre-release notes scripts
- Update build requirements to use pip-provided extras for documentation and test builds

Contributors
------------
- tangkong
36 changes: 36 additions & 0 deletions docs/source/upcoming_release_notes/template-full.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
IssueNumber Title
#################

Update the title above with your issue number and a 1-2 word title.
Your filename should be issuenumber-title.rst, substituting appropriately.

Make sure to fill out any section that represents changes you have made,
or replace the default bullet point with N/A.

API Changes
-----------
- List backwards-incompatible changes here.
Changes to PVs don't count as API changes for this library,
but changing method and component names or changing default behavior does.

Features
--------
- List new updates that add utility to many classes,
provide a new base classes, add options to helper methods, etc.

Bugfixes
--------
- List bug fixes that are not covered in the above sections.

Maintenance
-----------
- List anything else. The intent is to accumulate changes
that the average user does not need to worry about.

Contributors
------------
- List your github username and anyone else who made significant
code or conceptual contributions to the PR. You don't need to
add reviewers unless their suggestions lead to large rewrites.
These will be used in the release notes to give credit and to
notify you when your code is being tagged.
22 changes: 22 additions & 0 deletions docs/source/upcoming_release_notes/template-short.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
IssueNumber Title
#################

API Changes
-----------
- N/A

Features
--------
- N/A

Bugfixes
--------
- N/A

Maintenance
-----------
- N/A

Contributors
------------
- N/A
1 change: 0 additions & 1 deletion github_deploy_key_pcdshub_typhos.enc

This file was deleted.

6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ TyphosSignalPanelPlugin = "typhos.panel:TyphosSignalPanel"
HappiPlugin = "typhos.plugins:HappiPlugin"
SignalPlugin = "typhos.plugins:SignalPlugin"

[tool.pytest.ini_options]
addopts = "--cov=."

[tool.setuptools.packages.find]
where = [ ".",]
include = [ "typhos*",]
Expand All @@ -59,3 +62,6 @@ file = [ "requirements.txt",]

[tool.setuptools.dynamic.optional-dependencies.test]
file = "dev-requirements.txt"

[tool.setuptools.dynamic.optional-dependencies.doc]
file = "docs-requirements.txt"