Skip to content

Commit c2395f3

Browse files
committed
Remove top-level __init__.py global imports
1 parent a336a74 commit c2395f3

13 files changed

+150
-353
lines changed

syncall/__init__.py

Lines changed: 3 additions & 202 deletions
Original file line numberDiff line numberDiff line change
@@ -1,206 +1,7 @@
11
"""__init__"""
22

33
# global imports ------------------------------------------------------------------------------
4-
from syncall.__version__ import __version__, __version_tuple__
5-
from syncall.aggregator import Aggregator
6-
from syncall.app_utils import (
7-
app_name,
8-
cache_or_reuse_cached_combination,
9-
fetch_app_configuration,
10-
fetch_from_pass_manager,
11-
get_config_name_for_args,
12-
get_resolution_strategy,
13-
inform_about_app_extras,
14-
inform_about_combination_name_usage,
15-
list_named_combinations,
16-
name_to_resolution_strategy_type,
17-
report_toplevel_exception,
18-
)
19-
from syncall.cli import (
20-
opt_asana_task_gid,
21-
opt_asana_token_pass_path,
22-
opt_asana_workspace_gid,
23-
opt_asana_workspace_name,
24-
opt_combination,
25-
opt_custom_combination_savename,
26-
opt_filesystem_root,
27-
opt_gcal_calendar,
28-
opt_gkeep_labels,
29-
opt_gkeep_note,
30-
opt_gkeep_passwd_pass_path,
31-
opt_gkeep_user_pass_path,
32-
opt_google_oauth_port,
33-
opt_google_secret_override,
34-
opt_gtasks_list,
35-
opt_list_asana_workspaces,
36-
opt_list_combinations,
37-
opt_notion_page_id,
38-
opt_notion_token_pass_path,
39-
opt_resolution_strategy,
40-
opt_tw_project,
41-
opt_tw_tags,
42-
)
43-
from syncall.sync_side import ItemType, SyncSide
4+
from syncall.__version__ import __version__ as version
5+
from syncall.__version__ import __version_tuple__ as version_tuple
446

45-
__all__ = [
46-
"__version__",
47-
"__version_tuple__",
48-
"Aggregator",
49-
"ItemType",
50-
"SyncSide",
51-
"app_name",
52-
"cache_or_reuse_cached_combination",
53-
"fetch_app_configuration",
54-
"fetch_from_pass_manager",
55-
"get_config_name_for_args",
56-
"inform_about_app_extras",
57-
"inform_about_combination_name_usage",
58-
"list_named_combinations",
59-
"get_resolution_strategy",
60-
"name_to_resolution_strategy_type",
61-
"opt_asana_task_gid",
62-
"opt_asana_token_pass_path",
63-
"opt_asana_workspace_gid",
64-
"opt_asana_workspace_name",
65-
"opt_combination",
66-
"opt_custom_combination_savename",
67-
"opt_gcal_calendar",
68-
"opt_gtasks_list",
69-
"opt_gkeep_note",
70-
"opt_gkeep_passwd_pass_path",
71-
"opt_gkeep_user_pass_path",
72-
"opt_google_oauth_port",
73-
"opt_google_secret_override",
74-
"opt_list_asana_workspaces",
75-
"opt_list_combinations",
76-
"opt_notion_page_id",
77-
"opt_notion_token_pass_path",
78-
"opt_resolution_strategy",
79-
"opt_tw_project",
80-
"opt_filesystem_root",
81-
"opt_tw_tags",
82-
"opt_gkeep_labels",
83-
"report_toplevel_exception",
84-
]
85-
86-
# asana ----------------------------------------------------------------------------------------
87-
try:
88-
from syncall.asana.asana_side import AsanaSide
89-
from syncall.asana.utils import list_asana_workspaces
90-
from syncall.tw_asana_utils import convert_asana_to_tw, convert_tw_to_asana
91-
92-
__all__.extend(
93-
["AsanaSide", "convert_asana_to_tw", "convert_tw_to_asana", "list_asana_workspaces"]
94-
)
95-
except ImportError:
96-
pass
97-
98-
# tw ------------------------------------------------------------------------------------------
99-
try:
100-
from syncall.taskwarrior.taskwarrior_side import TaskWarriorSide
101-
102-
__all__.extend(
103-
[
104-
"TaskWarriorSide",
105-
]
106-
)
107-
except ImportError:
108-
pass
109-
110-
# notion --------------------------------------------------------------------------------------
111-
try:
112-
from syncall.notion.notion_side import NotionSide
113-
114-
__all__.extend(["NotionSide"])
115-
except ImportError:
116-
pass
117-
118-
# notion <> tw --------------------------------------------------------------------------------
119-
try:
120-
from syncall.tw_notion_utils import convert_notion_to_tw, convert_tw_to_notion
121-
122-
__all__.extend(["convert_notion_to_tw", "convert_tw_to_notion"])
123-
except ImportError:
124-
pass
125-
126-
# gcal ----------------------------------------------------------------------------------------
127-
try:
128-
from syncall.google.gcal_side import GCalSide
129-
from syncall.tw_gcal_utils import convert_gcal_to_tw, convert_tw_to_gcal
130-
except ImportError:
131-
__all__.extend(
132-
[
133-
"GCalSide",
134-
"convert_gcal_to_tw",
135-
"convert_tw_to_gcal",
136-
]
137-
)
138-
139-
# gtasks --------------------------------------------------------------------------------------
140-
try:
141-
from syncall.google.gtasks_side import GTasksSide
142-
from syncall.tw_gtasks_utils import convert_gtask_to_tw, convert_tw_to_gtask
143-
except ImportError:
144-
__all__.extend(
145-
[
146-
"GTasksSide",
147-
"convert_gtask_to_tw",
148-
"convert_tw_to_gtask",
149-
]
150-
)
151-
152-
# gkeep ---------------------------------------------------------------------------------------
153-
try:
154-
from syncall.google.gkeep_note import GKeepNote
155-
from syncall.google.gkeep_note_side import GKeepNoteSide
156-
from syncall.google.gkeep_todo_item import GKeepTodoItem
157-
from syncall.google.gkeep_todo_side import GKeepTodoSide
158-
159-
__all__.extend(
160-
[
161-
"GKeepNote",
162-
"GKeepNoteSide",
163-
"GKeepTodoItem",
164-
"GKeepTodoSide",
165-
"convert_gkeep_todo_to_tw",
166-
"convert_tw_to_gkeep_todo",
167-
]
168-
)
169-
except ImportError:
170-
pass
171-
172-
# gkeep <> tw
173-
try:
174-
from syncall.tw_gkeep_utils import convert_gkeep_todo_to_tw, convert_tw_to_gkeep_todo
175-
176-
__all__.extend(
177-
[
178-
"convert_gkeep_todo_to_tw",
179-
"convert_tw_to_gkeep_todo",
180-
]
181-
)
182-
except ImportError:
183-
pass
184-
185-
# filesytem -----------------------------------------------------------------------------------
186-
try:
187-
from syncall.filesystem.filesystem_file import FilesystemFile
188-
from syncall.filesystem.filesystem_side import FilesystemSide
189-
190-
__all__.extend(["FilesystemFile", "FilesystemSide"])
191-
except ImportError:
192-
pass
193-
194-
195-
# filesytem <> gkeep --------------------------------------------------------------------------
196-
try:
197-
from syncall.filesystem_gkeep_utils import (
198-
convert_filesystem_file_to_gkeep_note,
199-
convert_gkeep_note_to_filesystem_file,
200-
)
201-
202-
__all__.extend(
203-
["convert_filesystem_file_to_gkeep_note", "convert_gkeep_note_to_filesystem_file"]
204-
)
205-
except ImportError:
206-
pass
7+
__all__ = ["version", "version_tuple"]

syncall/app_utils.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,9 @@ def get_named_combinations(config_fname: str) -> Sequence[str]:
130130
return list(prefs_manager.keys())
131131

132132

133-
def list_named_combinations(config_fname: str) -> None:
134-
"""List the named configurations currently available for the given configuration name.
135-
136-
Mainly used by the top-level synchronization apps.
137-
"""
138-
logger.success(
139-
format_list(
140-
header="\n\nNamed configurations currently available",
141-
items=get_named_combinations(config_fname=config_fname),
142-
)
143-
)
144-
145-
146-
def fetch_app_configuration(config_fname: str, combination: str) -> Mapping[str, Any]:
133+
def fetch_app_configuration(
134+
side_A_name: str, side_B_name: str, combination: str
135+
) -> Mapping[str, Any]:
147136
"""
148137
Fetch the configuration of a top-level synchronization app.
149138
@@ -155,6 +144,7 @@ def fetch_app_configuration(config_fname: str, combination: str) -> Mapping[str,
155144
It will check whether the configuration file at hand exist and will also give meaningful
156145
errors to the user if the configuration file does not contain the said combination.
157146
"""
147+
config_fname = determine_app_config_fname(side_A_name, side_B_name)
158148
with PrefsManager(app_name=app_name(), config_fname=config_fname) as prefs_manager:
159149
if combination not in prefs_manager:
160150
# config not found ----------------------------------------------------------------
@@ -382,3 +372,18 @@ def teardown():
382372
atexit.register(teardown)
383373

384374
return hooks
375+
376+
377+
def determine_app_config_fname(side_A_name: str, side_B_name: str):
378+
"""
379+
Get the configuration name for the app at hand given the names of the sides involved.
380+
381+
>>> assert determine_app_config_fname("TW", "Google Tasks") == 'tw__google_tasks__configs'
382+
>>> assert determine_app_config_fname("TW", "Google Calendar") == 'tw__google_calendar__configs'
383+
"""
384+
config_fname = (
385+
f'{side_A_name.replace(" ", "_").lower()}'
386+
"__"
387+
f'{side_B_name.replace(" ", "_").lower()}__configs'
388+
)
389+
return config_fname

syncall/cli.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
import sys
99

1010
import click
11-
from bubop import logger
11+
from bubop import format_list, logger
1212

1313
from syncall import __version__
1414
from syncall.app_utils import (
15+
determine_app_config_fname,
1516
error_and_exit,
1617
fetch_from_pass_manager,
18+
get_named_combinations,
1719
name_to_resolution_strategy_type,
1820
)
1921
from syncall.constants import COMBINATION_FLAGS
@@ -484,7 +486,7 @@ def decorator(f):
484486
return decorator
485487

486488

487-
def _opt_default_duration_event_mins():
489+
def opt_default_duration_event_mins():
488490
return click.option(
489491
"--default-event-duration-mins",
490492
"default_event_duration_mins",
@@ -494,12 +496,35 @@ def _opt_default_duration_event_mins():
494496
)
495497

496498

497-
def _opt_list_combinations(name_A: str, name_B: str):
499+
def _list_named_combinations(config_fname: str) -> None:
500+
"""List the named configurations currently available for the given configuration name.
501+
502+
Mainly used by the top-level synchronization apps.
503+
"""
504+
logger.success(
505+
format_list(
506+
header="\n\nNamed configurations currently available",
507+
items=get_named_combinations(config_fname=config_fname),
508+
)
509+
)
510+
511+
512+
def _opt_list_combinations(side_A_name: str, side_B_name: str):
513+
def callback(ctx, param, value):
514+
_list_named_combinations(
515+
config_fname=determine_app_config_fname(
516+
side_A_name=side_A_name, side_B_name=side_B_name
517+
)
518+
)
519+
sys.exit(0)
520+
498521
return click.option(
499522
"--list-combinations",
500523
"do_list_combinations",
501524
is_flag=True,
502-
help=f"List the available named {name_A}<->{name_B} combinations",
525+
expose_value=False,
526+
help=f"List the available named {side_A_name}<->{side_B_name} combinations",
527+
callback=callback,
503528
)
504529

505530

@@ -531,24 +556,24 @@ def _opt_list_resolution_strategies():
531556
)
532557

533558

534-
def _opt_combination(name_A: str, name_B: str):
559+
def _opt_combination(side_A_name: str, side_B_name: str):
535560
return click.option(
536561
COMBINATION_FLAGS[0],
537562
COMBINATION_FLAGS[1],
538563
"combination_name",
539564
type=str,
540-
help=f"Name of an already saved {name_A}<->{name_B} combination",
565+
help=f"Name of an already saved {side_A_name}<->{side_B_name} combination",
541566
)
542567

543568

544-
def _opt_custom_combination_savename(name_A: str, name_B: str):
569+
def _opt_custom_combination_savename(side_A_name: str, side_B_name: str):
545570
return click.option(
546571
"-s",
547572
"--save-as",
548573
"custom_combination_savename",
549574
type=str,
550575
help=(
551-
f"Save the given {name_A}<->{name_B} filters combination using a specified custom"
552-
" name."
576+
f"Save the given {side_A_name}<->{side_B_name} filters combination using a"
577+
" specified custom name."
553578
),
554579
)

0 commit comments

Comments
 (0)