diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 062e25d..7ab0934 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,6 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks +# R specific hooks: https://github.com/lorenzwalthert/precommit repos: - repo: local hooks: @@ -7,9 +8,5 @@ repos: name: up-dev-version description: Bumps the dev version in DESCRIPTION entry: pixi run up-dev -# TODO add roxygenyze https://lorenzwalthert.github.io/precommit/articles/available-hooks.html -# TODO add one that bumps dev version (manually write) -# TODO check what each of these does -# TODO add pre-commit to README # TODO check extrachecks # TODO check the email \ No newline at end of file diff --git a/hook_scripts/up-dev-version.py b/hook_scripts/up-dev-version.py index 53bb4e2..433a741 100644 --- a/hook_scripts/up-dev-version.py +++ b/hook_scripts/up-dev-version.py @@ -1,12 +1,25 @@ -from expression import pipe +from expression import pipe # functional programming from expression.collections import seq -from icecream import ic +from icecream import ic # debugging import sys from warnings import warn -import subprocess -# ic.disable() +import subprocess # to run git commands +import click # to get user input +from pyprojroot.here import here # to get the root of the project + +desc = here("DESCRIPTION") +if not ("--debug" in sys.argv or "-d" in sys.argv): ic.disable() + +# input just to make sure +try: + result = click.confirm("Do you want to up the dev version?", default=True) + if not result: + sys.exit(0) +except click.Abort: + sys.exit(1) + version = None -with open('DESCRIPTION', 'r') as f: +with open(desc, 'r') as f: lines = f.readlines() # to later write back to file for line_number, line in enumerate(lines): if 'Version:' in line: @@ -22,7 +35,7 @@ warn("Version not found in DESCRIPTION file, assuming release version") sys.exit(0) ic(not_dev, dev) -print("Upping dev version before pushing") + version = pipe( dev, int, @@ -33,8 +46,8 @@ ic(version) lines[version_line] = ic(f"Version: {version}\n") -with open('DESCRIPTION', 'w') as f: +with open(desc, 'w') as f: f.writelines(lines) - subprocess.run(["git", "add", "DESCRIPTION"]) -subprocess.run(["git", "commit", "-m", f"Version {version}"]) \ No newline at end of file +subprocess.run(["git", "commit", "-m", f"Version {version}"]) +click.echo(f"Version {version} committed") \ No newline at end of file diff --git a/pixi.lock b/pixi.lock index 7e57b32..16848fc 100644 --- a/pixi.lock +++ b/pixi.lock @@ -7,6 +7,7 @@ environments: win-64: - conda: https://conda.anaconda.org/conda-forge/noarch/asttokens-2.4.1-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/cfgv-3.3.1-pyhd8ed1ab_0.tar.bz2 + - conda: https://conda.anaconda.org/conda-forge/noarch/click-8.1.7-win_pyh7428d3b_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/colorama-0.4.6-pyhd8ed1ab_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/distlib-0.3.8-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/executing-2.0.1-pyhd8ed1ab_0.conda @@ -22,6 +23,7 @@ environments: - conda: https://conda.anaconda.org/conda-forge/noarch/prompt_toolkit-3.0.42-hd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/pycparser-2.21-pyhd8ed1ab_0.tar.bz2 - conda: https://conda.anaconda.org/conda-forge/noarch/pygments-2.17.2-pyhd8ed1ab_0.conda + - conda: https://conda.anaconda.org/conda-forge/noarch/pyprojroot-0.3.0-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/radian-0.6.11-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/setuptools-69.0.3-pyhd8ed1ab_0.conda - conda: https://conda.anaconda.org/conda-forge/noarch/six-1.16.0-pyh6c4a22f_0.tar.bz2 @@ -139,6 +141,23 @@ packages: license_family: MIT size: 10788 timestamp: 1629909423398 +- kind: conda + name: click + version: 8.1.7 + build: win_pyh7428d3b_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/click-8.1.7-win_pyh7428d3b_0.conda + sha256: 90236b113b9a20041736e80b80ee965167f9aac0468315c55e2bad902d673fb0 + md5: 3549ecbceb6cd77b91a105511b7d0786 + depends: + - __win + - colorama + - python >=3.8 + license: BSD-3-Clause + license_family: BSD + size: 85051 + timestamp: 1692312207348 - kind: conda name: colorama version: 0.4.6 @@ -503,6 +522,21 @@ packages: license_family: BSD size: 860425 timestamp: 1700608076927 +- kind: conda + name: pyprojroot + version: 0.3.0 + build: pyhd8ed1ab_0 + subdir: noarch + noarch: python + url: https://conda.anaconda.org/conda-forge/noarch/pyprojroot-0.3.0-pyhd8ed1ab_0.conda + sha256: 560cabb0d3e917d732ce729709f53407407e4b9f8d8e2ea0f399482e9406c26c + md5: a8cf267fb068e62490a8ae9f7918c7f0 + depends: + - python >=3.7 + license: MIT + license_family: MIT + size: 12705 + timestamp: 1679412805849 - kind: conda name: python version: 3.12.1 diff --git a/pixi.toml b/pixi.toml index d3bf9de..7dab26a 100644 --- a/pixi.toml +++ b/pixi.toml @@ -14,3 +14,5 @@ pre-commit = ">=3.6.0,<3.7" radian = ">=0.6.11,<0.7" expression = ">=5.0.2,<5.1" icecream = ">=2.1.3,<2.2" +click = ">=8.1.7,<8.2" +pyprojroot = ">=0.3.0,<0.4"