Skip to content

Commit 558c9a7

Browse files
committed
Refactor code to comply with Black style
1 parent 34c2a14 commit 558c9a7

18 files changed

Lines changed: 3205 additions & 1666 deletions

scripts/fuzzer.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77

88
from watson import Watson
99

10-
if not os.environ.get('WATSON_DIR'):
10+
if not os.environ.get("WATSON_DIR"):
1111
sys.exit(
1212
"This script will corrupt Watson's data, please set the WATSON_DIR "
1313
"environment variable to safely use it for development purpose."
1414
)
1515

16-
watson = Watson(config_dir=os.environ.get('WATSON_DIR'),
17-
frames=None,
18-
current=None)
16+
watson = Watson(config_dir=os.environ.get("WATSON_DIR"), frames=None, current=None)
1917

2018
projects = [
2119
("apollo11", ["reactor", "module", "wheels", "steering", "brakes"]),
@@ -26,21 +24,22 @@
2624

2725
now = arrow.now()
2826

29-
for date in arrow.Arrow.range('day', now.shift(months=-1), now):
27+
for date in arrow.Arrow.range("day", now.shift(months=-1), now):
3028
if date.weekday() in (5, 6):
3129
# Weekend \o/
3230
continue
3331

34-
start = date.replace(hour=9, minute=random.randint(0, 59)) \
35-
.shift(seconds=random.randint(0, 59))
32+
start = date.replace(hour=9, minute=random.randint(0, 59)).shift(
33+
seconds=random.randint(0, 59)
34+
)
3635

3736
while start.hour < random.randint(16, 19):
3837
project, tags = random.choice(projects)
3938
frame = watson.frames.add(
4039
project,
4140
start,
4241
start.shift(seconds=random.randint(60, 4 * 60 * 60)),
43-
tags=random.sample(tags, random.randint(0, len(tags)))
42+
tags=random.sample(tags, random.randint(0, len(tags))),
4443
)
4544
start = frame.stop.shift(seconds=random.randint(0, 1 * 60 * 60))
4645

scripts/gen-cli-docs.py

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,65 @@
55
from click.core import Command, Context
66
from click.formatting import HelpFormatter
77
from watson import cli as watson_cli
8+
89
# from watson import watson
910

1011

1112
class MarkdownFormatter(HelpFormatter):
12-
1313
def write_heading(self, heading):
1414
"""Writes a heading into the buffer."""
15-
self.write('### {}\n'.format(heading))
15+
self.write("### {}\n".format(heading))
1616

17-
def write_usage(self, prog, args='', prefix='Usage: '):
17+
def write_usage(self, prog, args="", prefix="Usage: "):
1818
"""Writes a usage line into the buffer.
1919
:param prog: the program name.
2020
:param args: whitespace separated list of arguments.
2121
:param prefix: the prefix for the first line.
2222
"""
23-
self.write('```bash\n{} {} {}\n```\n'.format(prefix, prog, args))
23+
self.write("```bash\n{} {} {}\n```\n".format(prefix, prog, args))
2424

2525
def write_text(self, text):
26-
"""Writes re-indented text into the buffer.
27-
"""
26+
"""Writes re-indented text into the buffer."""
2827

2928
should_indent = False
3029
rows = []
3130

32-
for row in text.split('\n'):
31+
for row in text.split("\n"):
3332

3433
if should_indent:
35-
row = ' {}'.format(row)
34+
row = " {}".format(row)
3635

37-
if '\b' in row:
38-
row = row.replace('\b', '', 1)
36+
if "\b" in row:
37+
row = row.replace("\b", "", 1)
3938
should_indent = True
4039
elif not len(row.strip()):
4140
should_indent = False
4241

4342
rows.append(row)
4443

45-
self.write("{}\n".format('\n'.join(rows)))
44+
self.write("{}\n".format("\n".join(rows)))
4645

4746
def write_dl(self, rows, **kwargs):
4847
"""Writes a definition list into the buffer. This is how options
4948
and commands are usually formatted.
5049
:param rows: a list of two item tuples for the terms and values.
5150
"""
5251
rows = list(rows)
53-
self.write('\n')
52+
self.write("\n")
5453

55-
self.write('Flag | Help\n')
56-
self.write('-----|-----\n')
54+
self.write("Flag | Help\n")
55+
self.write("-----|-----\n")
5756

5857
for row in rows:
59-
self.write('`{}` | {}\n'.format(*row))
60-
self.write('\n')
58+
self.write("`{}` | {}\n".format(*row))
59+
self.write("\n")
6160

6261

6362
class MkdocsContext(Context):
64-
6563
@property
6664
def command_path(self):
6765
# Not so proud of it
68-
return 'watson {}'.format(self.command.name)
66+
return "watson {}".format(self.command.name)
6967

7068
def make_formatter(self):
7169
return MarkdownFormatter()
@@ -84,18 +82,19 @@ def is_click_command(obj):
8482
return True
8583
return False
8684

87-
content = '\n'.join((
88-
"<!-- ",
89-
" This document has been automatically generated.",
90-
" It should NOT BE EDITED.",
91-
" To update this part of the documentation,",
92-
" please type the following from the repository root:",
93-
" $ make docs"
94-
"-->",
95-
"",
96-
"# Commands",
97-
"",
98-
))
85+
content = "\n".join(
86+
(
87+
"<!-- ",
88+
" This document has been automatically generated.",
89+
" It should NOT BE EDITED.",
90+
" To update this part of the documentation,",
91+
" please type the following from the repository root:",
92+
" $ make docs" "-->",
93+
"",
94+
"# Commands",
95+
"",
96+
)
97+
)
9998

10099
# Iterate over commands to build docs
101100
for cmd_name, cmd in inspect.getmembers(watson_cli, is_click_command):
@@ -106,14 +105,14 @@ def is_click_command(obj):
106105

107106
# Each command is a section
108107
content += "## `{}`\n\n".format(cmd_name)
109-
content += ''.join(formatter.buffer)
108+
content += "".join(formatter.buffer)
110109

111110
# Write the commands documentation file
112-
with open(rowsput, 'w') as f:
111+
with open(rowsput, "w") as f:
113112
f.write(content)
114113

115114

116-
if __name__ == '__main__':
115+
if __name__ == "__main__":
117116

118-
commands_md = 'docs/user-guide/commands.md'
117+
commands_md = "docs/user-guide/commands.md"
119118
main(commands_md)

setup.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66
from setuptools import setup
77

8-
with open('README.rst') as f:
8+
with open("README.rst") as f:
99
readme = f.read()
1010

1111
# read package meta-data from version.py
1212
pkg = {}
13-
mod = join('watson', 'version.py')
14-
exec(compile(open(mod).read(), mod, 'exec'), {}, pkg)
13+
mod = join("watson", "version.py")
14+
exec(compile(open(mod).read(), mod, "exec"), {}, pkg)
1515

1616

17-
def parse_requirements(requirements, ignore=('setuptools',)):
17+
def parse_requirements(requirements, ignore=("setuptools",)):
1818
"""Read dependencies from requirements file (with version numbers if any)
1919
2020
Note: this implementation does not support requirements files with extra
@@ -24,32 +24,32 @@ def parse_requirements(requirements, ignore=('setuptools',)):
2424
packages = set()
2525
for line in f:
2626
line = line.strip()
27-
if line.startswith(('#', '-r', '--')):
27+
if line.startswith(("#", "-r", "--")):
2828
continue
29-
if '#egg=' in line:
30-
line = line.split('#egg=')[1]
29+
if "#egg=" in line:
30+
line = line.split("#egg=")[1]
3131
pkg = line.strip()
3232
if pkg not in ignore:
3333
packages.add(pkg)
3434
return tuple(packages)
3535

3636

3737
setup(
38-
name='td-watson',
39-
version=pkg['version'],
40-
description='A wonderful CLI to track your time!',
38+
name="td-watson",
39+
version=pkg["version"],
40+
description="A wonderful CLI to track your time!",
4141
url="https://github.com/TailorDev/Watson",
42-
packages=['watson'],
43-
author='TailorDev',
44-
author_email='contact@tailordev.fr',
45-
license='MIT',
42+
packages=["watson"],
43+
author="TailorDev",
44+
author_email="contact@tailordev.fr",
45+
license="MIT",
4646
long_description=readme,
47-
install_requires=parse_requirements('requirements.txt'),
48-
python_requires='>=3.6',
49-
tests_require=parse_requirements('requirements-dev.txt'),
47+
install_requires=parse_requirements("requirements.txt"),
48+
python_requires=">=3.6",
49+
tests_require=parse_requirements("requirements-dev.txt"),
5050
entry_points={
51-
'console_scripts': [
52-
'watson = watson.__main__:cli',
51+
"console_scripts": [
52+
"watson = watson.__main__:cli",
5353
]
5454
},
5555
classifiers=[
@@ -73,5 +73,5 @@ def parse_requirements(requirements, ignore=('setuptools',)):
7373
"Topic :: Office/Business",
7474
"Topic :: Utilities",
7575
],
76-
keywords='watson time-tracking time tracking monitoring report',
76+
keywords="watson time-tracking time tracking monitoring report",
7777
)

tests/__init__.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,18 @@
88
import py
99

1010

11-
TEST_FIXTURE_DIR = py.path.local(
12-
os.path.dirname(
13-
os.path.realpath(__file__)
14-
)
15-
) / 'resources'
11+
TEST_FIXTURE_DIR = (
12+
py.path.local(os.path.dirname(os.path.realpath(__file__))) / "resources"
13+
)
1614

1715

1816
def mock_datetime(dt, dt_module):
19-
2017
class DateTimeMeta(type):
21-
2218
@classmethod
2319
def __instancecheck__(mcs, obj):
2420
return isinstance(obj, datetime.datetime)
2521

2622
class BaseMockedDateTime(datetime.datetime):
27-
2823
@classmethod
2924
def now(cls, tz=None):
3025
return dt.replace(tzinfo=tz)
@@ -37,9 +32,9 @@ def utcnow(cls):
3732
def today(cls):
3833
return dt
3934

40-
MockedDateTime = DateTimeMeta('datetime', (BaseMockedDateTime,), {})
35+
MockedDateTime = DateTimeMeta("datetime", (BaseMockedDateTime,), {})
4136

42-
return mock.patch.object(dt_module, 'datetime', MockedDateTime)
37+
return mock.patch.object(dt_module, "datetime", MockedDateTime)
4338

4439

4540
def mock_read(content):

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
@pytest.fixture
1010
def config_dir(tmpdir):
11-
return str(tmpdir.mkdir('config'))
11+
return str(tmpdir.mkdir("config"))
1212

1313

1414
@pytest.fixture

tests/test_autocompletion.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@
4242
(get_tags, None, []),
4343
],
4444
)
45-
def test_if_returned_values_are_distinct(
46-
watson_df, func_to_test, rename_type, args
47-
):
45+
def test_if_returned_values_are_distinct(watson_df, func_to_test, rename_type, args):
4846
ctx = ClickContext(obj=watson_df, params={"rename_type": rename_type})
4947
prefix = ""
5048
ret_list = list(func_to_test(ctx, args, prefix))
@@ -89,9 +87,7 @@ def test_if_empty_prefix_returns_everything(
8987
(get_tags, None, []),
9088
],
9189
)
92-
def test_completion_of_nonexisting_prefix(
93-
watson_df, func_to_test, rename_type, args
94-
):
90+
def test_completion_of_nonexisting_prefix(watson_df, func_to_test, rename_type, args):
9591
ctx = ClickContext(obj=watson_df, params={"rename_type": rename_type})
9692
prefix = "NOT-EXISTING-PREFIX"
9793
ret_list = list(func_to_test(ctx, args, prefix))

0 commit comments

Comments
 (0)