Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 1059: Fix downloadable abs path #1060

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions sphinxcontrib/confluencebuilder/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,19 +257,19 @@ def find_env_abspath(env, out_dir, path: str) -> Path | None:
# later stage
return None

if normalized_path.is_absolute():
abs_path = normalized_path
# 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.parts[0] == os.sep:
abs_path = Path(env.srcdir, *normalized_path.parts[1:])

# 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:])
if abs_path.is_file():
return abs_path

if new_path.is_file():
abs_path = new_path
if normalized_path.is_absolute():
abs_path = normalized_path
else:
abs_path = Path(env.srcdir, normalized_path)

Expand Down
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/unit-tests/datasets/download/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ download
:download:`../../assets/example.pdf`

:download:`label<../../assets/example.pdf>`

:download:`files/example.pdf`

.. Absolute filename taken as relative to the top source directory

:download:`/files/example.pdf`
26 changes: 16 additions & 10 deletions tests/unit-tests/test_sphinx_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@ def test_storage_sphinx_download_defaults(self):
out_dir = self.build(self.dataset)

with parse('index', out_dir) as data:
# view-file
view_file_macro = data.find('ac:structured-macro',
# view-file(s)
#
# We have a couple of asset downloads in this example. A mixture
# of paths to sanity check download paths function. All use the
# same/replicated asset type and each will result in a single file
# upload, so we should have three matching view-file macros.
view_file_macros = data.find_all('ac:structured-macro',
{'ac:name': 'view-file'})
self.assertIsNotNone(view_file_macro)
self.assertEqual(len(view_file_macros), 3)

view_file_name = view_file_macro.find('ac:parameter',
{'ac:name': 'name'})
self.assertIsNotNone(view_file_name)
for view_file_macro in view_file_macros:
view_file_name = view_file_macro.find('ac:parameter',
{'ac:name': 'name'})
self.assertIsNotNone(view_file_name)

attachment_ref = view_file_name.find('ri:attachment')
self.assertIsNotNone(attachment_ref)
self.assertTrue(attachment_ref.has_attr('ri:filename'))
self.assertEqual(attachment_ref['ri:filename'], 'example.pdf')
attachment_ref = view_file_name.find('ri:attachment')
self.assertIsNotNone(attachment_ref)
self.assertTrue(attachment_ref.has_attr('ri:filename'))
self.assertEqual(attachment_ref['ri:filename'], 'example.pdf')

# link to file
file_link = data.find('ac:link')
Expand Down
Loading