getnikola/nikola

nikola auto throws ValueError exception on rebuild

wohali opened this issue · 6 comments

Environment

Python Version: 3.11.2

Nikola Version: master 0a533d6

Operating System: WSL 2.0

Description:

nikola auto throws an exception when rebuilding, though the rebuild seems to be successful:

$ nikola auto
[2024-03-14 17:54:06] INFO: auto: REBUILDING SITE
[2024-03-14 17:54:07] INFO: auto: Rebuild successful
Scanning posts........done!

[2024-03-14 17:54:07] INFO: auto: Serving on http://127.0.0.1:8000/ ...
[2024-03-14 17:54:15] INFO: auto: REBUILDING SITE
[2024-03-14 17:54:16] ERROR: asyncio: Task exception was never retrieved
future: <Task finished name='Task-25' coro=<CommandAuto.reload_page() done, defined at /usr/local/lib/python3.11/dist-packages/nikola/plugins/command/auto/__init__.py:426> exception=ValueError('no path specified')>
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/nikola/plugins/command/auto/__init__.py", line 434, in reload_page
    p = os.path.relpath(event_path, os.path.abspath(self.site.config['OUTPUT_FOLDER'])).replace(os.sep, '/')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen posixpath>", line 490, in relpath
ValueError: no path specified
[2024-03-14 17:54:16] ERROR: asyncio: Task exception was never retrieved
future: <Task finished name='Task-26' coro=<CommandAuto.reload_page() done, defined at /usr/local/lib/python3.11/dist-packages/nikola/plugins/command/auto/__init__.py:426> exception=ValueError('no path specified')>
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/dist-packages/nikola/plugins/command/auto/__init__.py", line 434, in reload_page
    p = os.path.relpath(event_path, os.path.abspath(self.site.config['OUTPUT_FOLDER'])).replace(os.sep, '/')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen posixpath>", line 490, in relpath
ValueError: no path specified
[2024-03-14 17:54:16] INFO: auto: Rebuild successful
Scanning posts........done!
.  render_posts:timeline_changes
.  render_posts:cache/pages/pagename.html
.  render_pages:output/page-name/index.html
.  sitemap:output/sitemap.xml

^C[2024-03-14 17:54:44] INFO: auto: Server is shutting down.

Can you add some print statements to figure out what arguments are passed to os.path.relpath on the offending line?

        print(f"event_path = {event_path}")
        print(f"OUTPUT_FOLDER = {self.site.config['OUTPUT_FOLDER']}")
        p = os.path.relpath(event_path, os.path.abspath(self.site.config['OUTPUT_FOLDER'])).replace(os.sep, '/')

results in:

event_path =
OUTPUT_FOLDER = output

I have a very similar issue on macOS.
Previously I used a Python 3.11 virtual environment and I had no problem. Now I created a new virtual env fior Python 3.12 and I have:

[2024-04-20 15:47:29] INFO: auto: REBUILDING SITE
event_path: 
config: output
[2024-04-20 15:47:32] ERROR: asyncio: Task exception was never retrieved
future: <Task finished name='Task-43' coro=<CommandAuto.reload_page() done, defined at /Users/rousseau/.virtualenvs/nikola/lib/python3.12/site-packages/nikola/plugins/command/auto/__init__.py:426> exception=ValueError('no path specified')>
Traceback (most recent call last):
  File "/Users/rousseau/.virtualenvs/nikola/lib/python3.12/site-packages/nikola/plugins/command/auto/__init__.py", line 436, in reload_page
    p = os.path.relpath(event_path, os.path.abspath(self.site.config['OUTPUT_FOLDER'])).replace(os.sep, '/')
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen posixpath>", line 509, in relpath
ValueError: no path specified

As suggested I print the values of event_path and self.site.config['OUTPUT_FOLDER'].

I also have another error that might be related:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.12/3.12.2_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/Users/rousseau/.virtualenvs/nikola/lib/python3.12/site-packages/watchdog/observers/api.py", line 223, in run
    self.dispatch_events(self.event_queue)
  File "/Users/rousseau/.virtualenvs/nikola/lib/python3.12/site-packages/watchdog/observers/api.py", line 402, in dispatch_events
    handler.dispatch(event)
  File "/Users/rousseau/.virtualenvs/nikola/lib/python3.12/site-packages/nikola/plugins/command/auto/__init__.py", line 627, in dispatch
    if event._src_path == self.configuration_filename:
       ^^^^^^^^^^^^^^^
AttributeError: 'FileModifiedEvent' object has no attribute '_src_path'. Did you mean: 'src_path'?

I added a print(event) and I get:
FileModifiedEvent(src_path='/Users/rousseau/Documents/blog/blog.apdu.fr/.doit.db.db', dest_path='', event_type='modified', is_directory=False, is_synthetic=False)

The event object does not have a _src_path but a src_path.

@LudovicRousseau Your issue is #3761, it’s fixed on the master branch, and will be fixed in v8.3.1, which I plan to release today.

The issue here seems to be event_path being a blank string. Looking back a step at when event_path is set

event_path = event.dest_path if hasattr(event, 'dest_path') else event.src_path

we see event_path = event.dest_path when dest_path is present but empty. When I get this error, event has the following values, including a blank dest_path

FileModifiedEvent(src_path='output/posts/1/index.rst', dest_path='', event_type='modified', is_directory=False, is_synthetic=False)

So perhaps changing that line to

event_path = getattr(event, 'dest_path', None) or event.src_path

fixes the issue. This code looks pretty old, so I'm not sure what changed to start causing this issue, probably something in watchdog.

@clayadavis I confirm you proposed patch fixes the issue for me.
Thanks