Commit graph

149 commits

Author SHA1 Message Date
Christian Wutte
d12d5c0c10 Feature - add bracketed date support when composing new entry (#1915)
Bracketed dates like [2020-01-01] will be parsed and used as the entry date, thus be removed from the entry text.
2024-09-24 07:18:09 +02:00
Ricardo Ruiz
8957ceb74d
Fix -contains to allow multiple terms with "OR" logic unless -and is added (#1890)
* Store multiple -contains arguments (OR default).

Allow multiple occurrences of the -contains argument
to be stored in a list. Previously, only the last occurrence was
considered. Additionally, the behavior has been modified to default to
OR logic, meaning that if multiple -contains arguments are provided,
entries matching any of them will be included in the results.

* Solved issue #1877 "-and" flag with multiple instances of the -contains option.

* Run poe format

* Fix unit test for contains to allow list instead of single value

* Add BDD tests for multiple contains with and without -and

* Black version updated.

* Revert pyproject.toml to appease poetry

---------

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
2024-05-20 21:16:33 -07:00
Ben Beasley
48b61f6953
Support pytest_bdd 7.1.2 and later (#1878)
* Support pytest_bdd 7.1.2 and later

Fix #1875.

* Prevent use of pytest 8.1 for now due to unrelated error

* poetry lock --no-update

---------

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
2024-03-28 08:08:00 -07:00
renovate[bot]
6962c399ea
Update dependency ruff to v0.0.287 (#1778)
* Update dependency ruff to v0.0.287

* add ruff target version to tailor linting to our required python versions

* fix linting issues

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
2023-09-09 15:44:46 -07:00
Micah Jerome Ellison
cb69bb474c
Use rich instead of ansiwrap to wrap text (#1693) 2023-07-29 14:36:43 -07:00
Micah Jerome Ellison
34c7903300
Replace flake8 and isort with ruff linter and add black --check to linting step (#1763)
* Add ruff

* Add ruff config

* Add ruff rules that look useful and are already passing

* Add more ruff rules after talking with Jonathan

* Add line length exception for acceptably long indented line

* Resolve ruff line length 88 rule in args. Changing small lines but adding a noqa ignore directive to longer lines that look best as they are. Their dedented length is still less than 88

* poe format

* Resolve all remaining ruff line length errors

* Replace flake* and isort with ruff calls

* Add black --check as final lint step. ruff catches most but not all black formatting issues

* Remove unneeded flakeheaven setting

* Remove flake* and isort now that ruff is handling all their business

* Update pyproject, lockfile with latest version of ruff

* Document each ruff rule with comment

* Add black --version call before black --check

* Remove extraneous period
2023-07-15 12:35:10 -07:00
Micah Jerome Ellison
4a7057c038
Refactor --template code (#1711)
* Move path concerns to path.py and template concerns to editor.py -- BDD tests are failing
* Move path-related constants from config.py to path.py
* Mock get_templates_path in its new calling file
* Mediate template arg vs. config in controller then read template text in editor and unify those two use cases.
Some tests still failing
* Fix test whose message had changed
* poe format
* Refactor for easier unit testing and add unit tests
* Use path strings instead of Path objects in return values to prevent side effects that caused unit tests to fail on some platforms
* poe format
* Attempt to bypass getcwd errors in CI with patch
* Consistently use strings for paths instead of some strings and some pathlib.Path
* Keep pathlib within a function for readability
* fix for ruamel.yaml versions >=0.17.22
* Run poe format

---------

Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
2023-05-20 16:13:24 -07:00
Jonathan Wren
4cb5d1e436
fix some linting issues for failing PR (#1745) 2023-05-20 16:03:46 -07:00
Micah Jerome Ellison
95836a7dd1
Only read text files that look like entries when opening folder journal (#1697)
* Add text file that should be ignored to basic test folder journal. Makes tons of tests fail
* Add additional files that should be ignored by FolderJournal
* Ignore all files in folder journal except year/month/day.txt
* Completely remake get_files in FolderJournal:
- move get_files into FolderJournal class and add underscore prefix
- create iterables to get for year/month folders and day files
- make year/month/day file reading strict: only exact expected months and days out of all possible months and days
* Restore accidentally-deleted self.sort() line
* Use match instead of string comparison to be os-agnostic
* Explicitly declare static methods
* Filter with glob first for max performance
* Explicitly check for valid dates in FolderJournal and add unit test
* Remove unneeded jrnl import
* Clean up method comment and add type hints
* Add is_valid_date unit test
* Elucidate comment

Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
2023-04-29 15:49:41 -07:00
Jonathan Wren
3c923ae943
Allow combinations of --change-time, --delete, and --edit while correctly counting the number of entries affected (#1669)
* Remove search mode conditional that added explicit tag search behavior
* Fix failing change-time test by using same method signature as base journal class
* Fix user input mock - was not appropriately checking return value
* Clean up controller
  - streamline `run` function in `controller.py`
  - add debug logging
  - fix unnecessary import of Journal class (only needed for typing)
  - standardize summary display across different actions
* Add currently-failing test conditions for count messages when changing time and deleting
* Don't show summary if no entries found and prevent extra line break when no entries found by short-circuiting display method
* Track found entry count and remove incorrect modified stat logic
* Track journal entry deletion consistently
* Remove unneeded exception when editor is empty and fix test that was testing incorrect message
* Correct entry edit modified count test
* Track modification of entries with --change-time
* Preserve existing behavior when editor is empty but make the message more clear
* Reconcile tests with new error message when clearing editor in edit mode
* Add found/modified counts to edit tests
* Add tests for found count with -n equivalent argument
* Test combinations of found/deleted messages when using --delete
* Add tests for counting combinations of action arguments (change-time, edit, delete) and for change-time counts. Some are failing and should be investigated
* Remove extraneous comment in test
* Track added/deleted counts in a register in the Journal class instead of attempting to infer it via controller counting
* Add encrypted to more tests
* Fix merge conflict typo
* Change 'write mode' -> 'append mode' in more places

---------

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
2023-03-25 12:32:25 -07:00
Aaron Lichtman
a2b217fdfc
Add ability to use template with --template (#1667)
* Add ability to pass template path with --template

Update jrnl/args.py

* Fix tests
2023-03-25 11:47:00 -07:00
Micah Jerome Ellison
427485a1d7
Add message with config location and docs location when installation is complete (#1695) 2023-03-04 12:45:37 -08:00
Micah Jerome Ellison
1a67fd5dec
Use pytest-bdd 6 (#1685)
* update pytest-bdd to 6.0
* update lock file
* fix first test (inject command fixture to request)
* fix some more tests
* fix cli_run fixture
* fix password fixture
* Remove unused import
* Fix greedy should_or_should_not parsing problems while also consolidating its parse/transformation-to-bool code
* Prevent greedy matching in "we run" by using regular expression lookahead
* Add missing "Outline" in scenario outlines with examples
* Split "we use the config" and "we use no config" so pytest won't try to consume config_file as a fixture
* Fix missing ShouldOrShouldNot
* Formatting
* fix get_fixture function
* change output of failing test to be a little more useful
* update lock file
* update type builder to for should/should not to be in it's own file, rename some vars for readability
* add parse-type new dev/testing dependency
* update lock file

---------

Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
2023-03-04 12:37:06 -08:00
Micah Jerome Ellison
e6804f1627
Prompt to include colors in config when first running jrnl (#1687)
* Add prompt to ask user if entries should be formatted with colors when installing jrnl
* Use magenta instead of black for default date color
* Use other default colors and alphabetize color list
* Update tests
* Delete test file
* update lock file
* fix failing test after merge conflict

---------

Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
2023-02-25 15:30:25 -08:00
Micah Jerome Ellison
3c87111710
Save empty journal on install instead of just creating a zero-length file (#1690)
* Add failing test for issue #1493
* Write journal upon creation instead of just creating 0-length file
* Fix test to accommodate current password mocking form
2023-02-25 12:29:43 -08:00
Briscoooe
b41a988d6f
Don't save templated journal entries if the received raw text is the same as the template itself (#1653) 2023-02-11 12:38:21 -08:00
Ciaran Concannon
7bd15d12ad
Search for entries with no tags or stars with -not -starred and -not -tagged (#1663)
* Allow for `-not -starred` to search for unstarred entries

* Add `-tagged` and `-not -tagged` functionality
2023-01-28 11:45:01 -08:00
Jonathan Wren
fff05eb646
Refactor flow for easier access to some files (avoid things like jrnl.Journal.Journal and jrnl.jrnl co-existing) (#1662)
* run format

* rename cli.py to main.py

* rename jrnl.py to controller.py

* move journal class files into journals dir

* rename start -> run in controller.py
2023-01-14 14:42:29 -08:00
Jonathan Wren
8da6029624
Update copyright notices for 2023 (#1660)
* update copyright notice for 2023

* standardize whitespace after copyright notice
2023-01-07 13:39:07 -08:00
Micah Jerome Ellison
9274ab16ed
Add basic template test (#1659)
* Add very basic test template
* Ensure that templates are copied to temporary test workspace
* Add basic template test
* Update copyright for this new file
2023-01-07 13:37:43 -08:00
Jonathan van der Steege
907566b39f
Add tag to XML file when edited DayOne entry and is searchable afterward (#1648)
* Add tag to XML file when edited DayOne entry
* Remove forbidden change
* undo edits
* Tags working for DayOne journal
* Correction doentries to prevent time-error
* Add sorting to tags
* Delete test statements
* Revert time changes
2023-01-07 12:51:07 -08:00
Jonathan van der Steege
d94325127f
Update version key in config file after version changes (#1646) 2023-01-07 11:46:12 -08:00
Jonathan Wren
fcc8d8e3fa
Rework Encryption to enable future support of other encryption methods (#1602)
- initial pass through to rework encryption into separate module
- little more cleanup
- rename function, fix some linting issues
- more cleaning
- fix password bug in encryption
- fix linting issue
- more cleanup
- move prompt into prompt.py
- more cleanup
- update the upgrade process for new encryption classes
- general cleanup
- turn into enum instead of strings
- store status code so tests don't fail
- standardize the load and store methods in journals
- get rid of old PlainJournal class
- typing cleanup
- more cleanup
- format
- fix linting issue
- Fix obscure Windows line ending issue with decode
  See https://bugs.python.org/issue40863
- fix for python 3.11
- add more typing
- don't use class variables because that's not what we want
- fix more type hints
- jrnlv1 encryption doesn't support encryption anymore (it's deprecated)
- keep logic for password attemps inside the class that uses it
- take out old line of code
- add some more logging
- update logging statements
- clean up logging statements
- run linters
- fix typo
- Fix for new test from develop branch
  There was a new test added for re-encrypting a journal. This updates the
  refactor to match the old (previously untested) behavior of jrnl.

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
2022-11-19 13:39:39 -08:00
Jonathan Wren
b508ed6c9a
Add simplify plugin to linting checks (#1630)
* add simplify plugin for flakeheaven

* update lock file

* fix linting issues in current codebase
2022-11-05 15:56:46 -07:00
Micah Jerome Ellison
44e2ace833
Add double encryption test (#1626) 2022-10-30 13:06:54 -07:00
Jonathan Wren
63850a33c1
Fix bug for new --list --format options when no default journal is specified (#1621)
* rename test config

* Change journal name validation

Journal name validation used to happen before postconfig commands could
have a chance to run, so now each command is responsible for its own
error-checking of the journal name.

Added a new decorator and function that makes this error-checking easier.

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>

* fix wrapper function call to be more like original

* change arg names to show which aren't used

* add type hints

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
2022-10-22 15:35:16 -07:00
outa
d7242d81a4
Don't create empty file when attempting a YAML export to a non-existing folder (#1600)
* Call `export_journal` before opening file handle
* Use correct exporter class
* Fix unit test
2022-10-08 13:48:29 -07:00
Micah Jerome Ellison
ceff398a01
Change default config to use journal key instead of journal name as key for file path (#1594) 2022-10-08 13:41:22 -07:00
Kevin
2df7acf488
Add machine readable --list output (#1592)
* Add machine readable --list output

* Refactor list_journals()

Create three new methods for each journal list format.
- JSON, YAML, STDOUT

* Added journal list export test

* Update test regex to handle windows filepaths
2022-09-24 12:46:49 -07:00
Micah Jerome Ellison
f65f07dbcb
Suppress "Entry added" message if using default journal (#1561)
* Suppress "Entry added to default journal" message if using default journal
* Replace "Entry added" BDD test steps with "we should get no error" now that the message is suppressed
* Add positive and negative tests for "Entry added" message behavior
2022-08-27 12:33:44 -07:00
Kevin
0cc771f633
Add message showing the number of search results (#1524)
* Added message showing the number of search results

Modified _search_journal() to return a bool based upon whether
any filter args were passed to the program.

Added _print_entries_found_count() which prints a message
based upon the number of entries found and prints warnings
if the user was trying to edit or delete.

* Add tests for search results msgs
2022-08-27 12:13:57 -07:00
Jonathan Wren
4eb9c9fdec
Clean up copyright notices and version screen (#1553)
* update copyright symbols to unicode

* clean up version screen/copyright notice

* small change to make commands more similar

* update imports to appease isort

* fix test

* update one more file merged since PR was open
2022-08-21 14:17:35 -07:00
Jonathan van der Steege
fb473007da
Export to file(s) when first line/title of an entry is very long (#1527) 2022-08-13 13:02:19 -07:00
outa
62f65ce3b9
Update tzlocal to v4.x and remove pytz dependency (#1528)
* Update tzlocal to v4.x and remove pytz dependency
* Avoid `unwrap_shim` method
* Remove upper bound of tzlocal version
2022-07-30 12:46:43 -07:00
Jonathan van der Steege
80bfff384e
Add linewrap option 'auto' (#1507)
* Add linewrap option 'auto'

* Specify the exception thrown

* Add BDD test

* Specify name instead of number

* Create test for linewrap auto and fancy format

* Fix linewrap auto for fancy format
2022-07-30 12:22:04 -07:00
Jonathan van der Steege
3a5316cedc
Check for duplicate keys in config file (#1511)
* Check for duplicate keys in config file
* Corrected BDD tests
* Unneeded check removed
* Make use of ruamel DuplicateKeyError exception
* Remove unneeded import and function
* slightly reword warning message
* fix merge conflicts
* update tests

Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
2022-07-16 14:21:21 -07:00
Jonathan Wren
0f2962a95f
Add and run isort on Python files (#1520)
* add and run isort

* udpate more import statements

* fix typo
2022-06-25 14:43:32 -07:00
Kevin
8b955ef002
Add bdd tests for jrnl installation (#1513)
* Added bdd tests for jrnl installation
2022-06-25 12:47:05 -07:00
Jonathan Wren
7dccc469b5
Implement Tox for testing (#1504)
* Get rid of `make` in favor of `poe`
This moves the tasks that were previously in Makefile, into
pyproject.toml (with all the other config)

This is also more inclusive of Windows developers since they only need
Python, and no longer have to install make separately.

* update docs
* don't make code blocks also links
* implement tox for testing
* update command to use new task runner
2022-06-18 11:54:28 -07:00
Jonathan Wren
f5e052937c
Update copyright year (#1502)
Update copyright year in comment headers and --version output
2022-06-18 11:30:56 -07:00
Jonathan Wren
f53110c69b
Rework how all output and messaging works in jrnl (#1475)
* fix missed statement from last PR
* replace print statement for adding an entry to a journal
* clean up linting and format
* change print statement over to new print_msg function
* make print_msg always print to stderr
* change print statement over to new print_msg function
* update importer to use new message function
* update yaml format to use new message function
* code cleanup
* update yaml format to use new message function
* update yaml format to use new exception handling
* update Journal class to use new message function
* update install module to use new message function
* update config module to use new message function
* update upgrade module to properly use new message and exception handling
* fix typo
* update upgrade module to use new message handling
* update welcome message to use new handling
* update upgrade module to use new message handling
* update upgrade module journal summaries to use new message handling
* take out old code
* update upgrade module to use new message handling
* update upgrade module to use new message handling
* update more modules to use new message handling
* take out old comment
* update deprecated_cmd to use new message handling
* update text_exporter with new message handling, get rid of old color constants
* get rid of hardcoded text
* whitespace changes
* rework MsgType into MsgStyle so messages can have different styles
* add comment
* Move around code to separate concerns of each function a bit more
* update create_password and yesno prompt functions for new messaging
* fix missing newline for keyboard interrupts
* fix misc linting
* fix bug with panel titles always showing 'error' after one error
* fix missing import
* update debug output after uncaught exception
* update exception for new exception handling
* rewrite yesno function to use new centralized messages
* reduce the debug output slightly
* clean up print_msgs function
* clean up create_password function
* clean up misc linting
* rename screen_input to hide_input to be more clear
* update encrypted journal prompt to use new messaging functionality
* fix typo in message key
* move rich console into function so we can mock properly
* update password mock to use rich console instead of getpass
* add more helpful output to then step
* fix test by updating expected output
* update message to use new functionality
* rework mocks in test suite for new messaging functionality
* fix linting issue
* fix more tests
* fix more tests
* fix more tests
* fix more tests
* fix merge bug
* update prompt_action_entries to use new messaging functionality
* Add new input_method "type"
  This does the same thing as input_method "pipe" but is more clear what
  it's doing (typing text into the builtin composer)
* get rid of old commented code
* get rid of unused code
* move some files around

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
2022-06-11 13:32:11 -07:00
Kevin
c043f5058f
Fixed error related to display_format in config file for some values (#1495)
* Fixed error related to display_format in config file
  Now _display_search_results tries to source the export arg from the
  config file before dispaying search results.
* Add BDD test for original bug
* update unit test

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
2022-06-04 15:13:30 -07:00
Jonathan van der Steege
e758986985
Create folder if config ends with (back)slash (#1492)
* Check config if FolderJournal and treat as so

* Add test for end of path is slash

* Code format correction

* Requested changes PR 1482

* Add info to doc about path of folder.

* Small addition to doc about folder journal
2022-06-04 13:20:51 -07:00
Kevin
36121007b1
-not search parameter doesn't open editor (#1490) 2022-06-04 13:09:07 -07:00
Jonathan van der Steege
663f151974
Prompt for password change when using 'jrnl --encrypt' on already encrypted journal (#1477)
* Create new password if journal already encrypted.
* Add test for encrypting already encrypted journal.
2022-05-21 14:11:55 -07:00
Kevin
ea6df4705c
Always expand all paths (journals, templates, etc) (#1468)
* Refactored path expansion calls into a new path.py file

This also fixed bugs with relative journal and template paths.

* Update tests for new path functions

Also, make the tests specific to Windows, Mac & Linux

Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
2022-05-21 14:06:07 -07:00
Richard Schneider
33c9dce80d
Implement --change-time flag (#1452)
* Implement --change-time flag
* Remove todo from --change-time bdd folder journal tests
* Add warning when --change-time used with no matching entries
* Add a test to make sure running --change-time with nothing prints a warning and doesn't change anything
* Add prompt for --change-time
* Don't prompt for --change-time when used with --edit and only one entry
* When using --edit and --change-time, change the time before editing
* Add test for --change-time used with --edit
* Modify failing --change-time test to conform to text in develop branch
2022-05-21 12:03:27 -07:00
Kevin
8458cdb06f
Fixed -not option with no arguments bug (#1466) 2022-05-07 12:19:37 -07:00
Jonathan van der Steege
792f188ecc
Give a proper message when trying to use an empty config file (#1461)
* Added check for empty config file and if so, use default config

* Added check for empty config file and if so, use default config

* Fix and add tests for empty config file

* Exit program with message if config is empty.
bdd-test doesn't add version if file is (and should stay) empty.

* Exit program with message if config is empty.

* bdd-test doesn't add version if file is (and should stay) empty.

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
2022-05-07 12:13:36 -07:00
Kevin
74200f8dc4
Yaml export errors now don't show stack trace (#1449)
* Yaml export errors now don't show stacktrace

* Add test for user-friendly error when exporting YAML to a nonexistent directory

* Leave partially written to files after export error

* unskip working tests

Co-authored-by: Micah Jerome Ellison <micah.jerome.ellison@gmail.com>
Co-authored-by: Jonathan Wren <jonathan@nowandwren.com>
2022-05-07 11:11:00 -07:00