From bf6fbc9878d8105806a9508162dfe5a583f66a50 Mon Sep 17 00:00:00 2001 From: Jose Storopoli Date: Mon, 27 Nov 2023 06:37:09 -0300 Subject: [PATCH] feat(flake): add nix-pre-commit checks with typos --- .github/workflows/build-slides.yml | 11 +- .github/workflows/release-slides.yml | 11 +- .github/workflows/update_flake_lock.yml | 21 +++ .gitignore | 1 + README.md | 4 +- _typos.toml | 11 ++ flake.lock | 186 ++++++++++++++++++++++++ flake.nix | 65 +++++++++ slides/02-Statistical_Distributions.tex | 2 +- slides/10-Hierarchical_Models.tex | 4 +- slides/12-Model_Comparison.tex | 2 +- slides/flake.lock | 127 +++++++++++++++- slides/flake.nix | 31 ++-- 13 files changed, 446 insertions(+), 30 deletions(-) create mode 100644 .github/workflows/update_flake_lock.yml create mode 100644 _typos.toml create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.github/workflows/build-slides.yml b/.github/workflows/build-slides.yml index 3813672..f83d4b5 100644 --- a/.github/workflows/build-slides.yml +++ b/.github/workflows/build-slides.yml @@ -15,12 +15,6 @@ jobs: runs-on: ubuntu-latest permissions: contents: write - env: - working-directory: ./slides - defaults: - run: - working-directory: ${{ env.working-directory }} - steps: - name: Checkout repository uses: actions/checkout@v4 @@ -31,6 +25,9 @@ jobs: - name: Cache Nix artifacts uses: DeterminateSystems/magic-nix-cache-action@v2 + - name: Nix Flake Check + run: nix flake check -L + - name: Build Slides run: nix build -L @@ -41,5 +38,5 @@ jobs: uses: actions/upload-artifact@v3 with: name: output - path: ./slides/slides.pdf + path: ./slides.pdf if-no-files-found: error diff --git a/.github/workflows/release-slides.yml b/.github/workflows/release-slides.yml index 5cb71fd..b8b1378 100644 --- a/.github/workflows/release-slides.yml +++ b/.github/workflows/release-slides.yml @@ -11,12 +11,6 @@ jobs: runs-on: ubuntu-latest permissions: contents: write - env: - working-directory: ./slides - defaults: - run: - working-directory: ${{ env.working-directory }} - steps: - name: Checkout repository uses: actions/checkout@v4 @@ -27,6 +21,9 @@ jobs: - name: Cache Nix artifacts uses: DeterminateSystems/magic-nix-cache-action@v2 + - name: Nix Flake Check + run: nix flake check -L + - name: Build Slides run: nix build -L @@ -37,4 +34,4 @@ jobs: uses: ncipollo/release-action@v1 id: release with: - artifacts: ./slides/slides.pdf + artifacts: ./slides.pdf diff --git a/.github/workflows/update_flake_lock.yml b/.github/workflows/update_flake_lock.yml new file mode 100644 index 0000000..95d26b3 --- /dev/null +++ b/.github/workflows/update_flake_lock.yml @@ -0,0 +1,21 @@ +name: Update Flake Lock File +on: + workflow_dispatch: # allows manual triggering + schedule: + - cron: '0 0 * * 0' # runs weekly on Sunday at 00:00 + +jobs: + lockfile: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Nix + uses: DeterminateSystems/nix-installer-action@v7 + - name: Update flake.lock + uses: DeterminateSystems/update-flake-lock@v20 + with: + pr-title: "fix: update flake.lock" # Title of PR to be created + pr-labels: | # Labels to be set on the PR + dependencies + automated diff --git a/.gitignore b/.gitignore index aab4804..4fb4b63 100644 --- a/.gitignore +++ b/.gitignore @@ -295,3 +295,4 @@ TSWLatexianTemp* # glossaries *.glstex +.pre-commit-config.yaml diff --git a/README.md b/README.md index 68e5e53..cd98acb 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ These were tested with `Turing.jl` version 0.21.9 and Julia 1.7.3. to a safe public or private well in the nearby area and the survey was conducted several years later to learn which of the affected residents had switched wells. - Souce: Gelman and Hill (2007). + Source: Gelman and Hill (2007). - `esoph` (ordinal regression): data from a case-control study of (o)esophageal cancer in Ille-et-Vilaine, France. Source: Breslow and Day (1980). - `roaches` (Poisson regression): data on the efficacy of a pest management system at reducing the number of roaches in urban apartments. @@ -280,6 +280,6 @@ Or in BibTeX format (LaTeX): ## License -This content is licensed under [Creative Commons Attribution-ShareAlike 4.0 Internacional](http://creativecommons.org/licenses/by-sa/4.0/). +This content is licensed under [Creative Commons Attribution-ShareAlike 4.0 International](http://creativecommons.org/licenses/by-sa/4.0/). [![CC BY-SA 4.0](https://licensebuttons.net/l/by-sa/4.0/88x31.png)](http://creativecommons.org/licenses/by-sa/4.0/) diff --git a/_typos.toml b/_typos.toml new file mode 100644 index 0000000..92ec7ae --- /dev/null +++ b/_typos.toml @@ -0,0 +1,11 @@ +[default] +extend-ignore-re = ["textcite\\{.*\\}", "lik", "Yau"] +files.ignore-hidden = true + +[type.bib] +extend-glob = ["*.bib"] +check-file = false + +[type.sty] +extend-glob = ["*.sty"] +check-file = false diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..9d6929b --- /dev/null +++ b/flake.lock @@ -0,0 +1,186 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1699186365, + "narHash": "sha256-Pxrw5U8mBsL3NlrJ6q1KK1crzvSUcdfwb9083sKDrcU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a0b3b06b7a82c965ae0bb1d59f6e386fe755001d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1689261696, + "narHash": "sha256-LzfUtFs9MQRvIoQ3MfgSuipBVMXslMPH/vZ+nM40LkA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "df1eee2aa65052a18121ed4971081576b25d6b5c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1700922917, + "narHash": "sha256-ej2fch/T584b5K9sk1UhmZF7W6wEfDHuoUYpFN8dtvM=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "e5ee5c5f3844550c01d2131096c7271cec5e9b78", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..725e440 --- /dev/null +++ b/flake.nix @@ -0,0 +1,65 @@ +{ + description = "A basic flake with a shell"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + + outputs = { self, nixpkgs, flake-utils, pre-commit-hooks }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + tex = pkgs.texlive.combine { + inherit (pkgs.texlive) scheme-small; + inherit (pkgs.texlive) latexmk pgf pgfplots tikzsymbols biblatex beamer; + inherit (pkgs.texlive) silence appendixnumberbeamer fira fontaxes mwe; + inherit (pkgs.texlive) noto csquotes babel helvetic transparent; + inherit (pkgs.texlive) xpatch hyphenat wasysym algorithm2e listings; + inherit (pkgs.texlive) lstbayes ulem subfigure ifoddpage relsize; + inherit (pkgs.texlive) adjustbox media9 ocgx2 biblatex-apa wasy; + }; + julia = pkgs.julia-bin.overrideDerivation (oldAttrs: { doInstallCheck = false; }); + + in + { + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + typos.enable = true; + }; + }; + }; + + devShells.default = pkgs.mkShell { + packages = with pkgs;[ + bashInteractive + # pdfpc # FIXME: broken on darwin + typos + cmdstan + julia + ]; + + inherit (self.checks.${system}.pre-commit-check) shellHook; + }; + packages.default = pkgs.stdenvNoCC.mkDerivation rec { + name = "slides"; + src = self; + buildInputs = with pkgs; [ + coreutils + tex + gnuplot + biber + ]; + phases = [ "unpackPhase" "buildPhase" "installPhase" ]; + buildPhase = '' + export PATH="${pkgs.lib.makeBinPath buildInputs}"; + export HOME=$(pwd) + latexmk -pdflatex -shell-escape slides/slides.tex + ''; + installPhase = '' + mkdir -p $out + cp slides.pdf $out/ + ''; + }; + }); +} diff --git a/slides/02-Statistical_Distributions.tex b/slides/02-Statistical_Distributions.tex index 6ff7c5f..d9d4e99 100644 --- a/slides/02-Statistical_Distributions.tex +++ b/slides/02-Statistical_Distributions.tex @@ -505,7 +505,7 @@ \subsubsection{Log-Normal} \subsubsection{Exponential} \begin{frame}{Exponential} The exponential distribution is the probability distribution of the time - between events that occurs in a continuos manner, are independent, + between events that occurs in a continuous manner, are independent, and have constant mean rate of occurrence. \vfill The exponential distribution has one parameter and its notation is diff --git a/slides/10-Hierarchical_Models.tex b/slides/10-Hierarchical_Models.tex index 094a130..c7279b5 100644 --- a/slides/10-Hierarchical_Models.tex +++ b/slides/10-Hierarchical_Models.tex @@ -489,8 +489,8 @@ \subsection{Hyperprior} $$ Here $\mathbf{y}$ is a variable of interest that belongs to distinct groups. $\boldsymbol{\theta}$, a prior for $\mathbf{y}$, - is a vector of group-leve parameters with their own prior - (which becomes a hiperprior) $\phi$. + is a vector of group-level parameters with their own prior + (which becomes a hyperprior) $\phi$. \end{frame} \subsection{Frequentist versus Bayesian Approaches} diff --git a/slides/12-Model_Comparison.tex b/slides/12-Model_Comparison.tex index dc6dae6..4d244ad 100644 --- a/slides/12-Model_Comparison.tex +++ b/slides/12-Model_Comparison.tex @@ -76,7 +76,7 @@ \subsection{Model Comparison Techniques} where $n$ is the sample size and $S$ is the number of posterior draws. \end{frame} -\begin{frame}{Historial Interlude -- AIC \parencite{akaike1998information}} +\begin{frame}{Historical Interlude -- AIC \parencite{akaike1998information}} $$ \text{AIC} = D(y, \boldsymbol{\theta}) + 2k = -2 \text{lppd}_{\text{mle}} + 2k $$ diff --git a/slides/flake.lock b/slides/flake.lock index 50c55c6..9d6929b 100644 --- a/slides/flake.lock +++ b/slides/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -18,6 +34,45 @@ "type": "github" } }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1699186365, @@ -34,10 +89,65 @@ "type": "github" } }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1689261696, + "narHash": "sha256-LzfUtFs9MQRvIoQ3MfgSuipBVMXslMPH/vZ+nM40LkA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "df1eee2aa65052a18121ed4971081576b25d6b5c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1700922917, + "narHash": "sha256-ej2fch/T584b5K9sk1UhmZF7W6wEfDHuoUYpFN8dtvM=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "e5ee5c5f3844550c01d2131096c7271cec5e9b78", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks" } }, "systems": { @@ -54,6 +164,21 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/slides/flake.nix b/slides/flake.nix index 858f925..010720a 100644 --- a/slides/flake.nix +++ b/slides/flake.nix @@ -2,8 +2,9 @@ description = "A basic flake with a shell"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; - outputs = { self, nixpkgs, flake-utils }: + outputs = { self, nixpkgs, flake-utils, pre-commit-hooks }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; @@ -18,20 +19,32 @@ }; in { + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + typos.enable = true; + }; + }; + }; + devShells.default = pkgs.mkShell { - packages = [ - pkgs.bashInteractive - pkgs.pdfpc + packages = with pkgs;[ + bashInteractive + # pdfpc # FIXME: broken on darwin + typos ]; + + inherit (self.checks.${system}.pre-commit-check) shellHook; }; - defaultPackage = pkgs.stdenvNoCC.mkDerivation rec { + packages.default = pkgs.stdenvNoCC.mkDerivation rec { name = "slides"; src = self; - buildInputs = [ - pkgs.coreutils + buildInputs = with pkgs; [ + coreutils tex - pkgs.gnuplot - pkgs.biber + gnuplot + biber ]; phases = [ "unpackPhase" "buildPhase" "installPhase" ]; buildPhase = ''