lervag / apy

CLI script for interacting with local Anki collection
MIT License
228 stars 17 forks source link

Error: Path is None on apy add #8

Closed gottschali closed 4 years ago

gottschali commented 4 years ago
$ apy add
Traceback (most recent call last):
  File "/home/ali/.local/bin/apy", line 11, in <module>
    load_entry_point('apy==0.1', 'console_scripts', 'apy')()
  File "/home/ali/.local/lib/python3.8/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/home/ali/.local/lib/python3.8/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/home/ali/.local/lib/python3.8/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/ali/.local/lib/python3.8/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ali/.local/lib/python3.8/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/home/ali/.local/lib/python3.8/site-packages/apy/cli.py", line 62, in add
    with Anki(cfg['base']) as a:
  File "/home/ali/.local/lib/python3.8/site-packages/apy/anki.py", line 15, in __init__
    self._init_load_collection(base, path)
  File "/home/ali/.local/lib/python3.8/site-packages/apy/anki.py", line 41, in _init_load_collection
    basepath = Path(base)
  File "/usr/lib/python3.8/pathlib.py", line 1018, in __new__
    self = cls._from_parts(args, init=False)
  File "/usr/lib/python3.8/pathlib.py", line 667, in _from_parts
    drv, root, parts = self._parse_args(args)
  File "/usr/lib/python3.8/pathlib.py", line 651, in _parse_args
    a = os.fspath(a)
TypeError: expected str, bytes or os.PathLike object, not NoneType

Anki is at /usr/share/anki Cloned and pip-installed as in README (not developer version)

gottschali commented 4 years ago

Should read --help more carefully. -b, --base TEXT Set Anki base directory apy -b .local/share/share/Anki2 in my case

gottschali commented 4 years ago

Well it finds my decks and note types, but I still get the same error on info/add/list/ and basically every other command.

lervag commented 4 years ago

That's strange. It would help if you could show me the exact command that you use when you also include the -b option.

In your last comment, it seems it works for some commands but not for others. Again, it is much easier to help if you are specific. What works, what does not work?

Note: You can specify the -b option in the config file located at ~/.config/apy/apy.json. My config file looks like this:

{
  "base": "/home/lervag/documents/anki",
  "pngCommands": [
    ["latex", "-interaction=nonstopmode", "tmp.tex"],
    ["dvipng", "-D", "150", "-T", "tight", "-bg", "Transparent",
      "tmp.dvi", "-o", "tmp.png"]
  ],
  "svgCommands": [
    ["lualatex", "-interaction=nonstopmode", "tmp.tex"],
    ["pdfcrop", "tmp.pdf", "tmp.pdf"],
    ["pdf2svg", "tmp.pdf", "tmp.svg"]
  ]
}
gottschali commented 4 years ago

Ok the problem was that I thought apy --base would set the path permenantly... With "base": "/home/ali/.local/share/Anki2/", for my case in my config it now works like a charm.

lervag commented 4 years ago

Great, happy to hear it! And please, open more issues if you find things not working as expected or if you have ideas for how to improve.