Skip to content

Commit

Permalink
Reformat the project
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyMarkinPPC committed Mar 27, 2024
1 parent 9ce41d2 commit d955d76
Show file tree
Hide file tree
Showing 43 changed files with 1,060 additions and 941 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ tags
dist/
*egg-info*
.eggs

13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ repos:
- id: check-added-large-files
- id: debug-statements
- id: double-quote-string-fixer
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.12.0
hooks:
- id: reorder-python-imports
args:
- --py38-plus
- --add-import
- from __future__ import annotations
- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
hooks:
- id: autoflake
args: [--remove-all-unused-imports, --in-place]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
Expand Down
50 changes: 27 additions & 23 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
from __future__ import annotations

import pathlib
from itertools import chain
from setuptools import setup, find_packages

from setuptools import find_packages
from setuptools import setup

HERE = pathlib.Path(__file__)
README = (HERE.parent / "README.md").read_text()
EXTRAS_REQUIRE = {"asana": ["asana==5.0.0"]}
README = (HERE.parent / 'README.md').read_text()
EXTRAS_REQUIRE = {'asana': ['asana==5.0.0']}

EXTRAS_REQUIRE['all'] = list(set(chain(*EXTRAS_REQUIRE.values())))

setup(
name="terka",
version="2.9.1",
description="CLI utility for creating and managing tasks in a terminal",
name='terka',
version='2.9.1',
description='CLI utility for creating and managing tasks in a terminal',
long_description=README,
long_description_content_type="text/markdown",
author="Andrei Markin",
author_email="[email protected]",
license="Apache 2.0",
url="https://github.com/AndreyMarkinPPC/terka",
long_description_content_type='text/markdown',
author='Andrei Markin',
author_email='[email protected]',
license='Apache 2.0',
url='https://github.com/AndreyMarkinPPC/terka',
packages=find_packages(),
include_package_data=True,
package_data={"": ["presentations/text_ui/css/*.css"]},
package_data={'': ['presentations/text_ui/css/*.css']},
install_requires=[
"sqlalchemy==1.4.0",
"pyaml",
"rich",
"textual==0.41.0",
"plotext==5.2.8",
"textual-plotext==0.2.1",
"pandas",
"matplotlib",
'sqlalchemy==1.4.0',
'pyaml',
'rich',
'textual==0.41.0',
'plotext==5.2.8',
'textual-plotext==0.2.1',
'pandas',
'matplotlib',
],
setup_requires=["pytest-runner"],
tests_requires=["pytest"],
setup_requires=['pytest-runner'],
tests_requires=['pytest'],
extras_require=EXTRAS_REQUIRE,
entry_points={"console_scripts": ["terka=terka.entrypoints.cli:main"]},
entry_points={'console_scripts': ['terka=terka.entrypoints.cli:main']},
)
48 changes: 30 additions & 18 deletions terka/adapters/orm.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
from sqlalchemy import (
Table,
MetaData,
Column,
Integer,
String,
Date,
DateTime,
Boolean,
Enum,
ForeignKey,
)
from sqlalchemy.orm import backref, mapper, relationship

from terka.domain.entities import (collaborator, commentary, composite, epic,
event_history, note, project, sprint, story,
tag, task, time_tracker, user, workspace)

from __future__ import annotations

from sqlalchemy import Boolean
from sqlalchemy import Column
from sqlalchemy import Date
from sqlalchemy import DateTime
from sqlalchemy import Enum
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy.orm import backref
from sqlalchemy.orm import mapper
from sqlalchemy.orm import relationship

from terka.domain.entities import collaborator
from terka.domain.entities import commentary
from terka.domain.entities import composite
from terka.domain.entities import epic
from terka.domain.entities import event_history
from terka.domain.entities import note
from terka.domain.entities import project
from terka.domain.entities import sprint
from terka.domain.entities import story
from terka.domain.entities import tag
from terka.domain.entities import task
from terka.domain.entities import time_tracker
from terka.domain.entities import user
from terka.domain.entities import workspace
from terka.domain.external_connectors import asana

metadata = MetaData()
Expand Down
11 changes: 6 additions & 5 deletions terka/adapters/publisher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from __future__ import annotations

import json
import logging
from dataclasses import asdict

from terka.domain import events
import logging


class BasePublisher:
Expand All @@ -11,20 +14,18 @@ class BasePublisher:
class RedisPublisher(BasePublisher):

def __init__(self,
client: "redis.Redis",
client: 'redis.Redis',
topic_prefix: str | None = None) -> None:
self.client = client
self.topic_prefix = topic_prefix

def publish(self, topic: str, event: events.Event):
if self.topic_prefix:
topic = f"{self.topic_prefix}_{topic}"
topic = f'{self.topic_prefix}_{topic}'
self.client.publish(topic, json.dumps(asdict(event)))


class LogPublisher(BasePublisher):

def publish(self, topic: str, event: events.Event):
logging.info("Published to topic '%s': %s", topic, asdict(event))


46 changes: 23 additions & 23 deletions terka/adapters/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import abc
from collections.abc import MutableSequence
from datetime import datetime, timedelta
from datetime import datetime
from datetime import timedelta

from terka.domain.entities.entity import Entity
from terka.domain.entities.event_history import TaskEvent
from . import orm


class AbsRepository(abc.ABC):
Expand Down Expand Up @@ -66,19 +66,19 @@ def list(self,
query_object = self.session.query(entity)
overdue_check = False
stale_check = False
if "overdue" in filter_dict:
if 'overdue' in filter_dict:
overdue_check = True
del filter_dict["overdue"]
if "stale" in filter_dict:
del filter_dict['overdue']
if 'stale' in filter_dict:
stale_check = True
stale_lookback = int(filter_dict["stale"])
del filter_dict["stale"]
stale_lookback = int(filter_dict['stale'])
del filter_dict['stale']
if filter_dict and isinstance(filter_dict, dict):
query_dict = {}
or_values = {}
for k, v in filter_dict.items():
if isinstance(v, str):
if len((multiple_values := v.split(","))) == 1:
if len((multiple_values := v.split(','))) == 1:
query_dict[k] = str(v)
else:
or_values[k] = [str(v) for v in multiple_values]
Expand All @@ -93,9 +93,9 @@ def list(self,
query_dict[k] = str(v[0])
if or_values:
for key, values in or_values.items():
if values[0].startswith("NOT"):
if values[0].startswith('NOT'):
values = [
value.replace("NOT:", "") for value in values
value.replace('NOT:', '') for value in values
]
query_object = query_object.filter(
~getattr(entity, key).in_(values))
Expand All @@ -104,9 +104,9 @@ def list(self,
getattr(entity, key).in_(values))
if query_dict:
for key, value in query_dict.items():
if isinstance(value, str) and value.startswith("NOT"):
if isinstance(value, str) and value.startswith('NOT'):
query_object = query_object.filter(
getattr(entity, key) != value.replace("NOT:", ""))
getattr(entity, key) != value.replace('NOT:', ''))
if isinstance(value, datetime):
query_object = query_object.filter(
getattr(entity, key) <= value)
Expand All @@ -118,35 +118,35 @@ def list(self,
days_ago = datetime.now().date() - timedelta(
days=stale_lookback)
query_object = query_object.filter(
getattr(entity, "status").in_([
"TODO", "IN_PROGRESS", "REVIEW"
getattr(entity, 'status').in_([
'TODO', 'IN_PROGRESS', 'REVIEW'
])).join(TaskEvent, (entity.id == TaskEvent.task)).filter(
TaskEvent.date <= days_ago, TaskEvent.type == "STATUS")
TaskEvent.date <= days_ago, TaskEvent.type == 'STATUS')
return query_object.all()
if overdue_check:
query_object = query_object.filter(
getattr(entity, "due_date") < datetime.now().date())
getattr(entity, 'due_date') < datetime.now().date())
return query_object.all()
elif isinstance(filter_dict, str):
if overdue_check:
query_object = query_object.filter(
getattr(entity, "due_date") < datetime.now().date())
if filter_dict.startswith("NOT:"):
getattr(entity, 'due_date') < datetime.now().date())
if filter_dict.startswith('NOT:'):
return query_object.filter(
getattr(entity, "name") != filter_dict.replace(
"NOT:", "")).all()
getattr(entity, 'name') != filter_dict.replace(
'NOT:', '')).all()
else:
return query_object.filter_by(name=filter_dict).first()
if overdue_check:
query_object = query_object.filter(
getattr(entity, "due_date") < datetime.now().date())
getattr(entity, 'due_date') < datetime.now().date())
if stale_check:
days_ago = datetime.now().date() - timedelta(days=stale_lookback)
query_object = query_object.filter(
getattr(entity,
"status").in_(["TODO", "IN_PROGRESS", "REVIEW"])).join(
'status').in_(['TODO', 'IN_PROGRESS', 'REVIEW'])).join(
Event, (entity.id == Event.entity_id)).filter(
Event.date <= days_ago, Event.type == "status")
Event.date <= days_ago, Event.type == 'status')
return query_object.all()

def _add(self, entity):
Expand Down
9 changes: 6 additions & 3 deletions terka/bootstrap.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import inspect
from __future__ import annotations

from terka.adapters import orm, publisher
from terka.service_layer import handlers, messagebus, unit_of_work
from terka.adapters import orm
from terka.adapters import publisher
from terka.service_layer import handlers
from terka.service_layer import messagebus
from terka.service_layer import unit_of_work


def bootstrap(
Expand Down
7 changes: 5 additions & 2 deletions terka/domain/commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import Dict, Literal, Optional, Type
from __future__ import annotations

from dataclasses import asdict
from dataclasses import dataclass
from datetime import datetime
from dataclasses import dataclass, asdict
from typing import Type

from terka import exceptions

Expand Down
2 changes: 1 addition & 1 deletion terka/domain/entities/collaborator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
class CollaboratorMixin:
def __repr__(self):
return str(self.users.name)
Expand All @@ -21,4 +22,3 @@ def __init__(self,
**kwargs: str) -> None:
self.project = id
self.collaborator = collaborator_id

4 changes: 3 additions & 1 deletion terka/domain/entities/commentary.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from datetime import datetime

from .entity import Entity
Expand All @@ -13,7 +15,7 @@ def __init__(self,
self.date = date

def __repr__(self):
return f"<Commentary> {self.text}"
return f'<Commentary> {self.text}'

def __bool__(self) -> bool:
return bool(self.text)
Expand Down
Loading

0 comments on commit d955d76

Please sign in to comment.