Add Windows support to preview
with minimal changes & CI support
#351
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #306
Closes #298
Closes #307 (supersedes it)
Hello!
Pull Request overview
doc-builder preview
on Windows without drastic implementation changes.Scope
This PR is intended to add support for
doc-builder preview
for Windows. Other commands, such as building with--html
are out of scope, as I don't believe that these commands are as useful. However, this support can also be added if requested in the future.Details
My experimentation has shown me that there were at least three main issues that prevented doc-builder from working on Windows. This PR tackles these three without negatively affecting other OSes.
Issue 1
Windows users of
doc-builder preview
will be greeted with this Exception:This is caused by these
subprocess.run
commands:doc-builder/src/doc_builder/commands/preview.py
Lines 132 to 147 in f398867
On windows,
shell=True
must be set (False
is the default) to run a command in this manner.The fix
I have set this behaviour using
platform.system() == "Windows"
, causing these changes to only affect Windows users. See theplatform.system()
docs here.Issue 2
The
_toctree.yml
file will commonly contain files in directories, e.g.api/main
. However, on Windows,doc-builder
finds those files asapi\\main
. Exceptions are thrown due to this mismatch incheck_doc_integrity
. A workaround is to useapi\\main
in the_toctree.yml
, but that will then only work for Windows users, which is even worse than the current behaviour.The fix
The fix is elementary, we already rely on
Path
in thischeck_doc_integrity
, so all we have to do is normalize both the toctree paths and the locally-discovered paths usingstr(path)
withpath
as aPath
instance. No need for OS-dependent conditionals here.Issue 3
This issue originates from improper URL modification in the TypeScript
get
endpoint, causing endless exceptions trying to load a path starting withC:\C:\
when the browser is started up:This issue originates here:
doc-builder/kit/src/routes/endpoints/toc.ts
Line 26 in f398867
In this line, the
file://
is replaced in a non-recommended manner. Please have a look at the this comment and the FileURLToPath documentation, which shows that improper use of slicing or replacing can have unintended consequences for cross-platform URLs.The fix
The cross-platform fix is uses the recommended
FileURLToPath
function, which works for all platforms.Tests
For convenience, I have added Windows to the CI test runner. Although I can imagine that the test suite doesn't cover all cases, I imagine the Windows support in the CI would be useful.
Closed issues
As mentioned, this PR closes some issues. I'd like to briefly discuss each:
tmp_dir
in the example is aPath
instance, which is responsible for correctly handling paths through the__truediv__
method.working_dir
instart_sveltekit_dev
.os.path.join
withPath
instances, which is not necessary. The true problem with this PR is that it addsshell=True
at all times, modifying behaviour for Unix users. My PR only makes changes for Windows users.Let me know if you need anything else from me at this point!