diff --git a/update.ipynb b/update.ipynb new file mode 100644 index 0000000..8212632 --- /dev/null +++ b/update.ipynb @@ -0,0 +1,197 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "e2343c3f", + "metadata": {}, + "source": [ + "# Update script\n", + "\n", + "This script updates the vocabularies and prepares to re-release the Python package." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e8675335", + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"src/harmony/__init__.py\", \"r\", encoding=\"utf-8\") as f:\n", + " text = f.read()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a101249b", + "metadata": {}, + "outputs": [], + "source": [ + "import re" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4683dcc3", + "metadata": {}, + "outputs": [], + "source": [ + "init_py_lines = text.split(\"\\n\")\n", + "for idx, line in list(enumerate(init_py_lines)):\n", + " if \"__version__\" in line:\n", + " old_version = re.sub(r'.+= \"|\"', \"\", line)\n", + " version_bits = old_version.split(\".\")\n", + " old_version_regex = r\"\\.\".join(version_bits)\n", + " version_bits[-1] = str(int(version_bits[-1]) + 1)\n", + " new_version = \".\".join(version_bits)\n", + " init_py_lines[idx] = re.sub(old_version, new_version, line)\n", + " \n", + " print (\"Old version\", old_version)\n", + " print (\"New version\", new_version)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56e9e1a5", + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"CITATION.cff\", \"r\", encoding=\"utf-8\") as f:\n", + " text = f.read()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3f2ee0dd", + "metadata": {}, + "outputs": [], + "source": [ + "citation_lines = text.split(\"\\n\")\n", + "for idx, line in list(enumerate(citation_lines)):\n", + " if line.startswith(\"version:\"):\n", + " citation_lines[idx] = re.sub(old_version_regex, new_version, line)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "34ec6596", + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"README.md\", \"r\", encoding=\"utf-8\") as f:\n", + " text = f.read()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "976202e1", + "metadata": {}, + "outputs": [], + "source": [ + "readme_lines = text.split(\"\\n\")\n", + "for idx, line in list(enumerate(readme_lines)):\n", + " if \"Version \" in line:\n", + " readme_lines[idx] = re.sub(\"Version \" + old_version_regex, \"Version \" + new_version, line)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4584b9c2", + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"src/harmony/__init__.py\", \"w\", encoding=\"utf-8\") as f:\n", + " f.write(\"\\n\".join(init_py_lines))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "23462417", + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"CITATION.cff\", \"w\", encoding=\"utf-8\") as f:\n", + " f.write(\"\\n\".join(citation_lines))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "29981793", + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"README.md\", \"w\", encoding=\"utf-8\") as f:\n", + " f.write(\"\\n\".join(readme_lines))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6a84d0aa", + "metadata": {}, + "outputs": [], + "source": [ + "!git add src/harmony/__init__.py\n", + "!git add CITATION.cff README.md" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1788b012", + "metadata": {}, + "outputs": [], + "source": [ + "!git commit -m \"Update version\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1ffccaef", + "metadata": {}, + "outputs": [], + "source": [ + "!git push" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e0feb82c", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}