Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add template for pipenv, update install routine #20

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ $ git commit
This allows the user to choose whether to execute the hooks by activating the
virtual environment or to ignore them by deactivating it.

### `auto-run` as an alternative

There might be use cases where you want the Git hooks to be run
automatically, for example if you want to commit using the commit
tools of your IDE or if you want to enforce a certain code style
across your team. In such cases, you can add
```
auto-run = true
```
to your `pyproject.toml`.

## Plugins

* Python code formatting via [black](https://github.com/greenbone/autohooks-plugin-black)
Expand Down
4 changes: 4 additions & 0 deletions autohooks/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def get_pre_commit_script_names(self):
def get_config(self):
return self._config

def get_auto_run(self):
if self.has_autohooks_config():
return self._autohooks_config.get_value('auto-run', False)


def load_config_from_pyproject_toml(pyproject_toml=None):
if pyproject_toml is None:
Expand Down
19 changes: 15 additions & 4 deletions autohooks/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from setuptools.command.install import install

import shutil

from setuptools.command.develop import develop
from setuptools.command.install import install

from autohooks.config import load_config_from_pyproject_toml
from autohooks.utils import (
get_git_hook_directory_path,
get_autohooks_directory_path,
)
get_pyproject_toml_path)


def get_pre_commit_hook_path():
Expand All @@ -30,8 +34,15 @@ def get_pre_commit_hook_path():


def get_pre_commit_hook_template_path():
setup_dir_path = get_autohooks_directory_path()
return setup_dir_path / 'precommit' / 'template'
pyproject_toml = get_pyproject_toml_path()
config = load_config_from_pyproject_toml(pyproject_toml)

auto_install = config.get_auto_run()

setup_dir_path = get_autohooks_directory_path() / 'precommit'
if auto_install:
return setup_dir_path / 'template_pipenv'
return setup_dir_path / 'template'


def get_autohooks_pre_commit_hook():
Expand Down
11 changes: 11 additions & 0 deletions autohooks/precommit/template_pipenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env pipenv run python3

import sys

try:
from autohooks.precommit import run
sys.exit(run())
except ImportError:
print('autohooks not installed. Ignoring pre-commit hook.')
sys.exit(0)