Skip to content

Commit

Permalink
Merge pull request #1 from notPlancha:pre_commit
Browse files Browse the repository at this point in the history
Added pre-commit
  • Loading branch information
notPlancha authored Feb 2, 2024
2 parents 88d2764 + eccd1c7 commit e3e9d9b
Show file tree
Hide file tree
Showing 10 changed files with 1,233 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
^LICENSE$
^revdep$
^CRAN-SUBMISSION$
^\.pre-commit-config\.yaml$
^hook_scripts$
3 changes: 2 additions & 1 deletion .Rprofile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ if (interactive()) {
require(devtools)
require(conflicted)
require(desc)
# pak("r-lib/desc") # theres a bug
# pak("r-lib/revdepcheck")
# pak("jumpingrivers/inteRgrate")
## https://www.r-bloggers.com/2020/07/how-to-write-your-own-r-package-and-publish-it-on-cran/

## https://github.com/DavisVaughan/extrachecks
d <- desc::desc()
tryit <- \() {devtools::load_all()}
build_docs <- \() {devtools::document()}
Expand Down
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML

217 changes: 214 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,219 @@
.Rproj.user



temp.*
temp/
# pixi environments
.pixi


# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

# History files
.Rhistory
.Rapp.history

# Session Data files
.RData
.RDataTmp

# User-specific files
.Ruserdata

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

temp.*
temp/
# knitr and R markdown default cache directories
*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# R Environment Variables
.Renviron

# pkgdown site
docs/

# translation temp files
po/*~

# RStudio Connect folder
rsconnect/
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +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 check extrachecks
# TODO check the email
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: settingsSync
Title: Rstudio Addin to Sync Settings and Keymaps
Version: 1.0.1-0
Version: 1.0.1-1
Authors@R:
person(, "notPlancha", , "[email protected]", role = c("aut", "cre"))
Author: notPlancha [aut, cre]
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,16 @@ pak::pak("notPlancha/settingsSync")
You can directly call `settingsSync::sync()`, or use the Rstudio Addin (they do the same thing); and follow the instructions. The extension pulls the settings from Google Drive (if any), tries to merge them with the local settings (the package has conflict resolution), and then pushes the merged settings to Google Drive.

## Contributing
I'm using (pixi)[https://github.com/prefix-dev/pixi] to ease development, and (pre-commit)[https://pre-commit.com/]. So after cloning:

```bash
# scoop install pixi
pixi install
pixi run hook-install
```
should do the trick. After that open the project in Rstudio.

> [!NOTE]
> I didn't add R to pixi because (Windows versions are not updated)[https://github.com/conda-forge/r-base-feedstock/issues/248] and they don't work well with rstudio (and [rstudio in conda is also not updated as of writing](https://github.com/conda-forge/rstudio-feedstock/issues/29)).
Feel free to open an issue or a PR.
53 changes: 53 additions & 0 deletions hook_scripts/up-dev-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from expression import pipe # functional programming
from expression.collections import seq
from icecream import ic # debugging
import sys
from warnings import warn
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(desc, 'r') as f:
lines = f.readlines() # to later write back to file
for line_number, line in enumerate(lines):
if 'Version:' in line:
version = ic(line.split(":")[1])
version_line = ic(line_number)
break
if version is None:
raise ValueError("Version not found in DESCRIPTION file")

try:
not_dev, dev = pipe(version.split("-"), seq.map(lambda x: x.strip()))
except ValueError:
warn("Version not found in DESCRIPTION file, assuming release version")
sys.exit(0)
ic(not_dev, dev)

version = pipe(
dev,
int,
lambda x: x + 1,
str,
lambda x: f"{not_dev}-{x}"
)
ic(version)
lines[version_line] = ic(f"Version: {version}\n")

with open(desc, 'w') as f:
f.writelines(lines)
subprocess.run(["git", "add", "DESCRIPTION"])
subprocess.run(["git", "commit", "-m", f"Version {version}"])
click.echo(f"Version {version} committed")
Loading

0 comments on commit e3e9d9b

Please sign in to comment.