Skip to content

Commit

Permalink
0.1.7 styling and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dudarev committed Jun 17, 2023
1 parent 6520e8b commit 6ecec55
Show file tree
Hide file tree
Showing 18 changed files with 178 additions and 126 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,8 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

.vscode
.vscode
.DS_Store

scripts/
out.txt
29 changes: 23 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,64 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.1.7 (2023-06-17)

### Changed

- Migrated from setup.py to pyproject.toml.
- Introduced package instead of a script
- Refactored commands to be more modular

## 0.1.6 (2023-02-13)

### Added

- `Makefile`
- `requirements-dev.txt` for development
- help to every command

### Changed
- Documentation is moved to [docs/](docs/README.md)

- Documentation is moved to [docs/](docs/README.md)

## 0.1.5 (2023-01-07)

### Added
- `ls -l` list files as wiki links

- `ls -l` list files as wiki links

## 0.1.4 (2022-12-03)

### Changed

- `count` command by default counts file modified from midnight of today in local time
- `ls` command by default lists files modified today in local time


## 0.1.3

### Added
- `random` returns a random file

- `random` returns a random file

## 0.1.2

### Changed
- `ls` command shows only `.md` files

- `ls` command shows only `.md` files

## 0.1.1

### Added
- `ls` command to list files modified in last 24 hours in reverse chronological order

- `ls` command to list files modified in last 24 hours in reverse chronological order

## 0.1.0

### Added

- `count` command
- tests
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.7
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ See some [[Examples]]
Check the planned features in [[Plan]]

For releases follow [[Release checklist]]


To navigate wikilinks you may use
- [Markdown Notes](https://marketplace.visualstudio.com/items?itemName=kortina.vscode-markdown-notes) plugin in VSCode
- [vimwiki](https://github.com/vimwiki/vimwiki) plugin in vim
15 changes: 14 additions & 1 deletion docs/Release checklist.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Release checklist

## Before release

- [ ] tests pass (`make test`)
- [ ] [CHANGELOG](../CHANGELOG.md) is updated
- [ ] version is updated in [setup.py](../setup.py)
- [ ] version is updated in [VERSION](../VERSION) and [pyproject.toml](../pyproject.toml)

## After release

- [ ] add a tag for the release in git:

```bash
git tag -a 0.1.0 -m "0.1.0"
git push origin 0.1.0
```
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[build-system]
requires = ["setuptools", "wheel"]


[project]
name = "think-cli"
version = "0.1.7"
description = "A command line tool to work with Markdown files"
readme = "README.md"
dependencies = [
"Click>=8.1.3"
]


[project.scripts]
t = "think:cli"


[tool.isort]
src_paths = ["think", "tests"]
15 changes: 0 additions & 15 deletions setup.py

This file was deleted.

5 changes: 1 addition & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import os

from datetime import datetime, timedelta, timezone
from pathlib import Path
from uuid import uuid4

import pytest
from pathlib import Path

from click.testing import CliRunner


LOCAL_TIMEZONE = datetime.now(timezone.utc).astimezone().tzinfo


Expand Down
2 changes: 0 additions & 2 deletions tests/test_count.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import os
from pathlib import Path


from click.testing import CliRunner


from think import count


Expand Down
3 changes: 1 addition & 2 deletions tests/test_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from click.testing import CliRunner

from think import ls

from conftest import FILE_1_NAME, FILE_2_NAME
from think import ls


def test_list_zero(cli_runner_and_dir: tuple[CliRunner, Path]):
Expand Down
7 changes: 2 additions & 5 deletions tests/test_random.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@

from click.testing import CliRunner

from conftest import FILE_1_NAME
from think import random

from conftest import FILE_1_NAME, FILE_2_NAME


def test_random_empty(cli_runner_and_dir: tuple[CliRunner, Path]):

cli_runner, tmp_dir = cli_runner_and_dir
result = cli_runner.invoke(random)
assert result.exit_code == 0
assert result.output == "No files available\n"


@mock.patch("think.choice", return_value=FILE_1_NAME)
@mock.patch("think.random.choice", return_value=FILE_1_NAME)
def test_random_two_files(
mock_random_choice, cli_runner_and_dir: tuple[CliRunner, Path], two_files
):

cli_runner, tmp_dir = cli_runner_and_dir
result = cli_runner.invoke(random)
assert result.exit_code == 0
Expand Down
90 changes: 0 additions & 90 deletions think.py

This file was deleted.

1 change: 1 addition & 0 deletions think/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .think import *
17 changes: 17 additions & 0 deletions think/count.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os

import click

from .files import iter_markdown_files_modified_today


@click.command(
help="Prints the total number of files and number of files modified today"
)
def count():
n_files = len(os.listdir())
n_modified_day = 0
for _ in iter_markdown_files_modified_today():
n_modified_day += 1
click.echo(f"Total files: {n_files}")
click.echo(f"Modified today: {n_modified_day}")
37 changes: 37 additions & 0 deletions think/files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
from datetime import datetime, timezone
from pathlib import Path

LOCAL_TIMEZONE = datetime.now(timezone.utc).astimezone().tzinfo


MARKDOWN_FILE_EXTENSIONS = {
"md",
"mkd",
"mdwn",
"mdown",
"mdtxt",
"mdtext",
"markdown",
"text",
"txt",
}


def is_markdown(p: Path):
extension = p.suffix.lower().replace(".", "")
return extension in MARKDOWN_FILE_EXTENSIONS


def is_modified_today(p: Path):
today_local = datetime.now().replace(
hour=0, minute=0, second=0, tzinfo=LOCAL_TIMEZONE
)
mtime = datetime.fromtimestamp(os.path.getmtime(p)).replace(tzinfo=LOCAL_TIMEZONE)
return mtime > today_local


def iter_markdown_files_modified_today():
for p in Path().iterdir():
if is_markdown(p) and is_modified_today(p):
yield p
19 changes: 19 additions & 0 deletions think/ls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

import click

from .files import iter_markdown_files_modified_today

CONVERTER_FOR_LINKS_PARAMETER = {
True: lambda x: f'[[{str(x).replace(".md", "")}]]',
False: lambda x: x,
}


@click.command(help="List files changed today")
@click.option("-l", "--links", is_flag=True, help="Formats files as wiki links")
def ls(links):
files = [(os.path.getmtime(p), p) for p in iter_markdown_files_modified_today()]
files.sort(reverse=True)
for f in files:
click.echo(CONVERTER_FOR_LINKS_PARAMETER[links](f[1]))
Loading

0 comments on commit 6ecec55

Please sign in to comment.