clickusagemd searches for git root to locate pyproject.yaml
This commit is contained in:
parent
6e12e15904
commit
7322a36e04
|
@ -1,14 +1,22 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import importlib
|
||||
import os
|
||||
from typing import Iterator
|
||||
|
||||
import click
|
||||
import git
|
||||
import toml
|
||||
|
||||
from clickusagelib.githook import install_hook, uninstall_hook
|
||||
|
||||
|
||||
def find_git_root(path) -> str:
|
||||
git_repo = git.Repo(path, search_parent_directories=True)
|
||||
git_root = git_repo.git.rev_parse("--show-toplevel")
|
||||
return git_root
|
||||
|
||||
|
||||
def iter_commands(
|
||||
module_name: str,
|
||||
cmd_chain: list,
|
||||
|
@ -63,7 +71,11 @@ def cli():
|
|||
|
||||
|
||||
@cli.command(help="Generate markdown usage description.")
|
||||
@click.argument("poetry_project_file", type=click.File(), default="pyproject.toml")
|
||||
@click.argument(
|
||||
"poetry_project_file",
|
||||
type=click.File(),
|
||||
default=os.path.join(find_git_root(os.getcwd()), "pyproject.toml"),
|
||||
)
|
||||
@click.pass_context
|
||||
def run(ctx, poetry_project_file):
|
||||
contents = toml.loads(poetry_project_file.read())
|
||||
|
@ -79,12 +91,12 @@ def run(ctx, poetry_project_file):
|
|||
|
||||
@cli.command(help="Install clickusagemd as pre-push hook.")
|
||||
def install():
|
||||
install_hook("./")
|
||||
install_hook(find_git_root(os.getcwd()))
|
||||
|
||||
|
||||
@cli.command(help="Uninstall clickusagemd pre-push hook.")
|
||||
def uninstall():
|
||||
uninstall_hook("./")
|
||||
uninstall_hook(find_git_root(os.getcwd()))
|
||||
|
||||
|
||||
cli.add_command(run)
|
||||
|
|
37
poetry.lock
generated
37
poetry.lock
generated
|
@ -45,6 +45,28 @@ python-versions = ">=3.7"
|
|||
docs = ["furo (>=2021.8.17b43)", "sphinx (>=4.1)", "sphinx-autodoc-typehints (>=1.12)"]
|
||||
testing = ["covdefaults (>=1.2.0)", "coverage (>=4)", "pytest (>=4)", "pytest-cov", "pytest-timeout (>=1.4.2)"]
|
||||
|
||||
[[package]]
|
||||
name = "gitdb"
|
||||
version = "4.0.9"
|
||||
description = "Git Object Database"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
|
||||
[package.dependencies]
|
||||
smmap = ">=3.0.1,<6"
|
||||
|
||||
[[package]]
|
||||
name = "gitpython"
|
||||
version = "3.1.27"
|
||||
description = "GitPython is a python library used to interact with Git repositories"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[package.dependencies]
|
||||
gitdb = ">=4.0.1,<5"
|
||||
|
||||
[[package]]
|
||||
name = "identify"
|
||||
version = "2.5.1"
|
||||
|
@ -108,6 +130,14 @@ category = "dev"
|
|||
optional = false
|
||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
|
||||
|
||||
[[package]]
|
||||
name = "smmap"
|
||||
version = "5.0.0"
|
||||
description = "A pure Python implementation of a sliding window memory map manager"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.6"
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.10.2"
|
||||
|
@ -136,8 +166,8 @@ testing = ["coverage (>=4)", "coverage-enable-subprocess (>=1)", "flaky (>=3)",
|
|||
|
||||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "6ca2ad33513723ed550f109e19f853415315fbb35760107dbf3a5818ffc4be4b"
|
||||
python-versions = "^3.8"
|
||||
content-hash = "c422cf7a9ff8a7d8d80908da29095a1ada90a86b3cea5e9b0ee7e00141e52c78"
|
||||
|
||||
[metadata.files]
|
||||
cfgv = []
|
||||
|
@ -145,11 +175,14 @@ click = []
|
|||
colorama = []
|
||||
distlib = []
|
||||
filelock = []
|
||||
gitdb = []
|
||||
gitpython = []
|
||||
identify = []
|
||||
nodeenv = []
|
||||
platformdirs = []
|
||||
pre-commit = []
|
||||
pyyaml = []
|
||||
six = []
|
||||
smmap = []
|
||||
toml = []
|
||||
virtualenv = []
|
||||
|
|
|
@ -16,6 +16,7 @@ packages = [
|
|||
python = "^3.8"
|
||||
click = "^8.1.3"
|
||||
toml = "^0.10.2"
|
||||
GitPython = "^3.1.27"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
pre-commit = "^2.20.0"
|
||||
|
|
Loading…
Reference in New Issue
Block a user