Skip to content

Commit 3e6dbf3

Browse files
committed
Run ruff
1 parent 57d8ccb commit 3e6dbf3

File tree

7 files changed

+174
-52
lines changed

7 files changed

+174
-52
lines changed

src/gitup/cli.py

Lines changed: 102 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@
1010
from colorama import init as color_init, Style
1111

1212
from gitup import __version__
13-
from gitup.config import (get_default_config_path, get_bookmarks, add_bookmarks,
14-
delete_bookmarks, list_bookmarks, clean_bookmarks)
13+
from gitup.config import (
14+
get_default_config_path,
15+
get_bookmarks,
16+
add_bookmarks,
17+
delete_bookmarks,
18+
list_bookmarks,
19+
clean_bookmarks,
20+
)
1521
from gitup.update import update_bookmarks, update_directories, run_command
1622

1723

@@ -23,71 +29,134 @@ def _build_parser():
2329
Both relative and absolute paths are accepted by all arguments.
2430
Direct bug reports and feature requests to
2531
https://github.com/earwig/git-repo-updater.""",
26-
add_help=False)
32+
add_help=False,
33+
)
2734

2835
group_u = parser.add_argument_group("updating repositories")
2936
group_b = parser.add_argument_group("bookmarking")
3037
group_a = parser.add_argument_group("advanced")
3138
group_m = parser.add_argument_group("miscellaneous")
3239

3340
group_u.add_argument(
34-
'directories_to_update', nargs="*", metavar="path",
41+
"directories_to_update",
42+
nargs="*",
43+
metavar="path",
3544
help="""update this repository, or all repositories it contains
36-
(if not a repo directly)""")
45+
(if not a repo directly)""",
46+
)
3747
group_u.add_argument(
38-
'-u', '--update', action="store_true", help="""update all bookmarks
39-
(default behavior when called without arguments)""")
48+
"-u",
49+
"--update",
50+
action="store_true",
51+
help="""update all bookmarks
52+
(default behavior when called without arguments)""",
53+
)
4054
group_u.add_argument(
41-
'-t', '--depth', dest="max_depth", metavar="n", type=int, default=3,
55+
"-t",
56+
"--depth",
57+
dest="max_depth",
58+
metavar="n",
59+
type=int,
60+
default=3,
4261
help="""max recursion depth when searching for repos in subdirectories
43-
(default: 3; use 0 for no recursion, or -1 for unlimited)""")
62+
(default: 3; use 0 for no recursion, or -1 for unlimited)""",
63+
)
4464
group_u.add_argument(
45-
'-c', '--current-only', action="store_true", help="""only fetch the
46-
remote tracked by the current branch instead of all remotes""")
65+
"-c",
66+
"--current-only",
67+
action="store_true",
68+
help="""only fetch the
69+
remote tracked by the current branch instead of all remotes""",
70+
)
4771
group_u.add_argument(
48-
'-f', '--fetch-only', action="store_true",
49-
help="only fetch remotes, don't try to fast-forward any branches")
72+
"-f",
73+
"--fetch-only",
74+
action="store_true",
75+
help="only fetch remotes, don't try to fast-forward any branches",
76+
)
5077
group_u.add_argument(
51-
'-p', '--prune', action="store_true", help="""after fetching, delete
52-
remote-tracking branches that no longer exist on their remote""")
78+
"-p",
79+
"--prune",
80+
action="store_true",
81+
help="""after fetching, delete
82+
remote-tracking branches that no longer exist on their remote""",
83+
)
5384

5485
group_b.add_argument(
55-
'-a', '--add', dest="bookmarks_to_add", nargs="+", metavar="path", help="add directory(s) as bookmarks")
86+
"-a",
87+
"--add",
88+
dest="bookmarks_to_add",
89+
nargs="+",
90+
metavar="path",
91+
help="add directory(s) as bookmarks",
92+
)
5693
group_b.add_argument(
57-
'-d', '--delete', dest="bookmarks_to_del", nargs="+", metavar="path",
58-
help="delete bookmark(s) (leaves actual directories alone)")
94+
"-d",
95+
"--delete",
96+
dest="bookmarks_to_del",
97+
nargs="+",
98+
metavar="path",
99+
help="delete bookmark(s) (leaves actual directories alone)",
100+
)
59101
group_b.add_argument(
60-
'-l', '--list', dest="list_bookmarks", action="store_true",
61-
help="list current bookmarks")
102+
"-l",
103+
"--list",
104+
dest="list_bookmarks",
105+
action="store_true",
106+
help="list current bookmarks",
107+
)
62108
group_b.add_argument(
63-
'-n', '--clean', '--cleanup', dest="clean_bookmarks",
64-
action="store_true", help="delete any bookmarks that don't exist")
109+
"-n",
110+
"--clean",
111+
"--cleanup",
112+
dest="clean_bookmarks",
113+
action="store_true",
114+
help="delete any bookmarks that don't exist",
115+
)
65116
group_b.add_argument(
66-
'-b', '--bookmark-file', nargs="?", metavar="path",
117+
"-b",
118+
"--bookmark-file",
119+
nargs="?",
120+
metavar="path",
67121
help="use a specific bookmark config file (default: {0})".format(
68-
get_default_config_path()))
122+
get_default_config_path()
123+
),
124+
)
69125

70126
group_a.add_argument(
71-
'-e', '--exec', '--batch', dest="command", metavar="command",
72-
help="run a shell command on all repos")
127+
"-e",
128+
"--exec",
129+
"--batch",
130+
dest="command",
131+
metavar="command",
132+
help="run a shell command on all repos",
133+
)
73134

74135
group_m.add_argument(
75-
'-h', '--help', action="help", help="show this help message and exit")
136+
"-h", "--help", action="help", help="show this help message and exit"
137+
)
76138
group_m.add_argument(
77-
'-v', '--version', action="version",
78-
version="gitup {0} (Python {1})".format(
79-
__version__, platform.python_version()))
139+
"-v",
140+
"--version",
141+
action="version",
142+
version="gitup {0} (Python {1})".format(__version__, platform.python_version()),
143+
)
80144
group_m.add_argument(
81-
'--selftest', action="store_true",
82-
help="run integrated test suite and exit (pytest must be available)")
145+
"--selftest",
146+
action="store_true",
147+
help="run integrated test suite and exit (pytest must be available)",
148+
)
83149

84150
return parser
85151

152+
86153
def _selftest():
87154
"""Run the integrated test suite with pytest."""
88155
from .test import run_tests
156+
89157
run_tests()
90158

159+
91160
def main():
92161
"""Parse arguments and then call the appropriate function(s)."""
93162
parser = _build_parser()
@@ -130,6 +199,7 @@ def main():
130199
if args.update or not acted:
131200
update_bookmarks(get_bookmarks(args.bookmark_file), args)
132201

202+
133203
def run():
134204
"""Thin wrapper for main() that catches KeyboardInterrupts."""
135205
try:

src/gitup/config.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,28 @@
1010

1111
from gitup.migrate import run_migrations
1212

13-
__all__ = ["get_default_config_path", "get_bookmarks", "add_bookmarks",
14-
"delete_bookmarks", "list_bookmarks", "clean_bookmarks"]
13+
__all__ = [
14+
"get_default_config_path",
15+
"get_bookmarks",
16+
"add_bookmarks",
17+
"delete_bookmarks",
18+
"list_bookmarks",
19+
"clean_bookmarks",
20+
]
1521

1622
YELLOW = Fore.YELLOW + Style.BRIGHT
1723
RED = Fore.RED + Style.BRIGHT
1824

1925
INDENT1 = " " * 3
2026

27+
2128
def _ensure_dirs(path):
2229
"""Ensure the directories within the given pathname exist."""
2330
dirname = os.path.dirname(path)
2431
if dirname and not os.path.exists(dirname): # Race condition, meh...
2532
os.makedirs(dirname)
2633

34+
2735
def _load_config_file(config_path=None):
2836
"""Read the config file and return a list of bookmarks."""
2937
run_migrations()
@@ -37,6 +45,7 @@ def _load_config_file(config_path=None):
3745
paths = [path.decode("utf8").strip() for path in paths]
3846
return [path for path in paths if path]
3947

48+
4049
def _save_config_file(bookmarks, config_path=None):
4150
"""Save the bookmarks list to the given config file."""
4251
run_migrations()
@@ -47,21 +56,25 @@ def _save_config_file(bookmarks, config_path=None):
4756
with open(cfg_path, "wb") as config_file:
4857
config_file.write(dump)
4958

59+
5060
def _normalize_path(path):
5161
"""Normalize the given path."""
5262
if path.startswith("~"):
5363
return os.path.normcase(os.path.normpath(path))
5464
return os.path.normcase(os.path.abspath(path))
5565

66+
5667
def get_default_config_path():
5768
"""Return the default path to the configuration file."""
5869
xdg_cfg = os.environ.get("XDG_CONFIG_HOME") or os.path.join("~", ".config")
5970
return os.path.join(os.path.expanduser(xdg_cfg), "gitup", "bookmarks")
6071

72+
6173
def get_bookmarks(config_path=None):
6274
"""Get a list of all bookmarks, or an empty list if there are none."""
6375
return _load_config_file(config_path)
6476

77+
6578
def add_bookmarks(paths, config_path=None):
6679
"""Add a list of paths as bookmarks to the config file."""
6780
config = _load_config_file(config_path)
@@ -85,6 +98,7 @@ def add_bookmarks(paths, config_path=None):
8598
for path in exists:
8699
print(INDENT1, path)
87100

101+
88102
def delete_bookmarks(paths, config_path=None):
89103
"""Remove a list of paths from the bookmark config file."""
90104
config = _load_config_file(config_path)
@@ -111,6 +125,7 @@ def delete_bookmarks(paths, config_path=None):
111125
for path in notmarked:
112126
print(INDENT1, path)
113127

128+
114129
def list_bookmarks(config_path=None):
115130
"""Print all of our current bookmarks."""
116131
bookmarks = _load_config_file(config_path)
@@ -121,15 +136,19 @@ def list_bookmarks(config_path=None):
121136
else:
122137
print("You have no bookmarks to display.")
123138

139+
124140
def clean_bookmarks(config_path=None):
125141
"""Delete any bookmarks that don't exist."""
126142
bookmarks = _load_config_file(config_path)
127143
if not bookmarks:
128144
print("You have no bookmarks to clean up.")
129145
return
130146

131-
delete = [path for path in bookmarks
132-
if not (os.path.isdir(path) or glob(os.path.expanduser(path)))]
147+
delete = [
148+
path
149+
for path in bookmarks
150+
if not (os.path.isdir(path) or glob(os.path.expanduser(path)))
151+
]
133152
if not delete:
134153
print("All of your bookmarks are valid.")
135154
return

src/gitup/migrate.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
__all__ = ["run_migrations"]
1111

12+
1213
def _get_old_path():
1314
"""Return the old default path to the configuration file."""
1415
xdg_cfg = os.environ.get("XDG_CONFIG_HOME") or os.path.join("~", ".config")
1516
return os.path.join(os.path.expanduser(xdg_cfg), "gitup", "config.ini")
1617

18+
1719
def _migrate_old_path():
1820
"""Migrate the old config location (~/.gitup) to the new one."""
1921
old_path = os.path.expanduser(os.path.join("~", ".gitup"))
@@ -26,6 +28,7 @@ def _migrate_old_path():
2628
os.makedirs(temp_dir)
2729
os.rename(old_path, temp_path)
2830

31+
2932
def _migrate_old_format():
3033
"""Migrate the old config file format (.INI) to our custom list format."""
3134
old_path = _get_old_path()
@@ -47,6 +50,7 @@ def _migrate_old_format():
4750
with open(new_path, "wb") as handle:
4851
handle.write(b"\n".join(bookmarks))
4952

53+
5054
def run_migrations():
5155
"""Run any necessary migrations to ensure the config file is up-to-date."""
5256
_migrate_old_path()

src/gitup/test/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
# Copyright (C) 2011-2018 Ben Kurtovic <ben.kurtovic@gmail.com>
44
# Released under the terms of the MIT License. See LICENSE for details.
55

6+
67
def run_tests(args=None):
78
import pytest
9+
810
if args is None:
911
args = ["-v", "-rxw"]
1012
return pytest.main(args)

src/gitup/test/test_bookmarks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from gitup import config
77

8+
89
def test_empty_list(tmpdir, capsys):
910
config_path = tmpdir / "config"
1011
config.list_bookmarks(config_path)

src/gitup/test/test_cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99

1010
from gitup import __version__
1111

12+
1213
def run_cli(*args):
1314
cmd = [sys.executable, "-m", "gitup"] + list(args)
1415
output = subprocess.check_output(cmd)
1516
return output.strip().decode("utf8")
1617

18+
1719
def test_cli_version():
1820
"""make sure we're using the right version of gitup"""
1921
output = run_cli("-v")
20-
expected = "gitup {} (Python {})".format(
21-
__version__, platform.python_version())
22+
expected = "gitup {} (Python {})".format(__version__, platform.python_version())
2223
assert output == expected

0 commit comments

Comments
 (0)