Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codebase Refactor ⭐ #663

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ If you have any suggestions or comments, feel free to contact me on the
mailing list or directly per mail. Before starting to work on a feature,
please check back with me briefly about its status.


## Important features

- [ ] Update GTK stack for Windows: use MinGW and Python >= 3.6.
- [ ] Use separate file for storing CSS to allow users to override styles more easily.
- [ ] Make default CSS prettier (see private email exchange).
- [ ] Allow searching for days that contain **multiple** words or tags.
- [ ] Check that non-ASCII image filenames work (https://bugs.launchpad.net/bugs/1739701).
- [ ] Check that non-ASCII image filenames work (<https://bugs.launchpad.net/bugs/1739701>).
- [ ] Search and replace (useful for renaming tags and other names).
Show "replace" text field after search text has been entered.
- [ ] Add simple way to show all entries: allow searching for whitespace (i.e., don't strip whitespace from search string).
Expand All @@ -28,7 +27,6 @@ please check back with me briefly about its status.
- [ ] Check that images work on Windows in LaTeX exports.
- [ ] Fix drag-and-drop on Windows (confirmed that it doesn't work in version 2.6.1). Might be fixed by now.


### Remove right-side tags panel (disabled by default)

- [ ] When searching for a hashtag (see #498):
Expand All @@ -39,7 +37,6 @@ please check back with me briefly about its status.
- [ ] Transform existing right-side tags foo:bar to "#foo bar" when loading a journal.
- [ ] Remove code for right-side tags panel.


## Optional features

- [ ] Auto-completion for hashtags.
Expand All @@ -58,14 +55,12 @@ please check back with me briefly about its status.
- create our own menu: complicated
- only show the menu if there's a selection: WebView.has_selection() seems to be broken


## Implementation changes

- [ ] Enable faulthandler module (https://docs.python.org/3/library/faulthandler.html, added in Python 3.3).
- [ ] Enable faulthandler module (<https://docs.python.org/3/library/faulthandler.html>, added in Python 3.3).
- [ ] Don't store regexes in Cloud class.
- [ ] Clouds: don't store link_dict, but use names directly in HTML in Cloud class.


## Deferred features

After deciding whether to switch to Markdown or not:
Expand All @@ -80,7 +75,6 @@ After deciding whether to switch to Markdown or not:
- [X] Numbered lists
- [X] Add quotes by indenting them with a tab


## Unwanted features

- verbatim / raw ( """/"" - supported, undocumented) (too confusing / poorly behaving)
Expand Down
6 changes: 4 additions & 2 deletions dev/check-style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
set -exuo pipefail

cd "$(dirname "$0")"

cd ../

black --check --diff .

# E203: whitespace before ':' (not compliant with PEP 8)
# E402: module level import not at top of file

python3 -m flake8 --exclude=external --extend-ignore=E203,E402 --max-line-length=110 --builtins="_" rednotebook tests setup.py dev/whitelist.py

isort --check-only rednotebook/ tests/

python3 -m pyupgrade --py36-plus `find rednotebook tests -name "*.py" -not -path "*external*"`
python3 -m pyupgrade --py36-plus $(find rednotebook tests -name "*.py" -not -path "*external*")

python3 -m vulture --exclude=external rednotebook dev/whitelist.py

python3 dev/build_translations.py test-translations

echo "All tests passed"
echo "All tests passed"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the added newlines are helpful. And the final newline should be brought back. I think you can simply revert all changes to this file.

4 changes: 2 additions & 2 deletions dev/generate-pot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ xgettext --output=rednotebook.pot \
--files-from=sourcefiles.txt \
tmp/main_window.glade.h

for file in `ls *.po`; do
msgmerge --previous --update ${file} rednotebook.pot
for file in $(ls *.po); do
msgmerge --previous --update "${file}" rednotebook.pot
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msgmerge --previous --update "${file}" rednotebook.pot
msgmerge --previous --update ${file} rednotebook.pot

Apostrophes are redundant when using ${}.

done

rm sourcefiles.txt
Expand Down
18 changes: 18 additions & 0 deletions rednotebook.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Metadata-Version: 2.1
Name: rednotebook
Version: 2.29
Summary: Graphical daily journal with calendar, templates and keyword searching
Home-page: https://rednotebook.app
Author: Jendrik Seipp
Author-email: jendrikseipp@gmail.com
Maintainer: Jendrik Seipp
Maintainer-email: jendrikseipp@gmail.com
License: GPL
Keywords: journal,diary
Provides-Extra: dev_style
License-File: LICENSE

RedNotebook is a modern desktop journal. It lets you format, tag and
search your entries. You can also add pictures, links and customizable
templates, spell check your notes, and export to plain text, HTML or
Latex.
146 changes: 146 additions & 0 deletions rednotebook.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
CHANGELOG.md
LICENSE
MANIFEST.in
README.md
TODO.md
pyproject.toml
run
setup.py
data/rednotebook.appdata.xml
data/rednotebook.desktop
dev/build_translations.py
po/ar.po
po/ast.po
po/be.po
po/bg.po
po/bs.po
po/ca.po
po/cs.po
po/cy.po
po/da.po
po/de.po
po/el.po
po/en_GB.po
po/eo.po
po/es.po
po/eu.po
po/fi.po
po/fo.po
po/fr.po
po/ga.po
po/gl.po
po/he.po
po/hi.po
po/hr.po
po/hu.po
po/hy.po
po/id.po
po/ie.po
po/it.po
po/ja.po
po/ka.po
po/kk.po
po/ko.po
po/ky.po
po/lt.po
po/ml.po
po/mn.po
po/ms.po
po/my.po
po/nb.po
po/nds.po
po/nl.po
po/nn.po
po/oc.po
po/pl.po
po/pt.po
po/pt_BR.po
po/rednotebook.pot
po/ro.po
po/ru.po
po/si.po
po/sk.po
po/sl.po
po/sr.po
po/sv.po
po/ta.po
po/te.po
po/tl.po
po/tr.po
po/ug.po
po/uk.po
po/uz.po
po/vi.po
po/wae.po
po/xh.po
po/zh_CN.po
po/zh_HK.po
po/zh_TW.po
rednotebook/__init__.py
rednotebook/backup.py
rednotebook/configuration.py
rednotebook/data.py
rednotebook/help.py
rednotebook/info.py
rednotebook/journal.py
rednotebook/rednotebook
rednotebook/storage.py
rednotebook/templates.py
rednotebook.egg-info/PKG-INFO
rednotebook.egg-info/SOURCES.txt
rednotebook.egg-info/dependency_links.txt
rednotebook.egg-info/requires.txt
rednotebook.egg-info/top_level.txt
rednotebook/external/__init__.py
rednotebook/external/elibintl.py
rednotebook/external/msgfmt.py
rednotebook/external/spellcheck.py
rednotebook/external/txt2tags.py
rednotebook/files/default.cfg
rednotebook/files/main_window.glade
rednotebook/files/rednotebook-highlight-style.xml
rednotebook/files/t2t.lang
rednotebook/gui/__init__.py
rednotebook/gui/browser.py
rednotebook/gui/browser_cef.py
rednotebook/gui/categories.py
rednotebook/gui/clouds.py
rednotebook/gui/customwidgets.py
rednotebook/gui/editor.py
rednotebook/gui/exports.py
rednotebook/gui/format_menu.py
rednotebook/gui/insert_menu.py
rednotebook/gui/main_window.py
rednotebook/gui/menu.py
rednotebook/gui/options.py
rednotebook/gui/search.py
rednotebook/images/bulletlist.png
rednotebook/images/date.png
rednotebook/images/formula.png
rednotebook/images/insert-image-16.png
rednotebook/images/insert-image-22.png
rednotebook/images/line.png
rednotebook/images/linebreak.png
rednotebook/images/link.png
rednotebook/images/numberedlist.png
rednotebook/images/picture.png
rednotebook/images/table.png
rednotebook/images/title.png
rednotebook/images/rednotebook-icon/rednotebook.svg
rednotebook/images/rednotebook-icon/rn-128.png
rednotebook/images/rednotebook-icon/rn-14.png
rednotebook/images/rednotebook-icon/rn-16.png
rednotebook/images/rednotebook-icon/rn-192.png
rednotebook/images/rednotebook-icon/rn-22.png
rednotebook/images/rednotebook-icon/rn-256.png
rednotebook/images/rednotebook-icon/rn-32.png
rednotebook/images/rednotebook-icon/rn-48.png
rednotebook/images/rednotebook-icon/rn-64.png
rednotebook/util/__init__.py
rednotebook/util/dates.py
rednotebook/util/filesystem.py
rednotebook/util/markup.py
rednotebook/util/pango_markup.py
rednotebook/util/statistics.py
rednotebook/util/urls.py
rednotebook/util/utils.py
1 change: 1 addition & 0 deletions rednotebook.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

11 changes: 11 additions & 0 deletions rednotebook.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

[dev_style]
black==22.3.0
flake8==4.0.1
flake8-2020==1.6.0
flake8-bugbear==21.11.28
flake8-comprehensions==3.7.0
flake8-executable==2.1.1
isort==5.10.1
pyupgrade==2.32.0
vulture==1.6
1 change: 1 addition & 0 deletions rednotebook.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rednotebook
jendrikseipp marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 8 additions & 10 deletions rednotebook/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@


def delete_comment(line):
if line.startswith("#"):
return ""
return line
return "" if line.startswith("#") else line


class Config(dict):
Expand Down Expand Up @@ -139,17 +137,17 @@ def write_list(self, key, list):
self[key] = ", ".join(list)

def changed(self):
return not (self == self.old_config)
return self != self.old_config

def save_to_disk(self):
if not self.changed():
return

lines = []
for key, value in sorted(self.items()):
if key not in self.suppressed_keys:
lines.append(f"{key}={value}")

lines = [
f"{key}={value}"
for key, value in sorted(self.items())
if key not in self.suppressed_keys
]
try:
filesystem.make_directory(os.path.dirname(self.filename))
filesystem.write_file(self.filename, "\n".join(lines))
Expand All @@ -158,5 +156,5 @@ def save_to_disk(self):
"Configuration could not be saved. Please check " "your permissions"
)
else:
logging.info("Configuration has been saved to %s" % self.filename)
logging.info(f"Configuration has been saved to {self.filename}")
self.save_state()
15 changes: 7 additions & 8 deletions rednotebook/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_text_with_dots(text, start, end, found_text=None):
res = res.replace("\n", " ")
if found_text:
# Make the searched_text bold
res = res.replace(found_text, "STARTBOLD%sENDBOLD" % found_text)
res = res.replace(found_text, f"STARTBOLD{found_text}ENDBOLD")

return res

Expand Down Expand Up @@ -165,7 +165,7 @@ def get_words(self, with_special_chars=False):
for category, content in self.get_category_content_pairs().items()
)

all_text = self.text + " " + categories_text
all_text = f"{self.text} {categories_text}"
words = all_text.split()

if with_special_chars:
Expand Down Expand Up @@ -204,8 +204,7 @@ def search(self, text, tags):
# Date contains searched text.
results.append(get_text_with_dots(self.text, 0, TEXT_RESULT_LENGTH))
else:
text_result = self.search_in_text(text)
if text_result:
if text_result := self.search_in_text(text):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to bump the minimum Python version to 3.8 for the walrus operator, but I think that's fine.

results.append(text_result)
results.extend(self.search_in_categories(text))
return str(self), results
Expand All @@ -218,10 +217,9 @@ def search_in_text(self, search_text):
return None

found_text = self.text[occurrence : occurrence + len(search_text)]
result_text = get_text_with_dots(
return get_text_with_dots(
self.text, occurrence, occurrence + len(search_text), found_text
)
return result_text

def search_in_categories(self, text):
results = []
Expand Down Expand Up @@ -261,8 +259,9 @@ def get_day(self, day_number):

def __str__(self):
lines = [f"Month {self.year_number} {self.month_number}"]
for day_number, day in self.days.items():
lines.append(f"{day_number}: {day.text}")
lines.extend(
f"{day_number}: {day.text}" for day_number, day in self.days.items()
)
return "\n".join(lines)

@property
Expand Down
8 changes: 2 additions & 6 deletions rednotebook/gui/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
WebKit2 = None
if not filesystem.IS_WIN:
logging.info(
"WebKit2Gtk 4.0 (gir1.2-webkit2-4.0) not found. Please install"
' it if you want in-app previews. Error message: "{}"'.format(err)
f'WebKit2Gtk 4.0 (gir1.2-webkit2-4.0) not found. Please install it if you want in-app previews. Error message: "{err}"'
)


Expand All @@ -57,10 +56,7 @@ def __init__(self):
self.show_all()

def set_font_size(self, size):
if size <= 0:
zoom = 1.0
else:
zoom = size / 10.0
zoom = 1.0 if size <= 0 else size / 10.0
# It seems webkit shows text a little bit bigger.
zoom *= 0.90
self.set_zoom_level(zoom)
Expand Down
Loading