Skip to content

Commit

Permalink
Add simple pre-commit hook and run it
Browse files Browse the repository at this point in the history
  • Loading branch information
SqAtx committed Mar 17, 2024
1 parent bd8028e commit 08a2958
Show file tree
Hide file tree
Showing 81 changed files with 413 additions and 421 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.10
uses: actions/setup-python@v2
with:
python-version: "3.10"
- name: Install dependencies

# Note: we could try and cache the pre-commit environment
# See the pre-commit docs at https://pre-commit.com/#github-actions-example
- name: Run pre-commit hooks
run: |
python -m pip install --upgrade pip
pip install pre-commit
pre-commit run --all-files
- name: Install dependencies
run: |
sudo apt-get update
sudo apt install -y libgirepository1.0-dev gir1.2-gtk-4.0 libgtksourceview-5-dev
pip install --user -e git+https://github.com/getting-things-gnome/liblarch.git#egg=liblarch
pip install --user pytest pycairo PyGObject caldav lxml
- name: Run unit tests with Pytest

run: |
./run-tests
1 change: 0 additions & 1 deletion .github/workflows/weekly_flatpak.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ jobs:
bundle: org.gnome.GTG.Devel.flatpak
manifest-path: build-aux/org.gnome.GTG.Devel.json
cache-key: flatpak-builder-${{ github.sha }}

10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
3 changes: 1 addition & 2 deletions GTG/backends/unmaintained/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ and support them.
If you are interested in taking over one of these, let us know in the bug
tracker!

---
---

Evolution synchronization service has dependencies:
* python3-evolution
Expand All @@ -27,4 +27,3 @@ version of Tweety library.

Remember the Milk synchronization service is shipped with a library for RTM api. It has an external dependency:
* python3-dateutil

2 changes: 1 addition & 1 deletion GTG/core/base_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def remove(self, item_id: UUID) -> None:
"""Remove an existing item from the store."""

item = self.lookup[item_id]

try:
parent = item.parent

Expand Down
20 changes: 10 additions & 10 deletions GTG/core/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,13 @@ def count_tasks(count: dict, tasklist: list):
'closed': {'all': 0, 'untagged': 0},
}

count_tasks(self.task_count['open'],
count_tasks(self.task_count['open'],
self.tasks.filter(Filter.ACTIVE))

count_tasks(self.task_count['closed'],
count_tasks(self.task_count['closed'],
self.tasks.filter(Filter.CLOSED))

count_tasks(self.task_count['actionable'],
count_tasks(self.task_count['actionable'],
self.tasks.filter(Filter.ACTIONABLE))


Expand All @@ -259,7 +259,7 @@ def refresh_tag_stats(self) -> None:

def notify_tag_change(self, tag) -> None:
"""Notify tasks that this tag has changed."""

for task in self.tasks.lookup.values():
if tag in task.tags:
task.notify('icons')
Expand All @@ -280,14 +280,14 @@ def do_first_run_versioning(self, filepath: str) -> None:
"""If there is an old file around needing versioning, convert it, then rename the old file."""

old_path = self.find_old_path(DATA_DIR)

if old_path is not None:
log.warning('Found old file: %r. Running versioning code.', old_path)
tree = versioning.convert(old_path, self)
self.load_data(tree)
self.save(filepath)
os.rename(old_path, old_path + '.imported')

else:
self.first_run(self.data_path)

Expand All @@ -297,13 +297,13 @@ def find_old_path(self, datadir: str) -> None | str:

# used by which version?
path = os.path.join(datadir, 'gtg_tasks.xml')

if os.path.isfile(path):
return path

# used by (at least) 0.3.1-4
path = os.path.join(datadir, 'projects.xml')

if os.path.isfile(path):
return self.find_old_uuid_path(path)

Expand All @@ -315,7 +315,7 @@ def find_old_uuid_path(self, path: str) -> None | str:

with open(path, 'r') as stream:
xml_tree = et.parse(stream)

for backend in xml_tree.findall('backend'):
module = backend.get('module')
if module == 'backend_localfile':
Expand Down
18 changes: 9 additions & 9 deletions GTG/core/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

def unwrap(row, expected_type):
"""Find an item in TreeRow widget (sometimes nested)."""

item = row.get_item()

while type(item) is not expected_type:
item = item.get_item()

Expand Down Expand Up @@ -58,7 +58,7 @@ def do_match(self, item) -> bool:

else:
return True


class TaskPaneFilter(Gtk.Filter):
__gtype_name__ = 'TaskPaneFilter'
Expand Down Expand Up @@ -90,13 +90,13 @@ def get_children(children: set) -> None:

if tag.children:
get_children(tag.children)

return result


def match_tags(self, task: Task) -> bool:
"""Match selected tags to task tags."""

all_tags = self.expand_tags()
return len(all_tags.intersection(set(task.tags))) >= len(self.tags)

Expand All @@ -108,7 +108,7 @@ def do_match(self, item) -> bool:
show = task.status is Status.ACTIVE
elif self.pane == 'workview':
show = task.is_actionable

if self.expand:
item.set_expanded(True)
self.expand = False
Expand Down Expand Up @@ -144,7 +144,7 @@ def __init__(self, ds, pane):

def set_query(self, query: str) -> None:
self.query = query

try:
self.checks = search.parse_search_query(query)
except search.InvalidQuery:
Expand All @@ -153,7 +153,7 @@ def set_query(self, query: str) -> None:

def match_tags(self, task: Task) -> bool:
"""Match selected tags to task tags."""

return len(self.tags.intersection(set(task.tags))) >= len(self.tags)


Expand All @@ -179,4 +179,4 @@ def do_match(self, item) -> bool:

return search.search_filter(task, self.checks)
else:
return False
return False
2 changes: 1 addition & 1 deletion GTG/core/firstrun_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,5 +410,5 @@ def generate() -> etree.Element:
tag_tag = etree.SubElement(taglist, 'tag')
tag_tag.set('id', tid)
tag_tag.set('name', tag)

return etree.ElementTree(root)
2 changes: 1 addition & 1 deletion GTG/core/info.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ AUTHORS_RELEASE_CONTRIBUTORS = """
• François Schmidts
• Sebastian Grabowski
• Fridolin Weisser
• Tommy Priest
• Tommy Priest
• Laurent Combe
• Smitty
• Tiziana Sellitto
Expand Down
4 changes: 2 additions & 2 deletions GTG/core/plugins/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self,
self.app = app
self.ds = app.ds
self.browser = app.browser

self.selection_changed_callback_listeners = []

if taskeditor:
Expand All @@ -60,7 +60,7 @@ def __init__(self,
else:
self.__ui = self.browser
self.__task_id = None

for pane in self.browser.panes.values():
pane.task_selection.connect('selection-changed', self.__selection_changed, pane)

Expand Down
2 changes: 1 addition & 1 deletion GTG/core/saved_searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def new(self, name: str, query: str, parent: UUID = None) -> SavedSearch:
self.model.append(search)

return search


def add(self, item, parent_id: UUID = None) -> None:
"""Add a tag to the tagstore."""
Expand Down
19 changes: 9 additions & 10 deletions GTG/core/sorters.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

def unwrap(row, expected_type):
"""Find an item in TreeRow widget (sometimes nested)."""

item = row

while type(item) is not expected_type:
item = item.get_item()

Expand All @@ -40,7 +40,7 @@ def __init__(self):


def do_compare(self, a, b) -> Gtk.Ordering:

a = unwrap(a, Task)
b = unwrap(b, Task)

Expand All @@ -63,7 +63,7 @@ def __init__(self):


def do_compare(self, a, b) -> Gtk.Ordering:

a = unwrap(a, Task)
b = unwrap(b, Task)

Expand All @@ -86,7 +86,7 @@ def __init__(self):


def do_compare(self, a, b) -> Gtk.Ordering:

a = unwrap(a, Task)
b = unwrap(b, Task)

Expand All @@ -109,7 +109,7 @@ def __init__(self):


def do_compare(self, a, b) -> Gtk.Ordering:

a = unwrap(a, Task)
b = unwrap(b, Task)

Expand All @@ -133,14 +133,14 @@ def __init__(self):

def get_first_letter(self, tags) -> str:
"""Get first letter of the first tag in a set of tags."""

# Fastest way to get the first item
# on a set in Python
for t in tags:
return t.name[0]

def do_compare(self, a, b) -> Gtk.Ordering:

a = unwrap(a, Task)
b = unwrap(b, Task)

Expand Down Expand Up @@ -170,7 +170,7 @@ def __init__(self):


def do_compare(self, a, b) -> Gtk.Ordering:

a = unwrap(a, Task)
b = unwrap(b, Task)

Expand All @@ -183,4 +183,3 @@ def do_compare(self, a, b) -> Gtk.Ordering:
return Gtk.Ordering.SMALLER
else:
return Gtk.Ordering.EQUAL

10 changes: 5 additions & 5 deletions GTG/core/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def has_icon(self) -> bool:

return self._icon


@GObject.Property(type=int, default=0)
def task_count_open(self) -> int:

Expand Down Expand Up @@ -174,8 +174,8 @@ def get_ancestors(self) -> List['Tag']:

def __hash__(self):
return id(self)


class TagStore(BaseStore):
"""A tree of tags."""

Expand Down Expand Up @@ -219,7 +219,7 @@ def __str__(self) -> str:
def get_all_tag_names(self) -> List[str]:
"""Return all tag names."""
return list(self.lookup_names.keys())


def find(self, name: str) -> Tag:
"""Get a tag by name."""
Expand Down Expand Up @@ -340,7 +340,7 @@ def rand_color() -> str:
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)

return f'#{r:02x}{g:02x}{b:02x}'

color = rand_color()
Expand Down
Loading

0 comments on commit 08a2958

Please sign in to comment.