Git Product home page Git Product logo

Comments (6)

lervag avatar lervag commented on September 27, 2024 1

Ah, yes. If you were to quit with :cquit in Vim, this would work as expected. But I think apy does not properly handle if the notes are not parseable (e.g. if you try to add an empty note, as in this case). I'll fix it. I guess the most natural behaviour would be to issue a warning when a note was not successfully parsed, and then avoid the error.

from apy.

lervag avatar lervag commented on September 27, 2024 1

Thanks! I've copied your cli tests! I was not aware of the click.testing module and I very much like the use of the temporary directories for testing as you've done here. Again, thanks!

Also, I can now reproduce the error and I'll look into a way to fix it!

from apy.

lervag avatar lervag commented on September 27, 2024 1

Thanks! I added a similar check for the n_notes attribute. In principle, I think there might still be a slight bug here, since the empty.md note is still parsed and we try to add it. It is detected as a dupe and so no notes are actually added.

In any case, I think the point here is not to become perfect. Good is good enough. When I make mistakes, I have found I can still use apy to fix them quite easily with the apy review function.

I really appreciate your effort, it is very nice to get some help in fixing issues and improving this utility. apy is already at 95% fully functional for me, but it might have some rough edges especially with regard to other users workflows and similar. As such, it is very nice to get help in fixing these.

from apy.

lervag avatar lervag commented on September 27, 2024

Ok, I can't quite reproduce this, actually. I think the issue is something else. Not sure exactly how to fix this unlless I can reproduce it, sorry.

Note: You should clean up such notes with e.g. apy review -q added:1 or the Anki browser and delete them, as it seems you might have actually added notes this way.

from apy.

ckp95 avatar ckp95 commented on September 27, 2024

Ok, I can't quite reproduce this, actually. I think the issue is something else. Not sure exactly how to fix this unlless I can reproduce it, sorry.

Have a look at my cli-tests branch, the test case test_cli_add_from_file reproduces it for me. I tested using the CLI interface itself because I couldn't reproduce it with the a.add_notes_from_file(filename) way like in the current test functions. Does this show the problem on your end?

(oh and you'll need to run pytest --ignore=tests/test_decks.py because that branch doesn't have this change in it)

from apy.

ckp95 avatar ckp95 commented on September 27, 2024

Returning early if n_decks == 0 in add and add_from_file seemed to fix it for me:

diff --git a/apy/cli.py b/apy/cli.py
index d6dfcf0..221bc5e 100644
--- a/apy/cli.py
+++ b/apy/cli.py
@@ -76,6 +76,10 @@ def add(tags, model, deck):
         decks = [a.col.decks.name(c.did) for n in notes for c in n.n.cards()]
         n_notes = len(notes)
         n_decks = len(decks)
+        
+        if n_decks == 0:
+            click.echo("No notes added")
+            return None
 
         if a.n_decks > 1:
             if n_notes == 1:
@@ -108,6 +112,10 @@ def add_from_file(file, tags):
         n_notes = len(notes)
         n_decks = len(decks)
 
+        if n_decks == 0:
+            click.echo("No notes added")
+            return None
+
         if a.n_decks > 1:
             if n_notes == 1:
                 click.echo(f'Added note to deck: {decks[0]}')

from apy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.