Skip to content

Commit

Permalink
Enable custom TW filters + virtual tags
Browse files Browse the repository at this point in the history
* For apps that interact with Taskwarrior there's a `-f`/`--tw-filter`
  option to specify a custom TW filter - exactly the same way as you'd
  specify it in the command line.

   ```sh
   tw_gtasks_sync  -l kalivradia -t kalimera  -f "+OVERDUE description.startswith:somestring"
   ```

* For debugging purposes introduce a --pdb-on-error flag to assist
  debugging the end-user applications

* Resturcture the command line parameters of the end-user apps
   Instead of passing each one of the arguments via a dedicated
   separators apps now use bundles of CLI params. Example:

   Before:

   ````python
   @click.command()
   @opt_gkeep_labels()
   @opt_gkeep_passwd_pass_path()
   @opt_gkeep_token_pass_path()
   @opt_gkeep_user_pass_path()
   main( ... )
   ```

   After:
   ```python
   @click.command()
   opts_gkeep()
   main( ...)
   ```

   Mark the specific cli.py::opt_ click decorators as internal

* tw: Use taskw_ng 0.2.1 and switch to taskw_ng package name
* Remove top-level __init__.py global imports.

   It was an extra effort maintaining them and there wasn't much of
   value
* Fix bug when combination filename contains a dot - allow config
  filenames such as
  `kalivradia__+OVERDUE%20description.startswith%3AE__None__kalimera.yaml`

This commit also includes:

* Format generate-shell-completions.sh with Shfmt
* Don't expose the list_resolution_strategies option to the apps.
* End all click option help strings with a dot for consistency
  • Loading branch information
bergercookie committed Jan 22, 2024
1 parent b56718f commit 0893f12
Show file tree
Hide file tree
Showing 18 changed files with 1,341 additions and 1,446 deletions.
603 changes: 294 additions & 309 deletions poetry.lock

Large diffs are not rendered by default.

12 changes: 4 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ gkeepapi = { version = "^0.13.7", optional = true }
asana = { version = "^1.0.0", optional = true }
caldav = { version = "^0.11.0", optional = true }
icalendar = { version = "^5.0.3", optional = true }
taskw = { version = "^1.3.1", optional = true }
taskw-ng = { version = "0.2.1", optional = true }
# taskw-ng = { path = "/home/berger/src_/taskw-ng", develop = true }
xattr = { version = "^0.9.9", optional = true }
xdg = { version = "^6.0.0", optional = true }

Expand All @@ -87,7 +88,7 @@ gkeep = ["gkeepapi"]
notion = ["notion-client"]
asana = ["asana"]
caldav = ["caldav", "icalendar"]
tw = ["taskw", "xdg"]
tw = ["taskw-ng", "xdg"]
fs = ["xattr"]

# dev dependencies -------------------------------------------------------------
Expand All @@ -112,12 +113,9 @@ coveralls = "^3.3.1"
pycln = "^1.3.1"
check-jsonschema = "^0.14.3"
# readline = "6.2.4.1"

# isort ------------------------------------------------------------------------

[tool.poetry.group.dev.dependencies]
ruff = "^0.1.5"

# isort ------------------------------------------------------------------------
[tool.isort]
include_trailing_comma = true
line_length = 95
Expand All @@ -142,8 +140,6 @@ module = [
"pytest",
"pexpect",
"notion_client",
"taskw",
"taskw.warrior",
"google.auth.transport.requests",
"google_auth_oauthlib.flow",
]
Expand Down
65 changes: 33 additions & 32 deletions scripts/generate-shell-completions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,70 @@ set -e

# helpers ----------------------------------------------------------------------
function finish {
tabs 8
tabs 8
}
trap finish EXIT

function inside_virtualenv() {
python3 -qc "import sys; sys.exit(0 if sys.prefix != sys.base_prefix else 1)"
python3 -qc "import sys; sys.exit(0 if sys.prefix != sys.base_prefix else 1)"
}

function inside_git_repo() {
git rev-parse
git rev-parse
}

function completion_dir_for() {
dir_=$completions_dir/$1
mkdir -p $dir_
echo "$dir_/$2"
dir_=$completions_dir/$1
mkdir -p $dir_
echo "$dir_/$2"
}

function get_ext_for() {
if [[ "$1" == "bash" || "$1" == "zsh" ]]; then
echo ".sh"
elif [[ "$1" == "fish" ]]; then
echo ".fish"
else
echo ""
fi
if [[ $1 == "bash" || $1 == "zsh" ]]; then
echo ".sh"
elif [[ $1 == "fish" ]]; then
echo ".fish"
else
echo ""
fi
}

# sanity checks ----------------------------------------------------------------
if ! inside_virtualenv; then
echo "You are not inside a virtualenv, can't proceed. Run "poetry shell" first".
exit 1
echo "You are not inside a virtualenv, can't proceed. Run "poetry shell" first".
exit 1
fi

if ! inside_git_repo; then
echo "You are not inside a git repo..."
exit 1
echo "You are not inside a git repo..."
exit 1
fi

git_root_dir=$(git rev-parse --show-toplevel)
this_file="$git_root_dir/scripts/generate-shell-completions.sh"

if [[ $(basename $git_root_dir) != "syncall" ]]; then
echo "This isn't the syncall repo -> $git_root_dir"
exit 1
if ! test -f "$this_file"; then
echo "This doesn't seem to be the syncall repo -> $git_root_dir"
exit 1
fi

completions_dir="${git_root_dir}/completions"
mkdir -p $completions_dir

# main loop --------------------------------------------------------------------
for exec in tw_gkeep_sync tw_notion_sync tw_gcal_sync tw_asana_sync tw_caldav_sync fs_gkeep_sync tw_gtasks_sync; do
tabs 4
# Run the following, grab the output and dumpt it to the completions/ files...
# _TW_GKEEP_SYNC_COMPLETE=fish_source tw_gkeep_sync
envvar="_$(echo $exec | tr "[:lower:]" "[:upper:]")_COMPLETE"
for shell in "bash" "zsh" "fish"; do
echo -e "Generating completions for [$exec\t| $shell\t]"
tabs 4
# Run the following, grab the output and dumpt it to the completions/ files...
# _TW_GKEEP_SYNC_COMPLETE=fish_source tw_gkeep_sync
envvar="_$(echo $exec | tr "[:lower:]" "[:upper:]")_COMPLETE"
for shell in "bash" "zsh" "fish"; do
echo -e "Generating completions for [$exec\t| $shell\t]"

# Execute command, grab its output, redirect it to file.
export $envvar=${shell}_source
contents=$($exec)
# Execute command, grab its output, redirect it to file.
export $envvar=${shell}_source
contents=$($exec)

path="$(completion_dir_for $shell $exec)$(get_ext_for $shell)"
echo "$contents" > "$path"
done
path="$(completion_dir_for $shell $exec)$(get_ext_for $shell)"
echo "$contents" > "$path"
done
done
205 changes: 3 additions & 202 deletions syncall/__init__.py
Original file line number Diff line number Diff line change
@@ -1,206 +1,7 @@
"""__init__"""

# global imports ------------------------------------------------------------------------------
from syncall.__version__ import __version__, __version_tuple__
from syncall.aggregator import Aggregator
from syncall.app_utils import (
app_name,
cache_or_reuse_cached_combination,
fetch_app_configuration,
fetch_from_pass_manager,
get_config_name_for_args,
get_resolution_strategy,
inform_about_app_extras,
inform_about_combination_name_usage,
list_named_combinations,
name_to_resolution_strategy_type,
report_toplevel_exception,
)
from syncall.cli import (
opt_asana_task_gid,
opt_asana_token_pass_path,
opt_asana_workspace_gid,
opt_asana_workspace_name,
opt_combination,
opt_custom_combination_savename,
opt_filesystem_root,
opt_gcal_calendar,
opt_gkeep_labels,
opt_gkeep_note,
opt_gkeep_passwd_pass_path,
opt_gkeep_user_pass_path,
opt_google_oauth_port,
opt_google_secret_override,
opt_gtasks_list,
opt_list_asana_workspaces,
opt_list_combinations,
opt_notion_page_id,
opt_notion_token_pass_path,
opt_resolution_strategy,
opt_tw_project,
opt_tw_tags,
)
from syncall.sync_side import ItemType, SyncSide
from syncall.__version__ import __version__ as version
from syncall.__version__ import __version_tuple__ as version_tuple

__all__ = [
"__version__",
"__version_tuple__",
"Aggregator",
"ItemType",
"SyncSide",
"app_name",
"cache_or_reuse_cached_combination",
"fetch_app_configuration",
"fetch_from_pass_manager",
"get_config_name_for_args",
"inform_about_app_extras",
"inform_about_combination_name_usage",
"list_named_combinations",
"get_resolution_strategy",
"name_to_resolution_strategy_type",
"opt_asana_task_gid",
"opt_asana_token_pass_path",
"opt_asana_workspace_gid",
"opt_asana_workspace_name",
"opt_combination",
"opt_custom_combination_savename",
"opt_gcal_calendar",
"opt_gtasks_list",
"opt_gkeep_note",
"opt_gkeep_passwd_pass_path",
"opt_gkeep_user_pass_path",
"opt_google_oauth_port",
"opt_google_secret_override",
"opt_list_asana_workspaces",
"opt_list_combinations",
"opt_notion_page_id",
"opt_notion_token_pass_path",
"opt_resolution_strategy",
"opt_tw_project",
"opt_filesystem_root",
"opt_tw_tags",
"opt_gkeep_labels",
"report_toplevel_exception",
]

# asana ----------------------------------------------------------------------------------------
try:
from syncall.asana.asana_side import AsanaSide
from syncall.asana.utils import list_asana_workspaces
from syncall.tw_asana_utils import convert_asana_to_tw, convert_tw_to_asana

__all__.extend(
["AsanaSide", "convert_asana_to_tw", "convert_tw_to_asana", "list_asana_workspaces"]
)
except ImportError:
pass

# tw ------------------------------------------------------------------------------------------
try:
from syncall.taskwarrior.taskwarrior_side import TaskWarriorSide

__all__.extend(
[
"TaskWarriorSide",
]
)
except ImportError:
pass

# notion --------------------------------------------------------------------------------------
try:
from syncall.notion.notion_side import NotionSide

__all__.extend(["NotionSide"])
except ImportError:
pass

# notion <> tw --------------------------------------------------------------------------------
try:
from syncall.tw_notion_utils import convert_notion_to_tw, convert_tw_to_notion

__all__.extend(["convert_notion_to_tw", "convert_tw_to_notion"])
except ImportError:
pass

# gcal ----------------------------------------------------------------------------------------
try:
from syncall.google.gcal_side import GCalSide
from syncall.tw_gcal_utils import convert_gcal_to_tw, convert_tw_to_gcal
except ImportError:
__all__.extend(
[
"GCalSide",
"convert_gcal_to_tw",
"convert_tw_to_gcal",
]
)

# gtasks --------------------------------------------------------------------------------------
try:
from syncall.google.gtasks_side import GTasksSide
from syncall.tw_gtasks_utils import convert_gtask_to_tw, convert_tw_to_gtask
except ImportError:
__all__.extend(
[
"GTasksSide",
"convert_gtask_to_tw",
"convert_tw_to_gtask",
]
)

# gkeep ---------------------------------------------------------------------------------------
try:
from syncall.google.gkeep_note import GKeepNote
from syncall.google.gkeep_note_side import GKeepNoteSide
from syncall.google.gkeep_todo_item import GKeepTodoItem
from syncall.google.gkeep_todo_side import GKeepTodoSide

__all__.extend(
[
"GKeepNote",
"GKeepNoteSide",
"GKeepTodoItem",
"GKeepTodoSide",
"convert_gkeep_todo_to_tw",
"convert_tw_to_gkeep_todo",
]
)
except ImportError:
pass

# gkeep <> tw
try:
from syncall.tw_gkeep_utils import convert_gkeep_todo_to_tw, convert_tw_to_gkeep_todo

__all__.extend(
[
"convert_gkeep_todo_to_tw",
"convert_tw_to_gkeep_todo",
]
)
except ImportError:
pass

# filesytem -----------------------------------------------------------------------------------
try:
from syncall.filesystem.filesystem_file import FilesystemFile
from syncall.filesystem.filesystem_side import FilesystemSide

__all__.extend(["FilesystemFile", "FilesystemSide"])
except ImportError:
pass


# filesytem <> gkeep --------------------------------------------------------------------------
try:
from syncall.filesystem_gkeep_utils import (
convert_filesystem_file_to_gkeep_note,
convert_gkeep_note_to_filesystem_file,
)

__all__.extend(
["convert_filesystem_file_to_gkeep_note", "convert_gkeep_note_to_filesystem_file"]
)
except ImportError:
pass
__all__ = ["version", "version_tuple"]
Loading

0 comments on commit 0893f12

Please sign in to comment.