Skip to content

Commit

Permalink
black style
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jan 29, 2021
1 parent 0a45bd2 commit c8cb719
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
requires = ["setuptools", "wheel"]

[tool.black]
line-length = 132
line-length = 100

[tool.pytest.ini_options]
addopts = "-ra -v"
7 changes: 6 additions & 1 deletion src/gitutils/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ def ActOnChanged():
p = argparse.ArgumentParser()
p.add_argument("path", help="root path to search under", nargs="?", default=".")
p.add_argument("-p", "--preview", help="web browser preview of localhost", action="store_true")
p.add_argument("--port", help="port of localhost web server (Jekyll: 4000, Hugo: 1313)", type=int, default=1313)
p.add_argument(
"--port",
help="port of localhost web server (Jekyll: 4000, Hugo: 1313)",
type=int,
default=1313,
)
p.add_argument("-v", "--verbose", action="store_true")
P = p.parse_args()

Expand Down
19 changes: 15 additions & 4 deletions src/gitutils/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ async def different_branch(main: T.Sequence[str], path: Path) -> T.Tuple[str, st
repo path and branch name
"""

proc = await asyncio.create_subprocess_exec(*[GITEXE, "-C", str(path)] + BRANCH_SIMPLE, stdout=asyncio.subprocess.PIPE)
proc = await asyncio.create_subprocess_exec(
*[GITEXE, "-C", str(path)] + BRANCH_SIMPLE, stdout=asyncio.subprocess.PIPE
)
stdout, _ = await proc.communicate()
if proc.returncode != 0:
logging.error(f"{path.name} return code {proc.returncode} {BRANCH_SIMPLE}")
Expand Down Expand Up @@ -82,13 +84,20 @@ def branch_switch(path: Path, old_branch: str, new_branch: str):
continue

cmd = [GITEXE, "-C", str(d)] + BRANCH_SIMPLE
ret = subprocess.run([GITEXE, "-C", str(d)] + SWITCH + [new_branch], stderr=subprocess.PIPE, timeout=10, text=True)
ret = subprocess.run(
[GITEXE, "-C", str(d)] + SWITCH + [new_branch],
stderr=subprocess.PIPE,
timeout=10,
text=True,
)
if ret.returncode != 0:
stderr = ret.stderr.strip()
if stderr == f"fatal: invalid reference: {new_branch}":
continue
else:
raise ValueError(f"{d} could not switch to {new_branch} from {old_branch}: {stderr}")
raise ValueError(
f"{d} could not switch to {new_branch} from {old_branch}: {stderr}"
)

print(d.name, old_branch, "=>", new_branch)

Expand All @@ -98,7 +107,9 @@ def cli():
report on git repos not on the expected branch e.g. 'master'
"""

p = argparse.ArgumentParser(description="check for non-default branches, and mass switch branches")
p = argparse.ArgumentParser(
description="check for non-default branches, and mass switch branches"
)
p.add_argument("path", help="path to look under", nargs="?", default="~/code")
p.add_argument("-v", "--verbose", action="store_true")
p.add_argument("-main", nargs="+", default=["main", "master"], help="name of your main branch")
Expand Down
8 changes: 6 additions & 2 deletions src/gitutils/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from .git import gitdirs, GITEXE, TIMEOUT


def gitemail(path: Path, exclude: str = None) -> T.Iterator[T.Tuple[Path, T.List[T.Tuple[str, int]]]]:
def gitemail(
path: Path, exclude: str = None
) -> T.Iterator[T.Tuple[Path, T.List[T.Tuple[str, int]]]]:
"""
returns email addresses of everyone who ever made a Git commit in this repo.
Expand All @@ -33,7 +35,9 @@ def gitemail(path: Path, exclude: str = None) -> T.Iterator[T.Tuple[Path, T.List
for d in gitdirs(path):

try:
ret = subprocess.check_output([GITEXE, "-C", str(d), "log", '--pretty="%ce"'], text=True, timeout=TIMEOUT)
ret = subprocess.check_output(
[GITEXE, "-C", str(d), "log", '--pretty="%ce"'], text=True, timeout=TIMEOUT
)
except subprocess.CalledProcessError as e:
logging.error(f"{path} {e}")
continue
Expand Down
5 changes: 4 additions & 1 deletion src/gitutils/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ async def fetchpull(mode: str, path: Path) -> Path:

cmd = [GITEXE, "-C", str(path), mode]
proc = await asyncio.create_subprocess_exec(
*cmd, stdout=subprocess.DEVNULL, stderr=asyncio.subprocess.PIPE, stdin=asyncio.subprocess.DEVNULL
*cmd,
stdout=subprocess.DEVNULL,
stderr=asyncio.subprocess.PIPE,
stdin=asyncio.subprocess.DEVNULL,
)
_, stderr = await proc.communicate()

Expand Down
12 changes: 9 additions & 3 deletions src/gitutils/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def git_porcelain(path: Path) -> bool:
if not path.is_dir():
raise NotADirectoryError(path)

ret = subprocess.run([GITEXE, "-C", str(path)] + C1, stdout=subprocess.PIPE, text=True, timeout=TIMEOUT)
ret = subprocess.run(
[GITEXE, "-C", str(path)] + C1, stdout=subprocess.PIPE, text=True, timeout=TIMEOUT
)
if ret.returncode != 0:
logging.error(f"{path.name} return code {ret.returncode} {C1}")
return False
Expand All @@ -67,7 +69,9 @@ async def _git_status(path: Path) -> T.Tuple[str, str]:
Git repo local changes
"""

proc = await asyncio.create_subprocess_exec(*[GITEXE, "-C", str(path)] + C1, stdout=asyncio.subprocess.PIPE)
proc = await asyncio.create_subprocess_exec(
*[GITEXE, "-C", str(path)] + C1, stdout=asyncio.subprocess.PIPE
)
stdout, _ = await proc.communicate()
if proc.returncode != 0:
logging.error(f"{path.name} return code {proc.returncode} {C1}")
Expand All @@ -78,7 +82,9 @@ async def _git_status(path: Path) -> T.Tuple[str, str]:
if out:
return path.name, out
# %% detect committed, but not pushed
proc = await asyncio.create_subprocess_exec(*[GITEXE, "-C", str(path)] + C0, stdout=asyncio.subprocess.PIPE)
proc = await asyncio.create_subprocess_exec(
*[GITEXE, "-C", str(path)] + C0, stdout=asyncio.subprocess.PIPE
)
stdout, _ = await proc.communicate()
if proc.returncode != 0:
logging.error(f"{path.name} return code {proc.returncode} {C0}")
Expand Down

0 comments on commit c8cb719

Please sign in to comment.