sphinx-contrib / confluencebuilder

Confluence Markup Builder Plugin for Sphinx
BSD 2-Clause "Simplified" License
316 stars 99 forks source link

[2.5+] Downloadable files not found anymore when using sphinx 'absolute' paths (in truth relative to 'src') #1059

Open Paldari opened 2 hours ago

Paldari commented 2 hours ago

Hello,

Issue (regression) appearing from confluencebuilder 2.5

Issue description

After updating confluencebuilder from version 2.4 to 2.8 (yeah, it's been a long time...) we started to get issues with :download: role when using an absolute path (absolute in the sense of Sphinx, i.e. the root is actually the repository root dir -env.srcdir- not the system root).

Note: It is still working fine with the HTML Builder.

Small example with a downloadable file located in a sphinx repo at: migrated-static/files/myppt.ppt

:download:`My PPT file </migrated-static/files/myppt.ppt>`

We get some logs like these (verbose only):

[confluence] failed to find path: /migrated-static/files/myppt.ppt
[confluence] process file node: /migrated-static/files/myppt.ppt

And a WARNING at the end:

WARNING: unable to find download: /migrated-static/files/myppt.ppt [confluence]

Could you please restore this functionnality and support these pseudo-absolute path?

Investigation

Regression seems to come from this commit in utils.py file: Commit 336725c

More specifically:

        # some generated nodes will prefix the path of an asset with `/`,
        # with the intent of that path being the root from the
        # configured source directory instead of an absolute path on the
        # system -- check the environment's source directory first before
        # checking the full system's path
        if normalized_path.name[0] == os.sep:
            new_path = Path(env.srcdir, normalized_path.name[1:])

normalized_path.name returns the last part of the path (name of the file) while this check was initially supposed to check the first char of the whole file path.

Report

(system)
 platform: Linux-5.15.153.1-microsoft-standard-WSL2-x86_64-with-glibc2.35
   python: 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0]
   sphinx: 8.1.3
 docutils: 0.21.2
 requests: 2.31.0
  urllib3: 2.1.0
  builder: 2.8.0

(configuration)
confluence_cleanup_purge: True
confluence_cleanup_search_mode: direct
confluence_disable_notifications: True
confluence_full_width: True
confluence_page_hierarchy: True
confluence_parent_page: (set)
confluence_publish: True
confluence_server_url: https://(removed) (cloud)
confluence_space_key: (set; upper)
confluence_timeout: 10

(confluence instance)
 connected: no
Paldari commented 2 hours ago

I can propose a small Pull Request to fix this, later today or tomorrow (tested only locally so far).

But I'm wondering if a better long term fix wouldn't be to rely on Sphinx utilities for that sort of path manipulation.

For instance: env.relfn2path(...) It would require some more changes though...