Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.7.1 cleanup #45

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,15 @@ max-complexity = 10
max-line-length = 100
statistics = True
ignore =
# Whitespace before ':'.
E203,
# Line too long (82 > 79 characters).
E501,
# Line break occurred before a binary operator.
W503,
# Invalid escape sequence
W605,
# undefined name name
F821,
# Function is too complex
C901,
# https://docs.python.org/3/tutorial/errors.html#exception-chaining for details
B904,
# camelcase imported as lowercase
N813
# Data class should either be immutable or use __slots__ to save memory
B903
# class name should use CapWords convention
N801
# function name should be lowercase
N802
# exception name should be named with an Error suffix
N818
# line too long
B950
# Module imported but unused
F401
# manually surrounded by quotes, consider using the `!r` conversion flag
B907
B907
7 changes: 0 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,6 @@ repos:
language: system
types: [ python ]
args: [ --py37-plus ]
- id: refurb
name: refurb
description: A tool for refurbishing and modernizing Python codebases.
entry: refurb
language: system
types: [ python ]
args: [ --python-version, "3.7" ]
- id: bandit
name: bandit
entry: bandit
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include LICENSE
include README.md
include CHANGELOG.md
include pyproject.toml
recursive-include tests *
recursive-exclude * __pycache__
recursive-exclude * *.py[cod]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ install:
install-dev:
pip uninstall workedon -y
pip install -e .
pip install -r requirements/dev.txt
pip install -U -r requirements/dev.txt

test:
pytest -rvx --setup-show
Expand Down
39 changes: 27 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,24 @@ Usage: workedon [OPTIONS] COMMAND [ARGS]...
workedon what --past-month

Options:
-v, --version Show the version and exit.
-h, --help Show this message and exit.
-v, --version Show the version and exit.
--print-settings-path Print the location of the settings file.
--print-settings Print all the current settings, including defaults.
--date-format TEXT Set the date format of the output. Must be a valid
Python strftime string. [env var:
WORKEDON_DATE_FORMAT]
--time-format TEXT Set the time format of the output. Must be a valid
Python strftime string. [env var:
WORKEDON_TIME_FORMAT]
--datetime-format TEXT Set the datetime format of the output. Must be a valid
Python strftime string. [env var:
WORKEDON_DATETIME_FORMAT]
--time-zone TEXT Set the timezone of the output. Must be a valid
timezone string. [env var: WORKEDON_TIME_ZONE]
-h, --help Show this message and exit.

Commands:
workedon* Specify what you worked on, with optional date/time.
what Fetch and display logged work.
what Fetch and display logged work.

$ workedon what --help
Usage: what [OPTIONS]
Expand Down Expand Up @@ -194,14 +206,17 @@ Options:
--delete Delete fetched work.
-g, --no-page Don't page the output.
-l, --text-only Output the work log text only.
--date-format TEXT Sets the date format of the output. Must be a valid
Python strftime string.
--time-format TEXT Sets the time format of the output. Must be a valid
Python strftime string.
--datetime-format TEXT Sets the datetime format of the output. Must be a
valid Python strftime string.
--time-zone TEXT Sets the timezone of the output. Must be a valid
timezone string.
--date-format TEXT Set the date format of the output. Must be a valid
Python strftime string. [env var:
WORKEDON_DATE_FORMAT]
--time-format TEXT Set the time format of the output. Must be a valid
Python strftime string. [env var:
WORKEDON_TIME_FORMAT]
--datetime-format TEXT Set the datetime format of the output. Must be a valid
Python strftime string. [env var:
WORKEDON_DATETIME_FORMAT]
--time-zone TEXT Set the timezone of the output. Must be a valid
timezone string. [env var: WORKEDON_TIME_ZONE]
--help Show this message and exit.
```
<!-- [[[end]]] -->
Expand Down
1 change: 0 additions & 1 deletion requirements/lint.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ bandit>=1.7.4
pre-commit-hooks>=4.3.0
pyupgrade>=3.3.1
cogapp>=3.3.0
refurb>=1.15.0
164 changes: 88 additions & 76 deletions workedon/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Console script for workedon."""
import functools

import warnings

import click
Expand All @@ -8,116 +8,97 @@
from . import __version__ as _version
from .conf import CONF_PATH, settings
from .models import DB_PATH, Work, get_or_create_db
from .utils import load_settings
from .utils import add_options, load_settings
from .workedon import fetch_work, save_work

warnings.filterwarnings("ignore")
CONTEXT_SETTINGS = dict(help_option_names=["-h", "--help"])


def settings_options(func):
@click.option(
settings_options = [
click.option(
"--date-format",
"DATE_FORMAT",
required=False,
default="",
type=click.STRING,
envvar="WORKEDON_DATE_FORMAT",
help="Sets the date format of the output. Must be a valid Python strftime string.",
)
@click.option(
show_envvar=True,
help="Set the date format of the output. Must be a valid Python strftime string.",
),
click.option(
"--time-format",
"TIME_FORMAT",
required=False,
default="",
type=click.STRING,
envvar="WORKEDON_TIME_FORMAT",
help="Sets the time format of the output. Must be a valid Python strftime string.",
)
@click.option(
show_envvar=True,
help="Set the time format of the output. Must be a valid Python strftime string.",
),
click.option(
"--datetime-format",
"DATETIME_FORMAT",
required=False,
default="",
type=click.STRING,
envvar="WORKEDON_DATETIME_FORMAT",
help="Sets the datetime format of the output. Must be a valid Python strftime string.",
)
@click.option(
show_envvar=True,
help="Set the datetime format of the output. Must be a valid Python strftime string.",
),
click.option(
"--time-zone",
"TIME_ZONE",
required=False,
default="",
type=click.STRING,
envvar="WORKEDON_TIME_ZONE",
help="Sets the timezone of the output. Must be a valid timezone string.",
)
@functools.wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper
show_envvar=True,
help="Set the timezone of the output. Must be a valid timezone string.",
),
]


@click.group(
cls=DefaultGroup,
default="workedon",
default_if_no_args=True,
context_settings=CONTEXT_SETTINGS,
invoke_without_command=True,
)
@click.version_option(_version, "-v", "--version")
def main():
"""
Work tracking from your shell.

\b
Example usages:
1. Logging work:
workedon painting the garage
workedon studying for the SAT @ June 23 2010
workedon pissing my wife off @ 2pm yesterday

\b
2. Fetching work:
workedon what
workedon what --from "2pm yesterday" --to "9am today"
workedon what --today
workedon what --past-month
"""
pass


@main.command(default=True)
@click.argument(
"stuff",
metavar="<what_you_worked_on>",
nargs=-1,
@click.option(
"--print-settings-path",
"settings_path",
is_flag=True,
required=False,
type=click.STRING,
default=False,
show_default=True,
help="Print the location of the settings file.",
)
@click.option(
"--print-settings",
"print_settings",
is_flag=True,
required=False,
default=False,
show_default=True,
help="Print all the current settings, including defaults.",
)
@click.option(
"--print-settings-path",
"settings_path",
"--db-version",
is_flag=True,
required=False,
default=False,
show_default=True,
help="Print the location of the settings file.",
hidden=True,
help="Print the version of SQLite being used.",
)
@click.option(
"--print-db-path",
"db_path",
is_flag=True,
required=False,
default=False,
show_default=True,
hidden=True,
help="Print the location of the database file.",
)
@click.option(
Expand All @@ -126,6 +107,7 @@ def main():
required=False,
default=False,
show_default=True,
hidden=True,
help="Execute the VACUUM command on the database to reclaim some space.",
)
@click.option(
Expand All @@ -134,34 +116,43 @@ def main():
required=False,
default=False,
show_default=True,
hidden=True,
help="Delete all data since the beginning of time.",
)
@click.option(
"--db-version",
is_flag=True,
required=False,
default=False,
show_default=True,
help="Print the version of SQLite being used.",
)
@settings_options
@add_options(settings_options)
@click.pass_context
@load_settings
def workedon(
stuff, settings_path, print_settings, db_path, vacuum_db, truncate_db, db_version, **kwargs
def main(
ctx,
settings_path,
print_settings,
db_version,
print_db_path,
vacuum_db,
truncate_db,
**kwargs,
):
"""
Specify what you worked on, with optional date/time. See examples.
Work tracking from your shell.

\b
Example usages:
1. Logging work:
workedon painting the garage
workedon studying for the SAT @ June 23 2010
workedon pissing my wife off @ 2pm yesterday

Options are for advanced users only.
\b
2. Fetching work:
workedon what
workedon what --from "2pm yesterday" --to "9am today"
workedon what --today
workedon what --past-month
"""
if settings_path:
return click.echo(CONF_PATH)
elif print_settings:
for key, value in settings.items():
if key.isupper():
click.echo(f'{key}="{value}"')
if ctx.invoked_subcommand:
return
elif db_path:

if print_db_path:
return click.echo(DB_PATH)
elif vacuum_db:
click.echo("Performing VACUUM...")
Expand All @@ -175,8 +166,29 @@ def workedon(
elif db_version:
server_version = ".".join([str(num) for num in get_or_create_db().server_version])
return click.echo(f"SQLite version: {server_version}")
else:
save_work(stuff)
elif print_settings:
for key, value in settings.items():
if key.isupper():
click.echo(f'{key}="{value}"')
elif settings_path:
return click.echo(CONF_PATH)


@main.command(hidden=True)
@click.argument(
"stuff",
metavar="<what_you_worked_on>",
nargs=-1,
required=False,
type=click.STRING,
)
@add_options(settings_options)
@load_settings
def workedon(stuff, **kwargs):
"""
Specify what you worked on, with optional date/time. See workedon --help.
"""
save_work(stuff)


@main.command()
Expand Down Expand Up @@ -319,7 +331,7 @@ def workedon(
show_default=True,
help="Output the work log text only.",
)
@settings_options
@add_options(settings_options)
@load_settings
def what(
count,
Expand Down
Loading
Loading