1
0

Ruff
Some checks failed
Test Python / Test (push) Failing after 25s

This commit is contained in:
Jon Michael Aanes 2024-09-28 14:13:51 +02:00
parent 3e5b4cd7b8
commit f448ee5eb8
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
6 changed files with 44 additions and 23 deletions

View File

@ -2,6 +2,7 @@
Implements methods for interacting with the [Favro API](https://favro.com/developer/).
"""
import dataclasses
from collections.abc import Iterator
from logging import getLogger
@ -156,22 +157,26 @@ class FavroClient:
)
def update_card_contents_locally(
self, card_id: CardId, card_contents: CardContents,
self,
card_id: CardId,
card_contents: CardContents,
) -> Card | None:
if card := self.cache.remove(card_id):
card = dataclasses.replace(
card,
detailed_description=card_contents.description,
name=card_contents.name,
tags=[], # TODO?
assignments=[], # TODO?
dependencies=[], # TODO
tags=[], # TODO?
assignments=[], # TODO?
dependencies=[], # TODO
)
self.cache.add_card(card)
return card
def update_card_contents(
self, card_id: CardId, card_contents: CardContents,
self,
card_id: CardId,
card_contents: CardContents,
) -> Card | None:
"""Returns updated Card."""
if self.read_only == 'silent':

View File

@ -3,6 +3,7 @@
Based on the descriptions on the [Favro API Specification
Page](https://favro.com/developer/), and observed behaviour.
"""
import dataclasses
import datetime
from typing import Any
@ -93,13 +94,13 @@ class TagInfo:
@dataclasses.dataclass(frozen=True)
class CustomField:
custom_field_id: CustomFieldId
value: list[str] # TODO
value: list[str] # TODO
@staticmethod
def from_json(json: dict[str, Any]) -> 'CustomField':
return CustomField(
CustomFieldId(json['customFieldId']),
json['value'], # TODO
CustomFieldId(json['customFieldId']),
json['value'], # TODO
)
@ -154,11 +155,15 @@ class Card:
name=json['name'],
todo_list_user_id=todo_list_user_id,
todo_list_completed=json.get('todoListCompleted'),
dependencies=[CardDependency.from_json(dep) for dep in json['dependencies']],
dependencies=[
CardDependency.from_json(dep) for dep in json['dependencies']
],
tags=[TagId(tag) for tag in json['tags']],
creator_user_id=UserId(json['createdByUserId']),
creation_date=datetime.datetime.fromisoformat(json['createdAt']),
assignments=[CardAssignment.from_json(ass) for ass in json['assignments']],
custom_fields=[CustomField.from_json(field) for field in json['customFields']],
attachments=json['attachments'], # TODO
custom_fields=[
CustomField.from_json(field) for field in json['customFields']
],
attachments=json['attachments'], # TODO
)

View File

@ -59,7 +59,10 @@ class FavroFuse(fuse.Fuse):
"""Favro Filesystem in Userspace."""
def __init__(
self, favro_client: FavroClient, formatter: CardFileFormatter, **kwargs,
self,
favro_client: FavroClient,
formatter: CardFileFormatter,
**kwargs,
):
self.favro_client = favro_client
self.formatter = formatter
@ -169,8 +172,11 @@ class FavroFuse(fuse.Fuse):
for assignment in card.assignments
]
dependencies = [
CARD_FILENAME_FORMAT.format(seq_id=self.favro_client.get_card_by_card_id(dep.card_id).seq_id.raw_id)
for dep in card.dependencies if dep.is_before
CARD_FILENAME_FORMAT.format(
seq_id=self.favro_client.get_card_by_card_id(dep.card_id).seq_id.raw_id
)
for dep in card.dependencies
if dep.is_before
]
card_contents = CardContents(
card.name,

View File

@ -1,6 +1,6 @@
import dataclasses
import re
import frontmatter
import marko
import marko.md_renderer
@ -18,6 +18,7 @@ class CardContents:
def format_obsidian_link(text: str) -> str:
return f'"[[{text}]]"'
def parse_obsidian_link(text: str) -> str:
if m := re.match(r'^\[\[(.*)\]\]$', text):
return m.group(1)
@ -45,13 +46,15 @@ class CardFileFormatter:
frontmatter_data['assignments'] = card.assignments
if self.obsidian_mode:
frontmatter_data['assignments'] = [
format_obsidian_link(name) for name in frontmatter_data['assignments']
format_obsidian_link(name)
for name in frontmatter_data['assignments']
]
if card.card_dependencies:
frontmatter_data['dependencies'] = card.card_dependencies
if self.obsidian_mode:
frontmatter_data['dependencies'] = [
format_obsidian_link(name) for name in frontmatter_data['dependencies']
format_obsidian_link(name)
for name in frontmatter_data['dependencies']
]
# Frontmatter
@ -100,7 +103,7 @@ class CardFileFormatter:
assignments = [parse_obsidian_link(text) for text in assignments]
card_dependencies: list[str] = fm.metadata.get('dependencies', [])
card_dependencies=[parse_obsidian_link(text) for text in card_dependencies]
card_dependencies = [parse_obsidian_link(text) for text in card_dependencies]
description = self.renderer.render_children(document).strip()
return CardContents(

View File

@ -1,7 +1,7 @@
def test_import():
import favro_sync.favro_data_model
import favro_sync.favro_client
import favro_sync.favro_fuse
import favro_sync.favro_markdown
import favro_sync
import favro_sync.favro_data_model # noqa
import favro_sync.favro_client # noqa
import favro_sync.favro_fuse # noqa
import favro_sync.favro_markdown # noqa
import favro_sync # noqa

View File

@ -38,6 +38,7 @@ Great news everyone! My weird program actually works!
FORMATTER = CardFileFormatter()
def test_parse_and_render():
card_contents = FORMATTER.parse_card_contents(EXAMPLE_TEXT_1)
@ -45,6 +46,7 @@ def test_parse_and_render():
assert '---' not in card_contents.description
assert FORMATTER.format_card_contents(card_contents) == EXAMPLE_TEXT_1
def test_parse_and_render_2():
card_contents = FORMATTER.parse_card_contents(EXAMPLE_TEXT_2)
print(card_contents)