Skip to content

Commit

Permalink
added pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
notPlancha committed Feb 2, 2024
1 parent da40185 commit eccd1c7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
5 changes: 1 addition & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# 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:
- id: up-dev-version
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
31 changes: 22 additions & 9 deletions hook_scripts/up-dev-version.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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,
Expand All @@ -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}"])
subprocess.run(["git", "commit", "-m", f"Version {version}"])
click.echo(f"Version {version} committed")
34 changes: 34 additions & 0 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit eccd1c7

Please sign in to comment.