diff --git a/.gitignore b/.gitignore index b6e4761..5b3abf5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,23 @@ + +# Created by https://www.gitignore.io/api/python,visualstudiocode,vim,sublimetext,git +# Edit at https://www.gitignore.io/?templates=python,visualstudiocode,vim,sublimetext,git + +### Git ### +# Created by git for backups. To disable backups in Git: +# $ git config --global mergetool.keepBackup false +*.orig + +# Created by git when using merge tools for conflicts +*.BACKUP.* +*.BASE.* +*.LOCAL.* +*.REMOTE.* +*_BACKUP_*.txt +*_BASE_*.txt +*_LOCAL_*.txt +*_REMOTE_*.txt + +### Python ### # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -47,7 +67,6 @@ htmlcov/ nosetests.xml coverage.xml *.cover -*.py,cover .hypothesis/ .pytest_cache/ @@ -55,16 +74,6 @@ coverage.xml *.mo *.pot -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - # Scrapy stuff: .scrapy @@ -74,13 +83,6 @@ docs/_build/ # PyBuilder target/ -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - # pyenv .python-version @@ -91,25 +93,12 @@ ipython_config.py # install all needed dependencies. #Pipfile.lock -# PEP 582; used by e.g. github.com/David-OConnor/pyflow -__pypackages__/ - -# Celery stuff +# celery beat schedule file celerybeat-schedule -celerybeat.pid # SageMath parsed files *.sage.py -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - # Spyder project settings .spyderproject .spyproject @@ -117,6 +106,11 @@ venv.bak/ # Rope project settings .ropeproject +# Mr Developer +.mr.developer.cfg +.project +.pydevproject + # mkdocs documentation /site @@ -127,3 +121,74 @@ dmypy.json # Pyre type checker .pyre/ + +### SublimeText ### +# Cache files for Sublime Text +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache + +# Workspace files are user-specific +*.sublime-workspace + +# Project files should be checked into the repository, unless a significant +# proportion of contributors will probably not be using Sublime Text +# *.sublime-project + +# SFTP configuration file +sftp-config.json + +# Package control specific files +Package Control.last-run +Package Control.ca-list +Package Control.ca-bundle +Package Control.system-ca-bundle +Package Control.cache/ +Package Control.ca-certs/ +Package Control.merged-ca-bundle +Package Control.user-ca-bundle +oscrypto-ca-bundle.crt +bh_unicode_properties.cache + +# Sublime-github package stores a github token in this file +# https://packagecontrol.io/packages/sublime-github +GitHub.sublime-settings + +### Vim ### +# Swap +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-rt-v][a-z] +[._]ss[a-gi-z] +[._]sw[a-p] + +# Session +Session.vim +Sessionx.vim + +# Temporary +.netrwhist +*~ + +# Auto-generated tag files +tags + +# Persistent undo +[._]*.un~ + +# Coc configuration directory +.vim + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history + +# End of https://www.gitignore.io/api/python,visualstudiocode,vim,sublimetext,git + diff --git a/Dockerfile b/Dockerfile index 8711877..6c7ed05 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ -FROM python:3 +FROM python:3-slim +RUN apt update && apt -y upgrade RUN pip install black -COPY entrypoint.sh /entrypoint.sh +COPY run_black_on_git_diff_adds.sh /run_black_on_git_diff_adds.sh -ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/run_black_on_git_diff_adds.sh"] \ No newline at end of file diff --git a/README.md b/README.md index b93f004..b429d93 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Readme -This is a github action that will run the [black python formatter](https://github.com/psf/black) on a PR, but only on the files changed in your PR. This helps avoid situations where one runs the formatter on an old code base and gets hundreds of files with warnings and hints. +This is a github action that will run the [black python formatter](https://github.com/psf/black) on a PR, but only on the files changed in your PR. This helps avoid situations where one runs the formatter on an old code base and gets hundreds of files with warnings and hints. Entrypoint code is inspired by the excellent [typilus](https://github.com/typilus/typilus-action/blob/master/entrypoint.py) ## Installation diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100644 index 9fac2ac..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -# TODO make this actually work, probably just convert into pythong -list_of_edited_files=`./git_diff_to_get_list_of_edited_files` -black ${list_of_edited_files} \ No newline at end of file diff --git a/run_black_on_git_diff_adds.sh b/run_black_on_git_diff_adds.sh new file mode 100644 index 0000000..abfdd86 --- /dev/null +++ b/run_black_on_git_diff_adds.sh @@ -0,0 +1,12 @@ +#!/bin/bash +if [[ ${GITHUB_EVENT_NAME} != "pull_request" ]] +then + echo "this action runs only on pull request events" + exit 1 +fi + +github_pr_url=`echo -En ${GITHUB_EVENT_PATH} | jq '.pull_request.url'` +github_diff=`curl --request GET --url ${github_pr_url} --header "authorization: Bearer ${GITHUB_TOKEN}" --header "Accept: application/vnd.github.v3.diff"` +list_of_edited_files=`echo -En ${github_diff} | grep -E -- "\+\+\+ " | awk '{print $2}' | grep -Po -- "(?<=[ab]/).+(.py$)"` + +black ${list_of_edited_files} \ No newline at end of file