papis
                                
                                 papis copied to clipboard
                                
                                    papis copied to clipboard
                            
                            
                            
                        commands.default: fail softly when no library paths are found
This should fix some issues when working with a new configuration file:
- Calling papis add --help(and all other) no longer shows a traceback, but a nicer error message.
- papis initcan be used without crashing horribly too.
- Removed logging messages in Configuration.initializebecause they weren't showing up correctly anyway.
Towards fixing #697.
Testing, I am getting the following behaviour:
Without $XDG_CONFIG_HOME/papis/:
$ ls "$XDG_CONFIG_HOME/papis/" ls: cannot access '/home/gesh/.local/etc/papis/': No such file or directory $ papis<TAB> add browse config exec git merge rename serve addto cache doctor explore init mv rm update bibtex citations edit export list open run $ pwd /home/gesh $ papis init [INFO] commands.init: Initializing a new config file: '/home/gesh/.local/etc/papis/config'. [INFO] commands.init: Setting library location: Name of the library (gesh): ... Do you want to save? (Y/n): Traceback (most recent call last): File "/usr/bin/papis", line 8, in
sys.exit(run()) ^^^^^ File "/usr/lib/python3.11/site-packages/click/core.py", line 1157, in call return self.main(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/click/core.py", line 1078, in main rv = self.invoke(ctx) ^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/click/core.py", line 1688, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/click/core.py", line 1434, in invoke return ctx.invoke(self.callback, **ctx.params) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/click/core.py", line 783, in invoke return __callback(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/site-packages/papis/commands/init.py", line 137, in cli with open(config_file, "w") as configfile: ^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: '/home/gesh/.local/etc/papis/config' 
(Note -- besides this error, it is confusing that papis init talks of knowing a library called papers when it hasn't been configured yet. Either drop all mention of that library (folding its defaults into the defaults for initializing the library at PWD, or make it the default name for a library when generating a config file from scratch (i.e. make it the default prompt for the Name of the library? question at the start)
If I instead create the directory $XDG_CONFIG_HOME/papis, I get the usual errors:
$ mkdir "$XDG_CONFIG_HOME/papis" $ papis init [ERROR] commands.default: Library 'papers' does not have any folders attached to it. Please create and add the required paths to the configuration file. [WARNING] commands.init: Config file '/home/gesh/.local/etc/papis/config' already exists! [WARNING] commands.init: This command may change some of its contents, e.g. whitespace and comments are not preserved. Do you want to continue? (Y/n): n $ cat "$XDG_CONFIG_HOME/papis/config" [papers] dir = ~/Documents/papers
[settings] default-library = papers
So it seems you've only silenced the tab-completion in case the config file couldn't be created, not disabled the config-generation-before-tab-completion codepath.
Hope this helps.
@hseg Thank you so much for testing this! It's been super helpful.
FileNotFoundError: [Errno 2] No such file or directory: '/home/gesh/.local/etc/papis/config'
This should be fixed now. The issue was that it tried to save the configuration file, but its parent folder didn't exist, so it crashed and burned on open.
Note -- besides this error, it is confusing that
papis inittalks of knowing a library calledpaperswhen it hasn't been configured yet.
Unless I'm misunderstanding, this refers to the bottom prompt saying Known libraries: 'papers'? That should also be fixed now. I couldn't get it to mention the papers library in other places either, so fingers crossed.
If I instead create the directory
$XDG_CONFIG_HOME/papis, I get the usual errors:
Trying this on an empty XDG_CONFIG_HOME/papis folder, i.e. with no configuration file, I now get:
[INFO] commands.init: Initializing a new config file: '/mnt/data/code/projects/papis/papis/local-init-tmp/papis/config'.
[INFO] commands.init: Setting library location:
Name of the library (papis):
No configuration file should be created before papis init saves one and it also doesn't mention any papers library at this point either anymore.
So it seems you've only silenced the tab-completion in case the config file couldn't be created, not disabled the config-generation-before-tab-completion codepath.
I think this should also be fixed now because we no longer create a configuration file without papis init or manual user intervention.
Hope this helps.
It helped a lot! Thank you again :heart:
Just a note to myself: this added quite a few workarounds in various places.
It would be nicer if we could refactor papis to properly support the "no-library" or "no-config-file" so most places can just go if not libraries: return. This seems like quite a bit of work though..
@hseg Have you had a chance to look at this again?
Not yet, can probably check Tuesday.
El 13 de marzo de 2024 20:29:50 GMT+02:00, Alex Fikl @.***> escribió:
@hseg Have you had a chance to look at this again?
-- Reply to this email directly or view it on GitHub: https://github.com/papis/papis/pull/741#issuecomment-1995298803 You are receiving this because you were mentioned.
Message ID: @.***>
Not yet, can probably check Tuesday.
That would be great! Thank you!
OK, so testing it, it all seems to be fixed!
Perhaps the only thing I'd add here is that papis init seems to be a common
codepath (i.e. I'd expect to run it once per research domain, setting up
libraries for each). Having it need to warn about not preserving whitespace and
comments makes it feel less polished.
Unless the common usecase is to have a single library for all research?
OK, so testing it, it all seems to be fixed!
Awesome! Thank you very much for helping out with this and reporting all the issues!
Perhaps the only thing I'd add here is that
papis initseems to be a common codepath (i.e. I'd expect to run it once per research domain, setting up libraries for each). Having it need to warn about not preserving whitespace and comments makes it feel less polished. Unless the common usecase is to have a single library for all research?
I agree it's not great that we have to warn about that. Ideally we'll move to toml or some other format that can preserve comments and whitespace, but for now it seems like a good idea to warn so that we don't mess up the config of someone who modifies their config manually as well..
I'll go ahead and merge this and we can tweak it further if needed! :rocket: