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
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
|
import os
|
||||||
from typing import Iterator
|
from typing import Iterator
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
import git
|
||||||
import toml
|
import toml
|
||||||
|
|
||||||
from clickusagelib.githook import install_hook, uninstall_hook
|
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(
|
def iter_commands(
|
||||||
module_name: str,
|
module_name: str,
|
||||||
cmd_chain: list,
|
cmd_chain: list,
|
||||||
|
@ -63,7 +71,11 @@ def cli():
|
||||||
|
|
||||||
|
|
||||||
@cli.command(help="Generate markdown usage description.")
|
@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
|
@click.pass_context
|
||||||
def run(ctx, poetry_project_file):
|
def run(ctx, poetry_project_file):
|
||||||
contents = toml.loads(poetry_project_file.read())
|
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.")
|
@cli.command(help="Install clickusagemd as pre-push hook.")
|
||||||
def install():
|
def install():
|
||||||
install_hook("./")
|
install_hook(find_git_root(os.getcwd()))
|
||||||
|
|
||||||
|
|
||||||
@cli.command(help="Uninstall clickusagemd pre-push hook.")
|
@cli.command(help="Uninstall clickusagemd pre-push hook.")
|
||||||
def uninstall():
|
def uninstall():
|
||||||
uninstall_hook("./")
|
uninstall_hook(find_git_root(os.getcwd()))
|
||||||
|
|
||||||
|
|
||||||
cli.add_command(run)
|
cli.add_command(run)
|
||||||
|
|
|
@ -45,6 +45,28 @@ python-versions = ">=3.7"
|
||||||
docs = ["furo (>=2021.8.17b43)", "sphinx (>=4.1)", "sphinx-autodoc-typehints (>=1.12)"]
|
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)"]
|
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]]
|
[[package]]
|
||||||
name = "identify"
|
name = "identify"
|
||||||
version = "2.5.1"
|
version = "2.5.1"
|
||||||
|
@ -108,6 +130,14 @@ category = "dev"
|
||||||
optional = false
|
optional = false
|
||||||
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
|
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]]
|
[[package]]
|
||||||
name = "toml"
|
name = "toml"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
|
@ -136,8 +166,8 @@ testing = ["coverage (>=4)", "coverage-enable-subprocess (>=1)", "flaky (>=3)",
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "1.1"
|
lock-version = "1.1"
|
||||||
python-versions = "^3.10"
|
python-versions = "^3.8"
|
||||||
content-hash = "6ca2ad33513723ed550f109e19f853415315fbb35760107dbf3a5818ffc4be4b"
|
content-hash = "c422cf7a9ff8a7d8d80908da29095a1ada90a86b3cea5e9b0ee7e00141e52c78"
|
||||||
|
|
||||||
[metadata.files]
|
[metadata.files]
|
||||||
cfgv = []
|
cfgv = []
|
||||||
|
@ -145,11 +175,14 @@ click = []
|
||||||
colorama = []
|
colorama = []
|
||||||
distlib = []
|
distlib = []
|
||||||
filelock = []
|
filelock = []
|
||||||
|
gitdb = []
|
||||||
|
gitpython = []
|
||||||
identify = []
|
identify = []
|
||||||
nodeenv = []
|
nodeenv = []
|
||||||
platformdirs = []
|
platformdirs = []
|
||||||
pre-commit = []
|
pre-commit = []
|
||||||
pyyaml = []
|
pyyaml = []
|
||||||
six = []
|
six = []
|
||||||
|
smmap = []
|
||||||
toml = []
|
toml = []
|
||||||
virtualenv = []
|
virtualenv = []
|
||||||
|
|
|
@ -16,6 +16,7 @@ packages = [
|
||||||
python = "^3.8"
|
python = "^3.8"
|
||||||
click = "^8.1.3"
|
click = "^8.1.3"
|
||||||
toml = "^0.10.2"
|
toml = "^0.10.2"
|
||||||
|
GitPython = "^3.1.27"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
pre-commit = "^2.20.0"
|
pre-commit = "^2.20.0"
|
||||||
|
|
Loading…
Reference in New Issue