Skip to content

Commit

Permalink
Merge pull request #1 from mergemaven11/with-black-config
Browse files Browse the repository at this point in the history
black config
  • Loading branch information
mergemaven11 authored May 20, 2024
2 parents eb3f4c9 + 8ca1266 commit 5be6d7c
Show file tree
Hide file tree
Showing 13 changed files with 589 additions and 69 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Code Quality

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python -
export PATH="$HOME/.local/bin:$PATH"
- name: Install dependencies
run: |
poetry install
- name: Run isort
run: |
poetry run isort $(git ls-files '*.py')
- name: Run black
run: |
poetry run black .
- name: Run autopep8
run: |
poetry run autopep8 --in-place $(git ls-files '*.py')
- name: Analysing the code with pylint
run: |
poetry run pylint --disable=C0103 $(git ls-files '*.py')
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.12"]
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
entries
__pycache__
poetry_venv
*.tmp
*.cache
*.pyc
.vscode/
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black

- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.5.7
hooks:
- id: autopep8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
hooks:
- id: mypy

- repo: local
hooks:
- id: pylint
name: pylint
entry: poetry run pylint --disable=C0103
language: python
files: \.py$
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MESSAGES CONTROL]
disable=C0103
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,36 @@ Date: 2023-05-16
Are you sure you want to delete the entry for 2023-05-16? (y/n): y
Entry deleted successfully!
```
### Contributing
We welcome contributions to improve the code quality of this project! Before submitting a pull request, please ensure that your changes adhere to our coding standards and pass all code quality checks.
### Code Quality Checks
We use various tools to maintain code quality, including formatting, linting, and static analysis. These tools are integrated into our development workflow using `pre-commit`, a framework for managing and maintaining multi-language pre-commit hooks.
To ensure that your changes meet our code quality standards, we recommend running `pre-commit` before committing your changes. This can be done by running the following command in your terminal:
```sh
pre-commit run -a
```
This command will execute all pre-commit hooks defined in our configuration file .pre-commit-config.yaml on all files in the repository.
### Running Tests
Before submitting a pull request, please make sure that your changes are covered by tests and that all existing tests pass. You can run the tests locally by following the instructions in our README file.
### Pull Request Guidelines
When submitting a pull request, please ensure the following:
- Provide a clear and descriptive title for the pull request.
- Explain the purpose of the changes and provide context in the pull request description.
- Include any necessary documentation updates.
- Ensure that your code adheres to our coding standards and passes all code quality checks.
- Reference any related issues or pull requests in the description.
Thank you for contributing to this project! I appreciate your efforts in helping to maintain code quality and improve the project for everyone.
47 changes: 28 additions & 19 deletions cli/handlers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import uuid
import typing as t

import uuid

from InquirerPy import prompt
from rich import print_json
Expand All @@ -24,24 +23,26 @@ def add_entry_to_file(entry_obj: t.Dict[str, t.Any], entries_file: str) -> None:
None
"""
# Load existing entries from the file
with open(entries_file, 'r') as f:
with open(entries_file, "r") as f:
entries_data: list = json.load(f)

# Generate a unique ID and timestamp for the new entry
entry_obj['id'] = str(uuid.uuid4())
entry_obj['timestamp'] = utils.current_datetime()
entry_obj["id"] = str(uuid.uuid4())
entry_obj["timestamp"] = utils.current_datetime()

# Append the new entry object to the existing list
entries_data.append(entry_obj)

# Write the updated entry data back to the file
with open(entries_file, 'w') as f:
with open(entries_file, "w") as f:
json.dump(entries_data, f, indent=4) # indent for pretty printing


# Searching an entry


def search_entries(keyword: str):
""" Search Entries by title, dropdown selection for multiple finds.
"""Search Entries by title, dropdown selection for multiple finds.
View all vs view one
Expand All @@ -56,23 +57,32 @@ def search_entries(keyword: str):
return

# Create a list of choices for the dropdown
choices = [f"{entry['title']} - {entry['timestamp']}" for entry in search_items]
choices = [
f"{entry['title']} - {entry['timestamp']}" for entry in search_items
] # type: ignore

# Use InquirerPy to present a dropdown selection
questions = [
{
'type': 'list',
'name': 'selected_entry',
'message': "Select an entry to view:",
'choices': choices
"type": "list",
"name": "selected_entry",
"message": "Select an entry to view:",
"choices": choices,
}
]

answers = prompt(questions)

# Find the selected entry
selected_entry = next((item for item in search_items if f"{item['title']} - {item['timestamp']}" == answers['selected_entry']), None)

selected_entry = next(
(
item
for item in search_items
if f"{item['title']} - {item['timestamp']}" == answers["selected_entry"]
),
None,
)

if selected_entry:
# Pretty-print the selected entry using rich
console.print("[bold green]Selected Entry:[/bold green]")
Expand All @@ -81,11 +91,10 @@ def search_entries(keyword: str):
console.print("[bold red]No entry selected.[/bold red]")



# Viewing an entry
# Viewing an entry

# Delete Entries

# Edit Entries

# Export Entries
# Export Entries
28 changes: 14 additions & 14 deletions cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import os
import json
import os
import re
import typing as t

from datetime import datetime, timezone

ENTRIES_DIR = './entries'
ENTRIES_FILE = './entries/entries.json'
ENTRIES_DIR = "./entries"
ENTRIES_FILE = "./entries/entries.json"


def check_entries_dir():
"""
Check if entries directory is present, and if not, create the directory and an initial JSON file.
"""
if not os.path.exists(ENTRIES_DIR):
os.makedirs(ENTRIES_DIR)
with open(ENTRIES_FILE, 'w') as f:
with open(ENTRIES_FILE, "w") as f:
# Create an empty array to store entries initially
json.dump([], f)

return ENTRIES_FILE



def current_datetime():
"""
Get the current UTC datetime and format it to a more human-readable format.
"""
# Get the current datetime in UTC timezone
utc_datetime = datetime.now(timezone.utc) # TODO handle tz
utc_datetime = datetime.now(timezone.utc) # TODO handle tz

# Format the datetime object to a more human-readable format
formatted_datetime = utc_datetime.strftime("%m/%d/%Y @ %I:%M:%S %p")
Expand All @@ -40,24 +39,25 @@ def search(keyword: str) -> t.List[t.Dict[str, str]]:
Args:
keyword (str): Keyword used to query JSON file.
Returns:
search_data (List): List of entries matching the keyword.
TODO: - Fix permissions issue
"""
search_data = []

if os.path.exists(ENTRIES_DIR):
with open(ENTRIES_DIR, 'r') as file:
with open(ENTRIES_DIR, "r") as file:
entries = json.load(file)

for entry in entries:
if re.search(keyword, entry['title'], re.IGNORECASE) or re.search(keyword, entry['content'], re.IGNORECASE):
if re.search(keyword, entry["title"], re.IGNORECASE) or re.search(
keyword, entry["content"], re.IGNORECASE
):
search_data.append(entry)

if not search_data:
print(f"There are no entries with keyword: {keyword}")

return search_data

return search_data
17 changes: 9 additions & 8 deletions journal.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import typer

import cli.handlers as handler
import cli.utils as util # pytest works but python journal.py wont


app = typer.Typer()

# def main():
# print("Hello World")


# Add imported commands to the main Typer application instance
@app.command()
def add():
title = typer.prompt("Please enter a title")
entry = typer.prompt("Please enter your journal entry")
# Send data to add handler
handler.add_entry_to_file({"Title": title, "Entry": entry})


@app.command()
def view(name: str):
typer.echo(f"Hello {name}")
Expand All @@ -26,12 +27,12 @@ def view(name: str):
def export(name: str):
typer.echo(f"Hello {name}")


@app.command()
def search(keyword: str):
def search(keyword: str):
handler.search_entries(keyword)



@app.command()
def delete(name: str):
typer.echo(f"Hello {name}")
Expand All @@ -43,6 +44,6 @@ def edit(name: str):


if __name__ == "__main__":
# Check if first entry, if so create the dir and file.
util.check_entries_dir()
app()
# Check if first entry, if so create the dir and file.
util.check_entries_dir()
app()
Loading

0 comments on commit 5be6d7c

Please sign in to comment.