-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added the option to ignore files and folders via settings (#289)
* added rudimentary support for ignoring files * Added File Ignore Settings * Increased width of the ignore file settings textarea * fixed issue that occured when ignore settings were not initialized * fixed problem with loading settings if ignore settings don't exist * bumped version for release in niposch/obsidian_to_anki * Style.css and manifest are copied to build output folder * created prerelease 3.5.0-prerelease2 * handle undefined value when setting isn't initialized properly * reverted changes to rollup config * added missing dependency * reverted change to format.ts * added tests for ignore setting * Extended ignore_setting test to test if scandir and ignore setting work properly together * Added default glob for excalidraw; description in readme and plugin setting * fixed python tests * Squashed commit of the following: commit 867f230 Author: niposch <[email protected]> Date: Tue Jan 23 16:34:09 2024 +0100 fixed python tests * revert folder scan changes * fix ignore_setting.py * Update README.md * revert changes in test_folder_scan --------- Co-authored-by: Harsha Raghu <[email protected]>
- Loading branch information
1 parent
fd29403
commit af2424d
Showing
16 changed files
with
375 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import re | ||
import pytest | ||
from anki.errors import NotFoundError # noqa | ||
from anki.collection import Collection | ||
from anki.collection import SearchNode | ||
|
||
# from conftest import col | ||
|
||
test_name = "ignore_setting" | ||
col_path = "tests/test_outputs/{}/Anki2/User 1/collection.anki2".format(test_name) | ||
|
||
test_file_paths = [ | ||
"tests/test_outputs/{}/Obsidian/{}/scan_dir/included_file.md".format( | ||
test_name, test_name | ||
), | ||
"tests/test_outputs/{}/Obsidian/{}/scan_dir/some/other/subdir/also_included_file.md".format( | ||
test_name, test_name | ||
), | ||
] | ||
|
||
test_file_no_cards_paths = [ | ||
"tests/test_outputs/{}/Obsidian/{}/outside_of_scandir/not_supposed_to_be_scanned.md".format( | ||
test_name, test_name | ||
), | ||
"tests/test_outputs/{}/Obsidian/{}/scan_dir/ignored_by_setting_ignored/not_supposed_to_be_scanned.md".format( | ||
test_name, test_name | ||
), | ||
"tests/test_outputs/{}/Obsidian/{}/scan_dir/ignored_by_setting_ignored/some/other/subdir/not_supposed_to_be_scanned.md".format( | ||
test_name, test_name | ||
), | ||
] | ||
|
||
|
||
@pytest.fixture() | ||
def col(): | ||
col = Collection(col_path) | ||
yield col | ||
col.close() | ||
|
||
|
||
def test_col_exists(col): | ||
assert not col.is_empty() | ||
|
||
|
||
def test_deck_default_exists(col: Collection): | ||
assert col.decks.id_for_name("Default") is not None | ||
|
||
|
||
def test_cards_count(col: Collection): | ||
assert len(col.find_cards(col.build_search_string(SearchNode(deck="Default")))) == 6 | ||
|
||
|
||
def test_cards_ids_from_obsidian(col: Collection): | ||
ID_REGEXP_STR = r"\n?(?:<!--)?(?:ID: (\d+).*)" | ||
|
||
obs_IDs = [] | ||
for obsidian_test_md in test_file_paths: | ||
with open(obsidian_test_md) as file: | ||
for line in file: | ||
output = re.search(ID_REGEXP_STR, line.rstrip()) | ||
if output is not None: | ||
output = output.group(1) | ||
obs_IDs.append(output) | ||
|
||
anki_IDs = col.find_notes(col.build_search_string(SearchNode(deck="Default"))) | ||
for aid, oid in zip(anki_IDs, obs_IDs): | ||
assert str(aid) == oid | ||
|
||
|
||
def test_no_cards_added_from_ignored_paths(col: Collection): | ||
ID_REGEXP_STR = r"\n?(?:<!--)?(?:ID: (\d+).*)" | ||
|
||
for obsidian_test_md in test_file_no_cards_paths: | ||
obs_IDs = [] | ||
with open(obsidian_test_md) as file: | ||
for line in file: | ||
output = re.search(ID_REGEXP_STR, line.rstrip()) | ||
if output is not None: | ||
output = output.group(1) | ||
obs_IDs.append(output) | ||
|
||
assert len(obs_IDs) == 0 |
71 changes: 71 additions & 0 deletions
71
...ults/test_vault_suites/ignore_setting/.obsidian/plugins/obsidian-to-anki-plugin/data.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"settings": { | ||
"CUSTOM_REGEXPS": { | ||
"Basic": "", | ||
"Basic (and reversed card)": "", | ||
"Basic (optional reversed card)": "", | ||
"Basic (type in the answer)": "", | ||
"Cloze": "" | ||
}, | ||
"FILE_LINK_FIELDS": { | ||
"Basic": "Front", | ||
"Basic (and reversed card)": "Front", | ||
"Basic (optional reversed card)": "Front", | ||
"Basic (type in the answer)": "Front", | ||
"Cloze": "Text" | ||
}, | ||
"CONTEXT_FIELDS": {}, | ||
"FOLDER_DECKS": {}, | ||
"FOLDER_TAGS": {}, | ||
"Syntax": { | ||
"Begin Note": "START", | ||
"End Note": "END", | ||
"Begin Inline Note": "STARTI", | ||
"End Inline Note": "ENDI", | ||
"Target Deck Line": "TARGET DECK", | ||
"File Tags Line": "FILE TAGS", | ||
"Delete Note Line": "DELETE", | ||
"Frozen Fields Line": "FROZEN" | ||
}, | ||
"Defaults": { | ||
"Scan Directory": "ignore_setting/scan_dir", | ||
"Tag": "Obsidian_to_Anki", | ||
"Deck": "Default", | ||
"Scheduling Interval": 0, | ||
"Add File Link": false, | ||
"Add Context": false, | ||
"CurlyCloze": true, | ||
"CurlyCloze - Highlights to Clozes": false, | ||
"ID Comments": true, | ||
"Add Obsidian Tags": false | ||
}, | ||
"IGNORED_FILE_GLOBS": [ | ||
"ignore_setting/scan_dir/*ignored/**" | ||
] | ||
}, | ||
"Added Media": [], | ||
"File Hashes": {}, | ||
"fields_dict": { | ||
"Basic": [ | ||
"Front", | ||
"Back" | ||
], | ||
"Basic (and reversed card)": [ | ||
"Front", | ||
"Back" | ||
], | ||
"Basic (optional reversed card)": [ | ||
"Front", | ||
"Back", | ||
"Add Reverse" | ||
], | ||
"Basic (type in the answer)": [ | ||
"Front", | ||
"Back" | ||
], | ||
"Cloze": [ | ||
"Text", | ||
"Back Extra" | ||
] | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
tests/defaults/test_vault_suites/ignore_setting/ignore_setting.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Just a file for the test to open |
Oops, something went wrong.