Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ _trial_temp/
apidocs/
*.egg-info
.eggs
.hypothesis
12 changes: 11 additions & 1 deletion pydoctor/templatewriter/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations

import itertools
import os
from pathlib import Path
from typing import IO, Iterable, Type, TYPE_CHECKING

Expand Down Expand Up @@ -108,7 +109,16 @@ def writeSummaryPages(self, system: model.System) -> None:
# not using missing_ok=True because that was only added in Python 3.8 and we still support Python 3.6
except FileNotFoundError:
pass
root_module_path.symlink_to('index.html')

# When support for Python 3.9 and older is dropped use
# pathlib.Path.hardlink_to() instead.
x = list(root_module_path.parent.glob('*'))
print(f'TTTT\n{root_module_path=} {x=}')
print(f'{root_module_path.exists()=}')
os.link(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I need your help here. First of all I think I confounded the arguments in os.link(). So I changed them but this does not solve the problem.

The value of root_module_path is PosixPath('apidocs/basic.html') which does not exist. That seems to be the problem. But I do not understand why it does not exist or even if it have to exists.
Of course because of that the os.link() can not work.

Copy link
Contributor

@tristanlatr tristanlatr Dec 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of root_module_path is PosixPath('apidocs/basic.html') which does not exist. That seems to be the problem. But I do not understand why it does not exist or even if it have to exists.

I believe it doesn’t exist because it hasn’t been generated yet at the time the index page is generated. This is because the summary pages are written before the individual files, you can see that here:

writer.writeIndividualFiles(subjects)

I guess a symlink doesn’t need the file to exists while a hard link need it to exists. So the fix would be to call writeIndividualFiles before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make totally sense. Thanks for analyzing. Because this is not your own code, are you sure that your solution will do the job? Or I might should do some more research if there is a better location in code to call writeIndividualFiles()?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure: I haven’t tried it.

src=root_module_path, # original
dst=root_module_path.parent / 'index.html' # the hardlink
)

def _writeDocsFor(self, ob: model.Documentable) -> None:
if not ob.isVisible:
Expand Down
3 changes: 3 additions & 0 deletions pydoctor/test/test_commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ def test_main_symlinked_paths(tmp_path: Path) -> None:
link = tmp_path / 'src'
link.symlink_to(Path.cwd(), target_is_directory=True)

print(f'{link=} {link.exists()=}')
print(f'{Path.cwd()=} {Path.cwd().exists()=}')

exit_code = driver.main(args=[
'--project-base-dir=.',
'--html-viewsource-base=http://example.com',
Expand Down
3 changes: 3 additions & 0 deletions pydoctor/test/test_templatewriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,14 @@ def test_basic_package(tmp_path: Path) -> None:
root, = system.rootobjects
w._writeDocsFor(root)
w.writeSummaryPages(system)

for ob in system.allobjects.values():
url = ob.url
if '#' in url:
url = url[:url.find('#')]

assert (tmp_path / url).is_file()

with open(tmp_path / 'basic.html', encoding='utf-8') as f:
assert 'Package docstring' in f.read()

Expand Down