Skip to content

Commit

Permalink
minor cleanup (#114)
Browse files Browse the repository at this point in the history
* do not throw exception when DB does not exist
* remove Scrutinizer
* add ruff linter, add doctest coverage, remove lint
* add pytest-cov
  • Loading branch information
AlexanderWillner committed May 22, 2023
1 parent efb0493 commit f1b1a01
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
make deps-install
- name: Run tests
run: |
pip install coverage pytest
pip install coverage pytest pytest-cov
make test testdoc
- name: "Upload coverage to Codecov"
if: github.repository == 'thingsapi/things.py'
Expand All @@ -34,6 +34,6 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Run lint
run: |
pip install black pycodestyle pylama pylint flake8 mypy pydocstyle vulture pytest
pip install black pycodestyle pylama pylint flake8 mypy pydocstyle vulture pytest ruff
sudo npm install -g pyright
make lint
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ package-lock.json
package.json
env
.vscode
coverage.xml

9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ test: ## Test the code
@coverage html

testdoc: ## Test the code within the documentation
@coverage erase
@type pytest >/dev/null 2>&1 || (echo "Run '$(PIP) install pytest' first." >&2 ; exit 1)
THINGSDB=tests/main.sqlite pytest --doctest-modules
THINGSDB=tests/main.sqlite pytest --cov=things -W ignore::UserWarning --cov-report=xml --cov-context=test --doctest-modules
@coverage report
@coverage html

.PHONY: doc
doc: install ## Document the code
Expand All @@ -57,6 +60,7 @@ clean: ## Cleanup
@rm -rf .mypy_cache/ */.mypy_cache/
@rm -f .coverage
@rm -rf .tox
@rm -rf .ruff_cache

auto-style: ## Style the code
@if type isort >/dev/null 2>&1 ; then isort . ; \
Expand Down Expand Up @@ -85,6 +89,9 @@ code-lint: code-style ## Lint the code
@echo Pylint...
@if type pylint >/dev/null 2>&1 ; then pylint -sn *.py $(SRC_CORE) $(SRC_TEST) ; \
else echo "SKIPPED. Run '$(PIP) install pylint' first." >&2 ; fi
@echo Ruff...
@if type ruff >/dev/null 2>&1 ; then ruff check . ; \
else echo "SKIPPED. Run '$(PIP) install ruff' first." >&2 ; fi
@echo Flake...
@if type flake8 >/dev/null 2>&1 ; then flake8 . ; \
else echo "SKIPPED. Run '$(PIP) install flake8' first." >&2 ; fi
Expand Down
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pylama = "*"
pylint = "*"
pyright = "*"
pytest = "*"
pytest-cov = "*"
ruff = "*"
vulture = "*"

[requires]
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ _things.py_ is a simple Python 3 library to read data from your [Things app](htt
[![Build Status](https://github.com/thingsapi/things.py/workflows/Build-Test/badge.svg)](https://github.com/thingsapi/things.py/actions)
[![Coverage Status](https://codecov.io/gh/thingsapi/things.py/branch/main/graph/badge.svg?token=DBWGKAEYAP)](https://codecov.io/gh/thingsapi/things.py)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=thingsapi_things.py&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=thingsapi_things.py)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/thingsapi/things.py/badges/quality-score.png?b=main)](https://scrutinizer-ci.com/g/thingsapi/things.py/?branch=main)
[![GitHub Issues](https://img.shields.io/github/issues/thingsapi/things.py)](https://github.com/thingsapi/things.py/issues)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/things.py?label=pypi%20downloads)](https://pypi.org/project/things.py/)
Expand Down
Binary file modified tests/main.sqlite-shm
Binary file not shown.
62 changes: 34 additions & 28 deletions things/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,28 @@
import re
import sqlite3
from textwrap import dedent
from typing import Optional
from typing import Optional, Union


# --------------------------------------------------
# Core constants
# --------------------------------------------------


# Database filepath
DEFAULT_FILEROOT = os.path.expanduser(
# Database filepath with glob pattern for version 3.15.16+
DEFAULT_FILEPATH_31616502 = (
"~/Library/Group Containers/JLMPQHK86H.com.culturedcode.ThingsMac"
"/ThingsData-*/Things Database.thingsdatabase/main.sqlite"
)
# Migration for April 2023 update
if os.path.isfile(f"{DEFAULT_FILEROOT}/Things Database.thingsdatabase"):
for filename in glob.glob(os.path.join(DEFAULT_FILEROOT, "ThingsData-*")):
DEFAULT_FILEROOT = filename
DEFAULT_FILEPATH = f"{DEFAULT_FILEROOT}/Things Database.thingsdatabase/main.sqlite"
DEFAULT_FILEPATH_31516502 = (
"~/Library/Group Containers/JLMPQHK86H.com.culturedcode.ThingsMac"
"/Things Database.thingsdatabase/main.sqlite"
)

try:
DEFAULT_FILEPATH = next(glob.iglob(os.path.expanduser(DEFAULT_FILEPATH_31616502)))
except StopIteration:
DEFAULT_FILEPATH = os.path.expanduser(DEFAULT_FILEPATH_31516502)

This comment has been minimized.

Copy link
@mikez

mikez May 22, 2023

Contributor

@AlexanderWillner The numbers 31516502 and 31616502 I just made up as "to be replaced". We may want to replace them with the actual version numbers where these changes were introduced, or not... ;)

This comment has been minimized.

Copy link
@AlexanderWillner

AlexanderWillner May 23, 2023

Author Contributor

the numbers sounded reasonable ;)

ENVIRONMENT_VARIABLE_WITH_FILEPATH = "THINGSDB"

Expand Down Expand Up @@ -197,24 +202,24 @@ def __init__(self, filepath=None, print_sql=False):

def get_tasks( # pylint: disable=R0914
self,
uuid=None,
type=None, # pylint: disable=W0622
status=None,
start=None,
area=None,
project=None,
heading=None,
tag=None,
start_date=None,
stop_date=None,
deadline=None,
deadline_suppressed=None,
trashed=False,
context_trashed=False,
last=None,
search_query=None,
index="index",
count_only=False,
uuid: Optional[str] = None,
type: Optional[str] = None, # pylint: disable=W0622
status: Optional[str] = None,
start: Optional[str] = None,
area: Optional[Union[str, bool]] = None,
project: Optional[Union[str, bool]] = None,
heading: Optional[str] = None,
tag: Optional[Union[str, bool]] = None,
start_date: Optional[Union[str, bool]] = None,
stop_date: Optional[Union[str, bool]] = None,
deadline: Optional[Union[str, bool]] = None,
deadline_suppressed: Optional[bool] = None,
trashed: Optional[bool] = False,
context_trashed: Optional[bool] = False,
last: Optional[str] = None,
search_query: Optional[str] = None,
index: str = "index",
count_only: bool = False,
):
"""Get tasks. See `things.api.tasks` for details on parameters."""
if uuid:
Expand Down Expand Up @@ -799,8 +804,9 @@ def make_search_filter(query: Optional[str]) -> str:
Example:
--------
>>> make_search_filter('dinner') #doctest: +REPORT_NDIFF
"AND (TASK.title LIKE '%dinner%' OR TASK.notes LIKE '%dinner%' OR AREA.title LIKE '%dinner%')"
>>> make_search_filter('dinner')
"AND (TASK.title LIKE '%dinner%' OR TASK.notes LIKE '%dinner%' OR \
AREA.title LIKE '%dinner%')"
"""
if not query:
return ""
Expand Down

0 comments on commit f1b1a01

Please sign in to comment.