From ffc539715ca1c09a86e045fcac3be9b652e007f4 Mon Sep 17 00:00:00 2001 From: aeturrell Date: Thu, 2 Jan 2025 19:27:34 +0000 Subject: [PATCH] splitting into test and release workflows --- .github/workflows/release.yml | 111 +++++++++++++++++++++ .github/workflows/{build.yml => tests.yml} | 26 +++-- README.md | 2 + _config.yml | 1 + auto-research-outputs.md | 4 + environment.yml | 1 + pyproject.toml | 11 ++ version_bumper.py | 45 +++++++++ 8 files changed, 187 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/release.yml rename .github/workflows/{build.yml => tests.yml} (77%) create mode 100644 pyproject.toml create mode 100644 version_bumper.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..6dcef53 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,111 @@ +name: release + +permissions: + contents: write + pages: write + +on: + push: + branches: + - main + +jobs: + release: + name: release + runs-on: ubuntu-latest + steps: + - name: Check out the repository + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: install mamba + uses: mamba-org/setup-micromamba@v2 + with: + environment-file: environment.yml + init-shell: >- + bash + cache-environment: true + post-cleanup: 'all' + + - name: set timezone + run: | + TZ="Europe/London" && + sudo ln -snf /usr/share/zoneinfo/$TZ /etc/localtime + + - name: install linux deps + run: | + sudo apt-get -y install openssl graphviz nano texlive graphviz-dev unzip + + - name: install special fonts + run: | + mkdir -p /usr/share/fonts/truetype/ && + wget https://www.wfonts.com/download/data/2015/10/08/varta/varta.zip && + unzip varta.zip && + install -m644 *.ttf /usr/share/fonts/truetype/ && + rm *.ttf + rm varta.zip + + - name: install text models + run: | + micromamba run -n codeforecon python3 -m spacy download en_core_web_sm && + micromamba run -n codeforecon python3 -m nltk.downloader all + + - name: special fix for todoify + run: | + sed -i '90 s/^/#/' /home/runner/micromamba/envs/codeforecon/lib/python3.10/site-packages/mdit_py_plugins/tasklists/__init__.py + + # Issue with pymc needing np<2.0 and skimpy needing >2.0, so pip install of latter causes upgrade to np + - name: special fix for numpy + run: | + micromamba run -n codeforecon pip install --force-reinstall -v "numpy==1.26" + + - name: Monkey patch for binsreg # sets np.math = math + run: | + sed -i '/^import\|^from.*import/ { :a; n; /^import\|^from.*import/! { x; s/.*//; x; ba; }; }; a\import math\nimport numpy as np\nnp.math = math' ~/micromamba/envs/codeforecon/lib/python3.10/site-packages/binsreg/funs.py + + - name: git config # Needed as git config --get user.name is used in one example + run: | + git config user.name "$(git log -n 1 --pretty=format:%an)" && + git config user.email "$(git log -n 1 --pretty=format:%ae)" + + - name: build the book + run: | + micromamba run -n codeforecon jupyter-book build . --verbose + + - name: Check if there is a parent commit + id: check-parent-commit + run: | + echo "::set-output name=sha::$(git rev-parse --verify --quiet HEAD^)" + + - name: Detect and tag new version + id: check-version + if: steps.check-parent-commit.outputs.sha + uses: salsify/action-detect-and-tag-new-version@v2.0.3 + with: + version-command: | + micromamba run -n codeforecon toml get --toml-path=pyproject.toml project.version + + - name: Bump version for developmental release + if: "! steps.check-version.outputs.tag" + run: | + micromamba run -n codeforecon python version_bumper.py && + version=$(micromamba run -n codeforecon toml get --toml-path=pyproject.toml project.version) && + micromamba run -n codeforecon toml set --toml-path=pyproject.toml project.version $version.dev.$(date +%s) + + - name: Publish + if: steps.check-version.outputs.tag + run: ghp-import -n -p -f _build/html + + - name: Publish the release notes + uses: release-drafter/release-drafter@v6.0.0 + with: + publish: ${{ steps.check-version.outputs.tag != '' }} + tag: ${{ steps.check-version.outputs.tag }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Success + if: steps.check-version.outputs.tag + run: | + echo "Success in releasing a new version of Coding for Economists!" diff --git a/.github/workflows/build.yml b/.github/workflows/tests.yml similarity index 77% rename from .github/workflows/build.yml rename to .github/workflows/tests.yml index 122bec7..9d7f4ae 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/tests.yml @@ -1,18 +1,19 @@ -name: build - -# permissions: -# contents: write -# pages: write +name: tests on: - push: - branches: - - build-book-action - + pull_request: jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.10.6' + - uses: pre-commit/action@v3.0.1 + build: - name: build runs-on: ubuntu-latest steps: - name: Check out the repository @@ -60,9 +61,6 @@ jobs: - name: special fix for numpy run: | micromamba run -n codeforecon pip install --force-reinstall -v "numpy==1.26" - # sed -i 's/if np\.obj2sctype(dtype) is None:/if np.dtype(dtype).type is None:/' ~/micromamba/envs/codeforecon/lib/python3.10/site-packages/pytensor/tensor/type.py && - # sed -i 's/from numpy import e, euler_gamma, inf, infty, nan, newaxis, pi/from numpy import e, euler_gamma, inf, nan, newaxis, pi/' ~/micromamba/envs/codeforecon/lib/python3.10/site-packages/pytensor/tensor/__init__.py && - # sed -i 's/infty/inf/g' ~/micromamba/envs/codeforecon/lib/python3.10/site-packages/pytensor/tensor/__init__.py - name: Monkey patch for binsreg # sets np.math = math run: | @@ -79,4 +77,4 @@ jobs: - name: success run: | - echo "success!" + echo "Success in building book without errors!" diff --git a/README.md b/README.md index 638d4a4..265a788 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ To read or use the book, head to the [*Coding for Economists* website](https://a The rest of this readme is intended to help those who are contributing to the book, rather than readers. +Note that there is a custom, non-compliant `pyproject.toml` file included in this project. Its main purpose is to provide the version of the book, and the version of Python. + ## Dev These instructions are only for developers working on the book. diff --git a/_config.yml b/_config.yml index e13165c..34ab07a 100644 --- a/_config.yml +++ b/_config.yml @@ -56,3 +56,4 @@ sphinx: bibtex_reference_style: author_year suppress_warnings: ["mystnb.unknown_mime_type"] nb_execution_show_tb: true + nb_execution_raise_on_error: true # Make build fail any content errors (don't want to publish if errors) diff --git a/auto-research-outputs.md b/auto-research-outputs.md index d8ce35d..2d29968 100644 --- a/auto-research-outputs.md +++ b/auto-research-outputs.md @@ -15,6 +15,10 @@ kernelspec: (auto-research-outputs)= # Automating Research Outputs +```{code-cell} ipython3 +print(errrywerror) +``` + In this chapter, you'll learn how to automate the inclusion of figures and tables in LaTeX-derived research outputs including PDFs and slides——plus how to convert those outputs to Microsoft Word documents and more. Much of what you'll see in this chapter applies to a wide range of coding languages. This chapter has some similarities with another chapter, on {ref}`quarto`. But this chapter puts the LaTeX typesetting language front and centre, because it's the *de facto* standard for preparing *research outputs* (most journals have a LaTeX template for submission, for example), and it gives you full control over every aspect of how your outputs look. However, if you don't already know LaTeX, there is a steep-ish learning curve and—if you're just looking to create some automated reports using code and text rather than write pre-prints, working papers, journal articles, or academic-talk style slide decks—the chapter on {ref}`quarto` is going to be a better and easier fit for you. diff --git a/environment.yml b/environment.yml index cb1435b..00f20d5 100644 --- a/environment.yml +++ b/environment.yml @@ -78,3 +78,4 @@ dependencies: - pyfixest>=0.17.0 - watermark - ydata_profiling + - toml-cli diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..e9da1a9 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,11 @@ +[project] +name = "Coding for Economists" +version = "1.0.2" +description = "A guide for economists on what programming is, why it's useful, and how to do it." +authors = [{name="Arthur Turrell", email="None@none.com"}] +readme = "README.md" +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Programming Language :: Python :: 3.10", +] +requires-python = "==3.10.16" diff --git a/version_bumper.py b/version_bumper.py new file mode 100644 index 0000000..66c3646 --- /dev/null +++ b/version_bumper.py @@ -0,0 +1,45 @@ +import subprocess +from typing import Literal + +import toml + + +def bump_version(part: Literal["major", "minor", "patch"] = "patch") -> None: + file_path = "pyproject.toml" + + with open(file_path, "r") as f: + pyproject = toml.load(f) + + version = pyproject["project"]["version"] + major, minor, patch = map(int, version.split(".")) + + if part == "major": + major += 1 + minor = 0 + patch = 0 + elif part == "minor": + minor += 1 + patch = 0 + elif part == "patch": + patch += 1 + else: + raise ValueError("Invalid part value. Choose 'major', 'minor', or 'patch'.") + + new_version = f"{major}.{minor}.{patch}" + subprocess.run( + [ + "uvx", + "--from=toml-cli", + "toml", + "set", + "--toml-path=pyproject.toml", + "project.version", + new_version, + ] + ) + + print(f"Version bumped to {major}.{minor}.{patch}") + + +if __name__ == "__main__": + bump_version()