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

BUG: posixpath.normal path returns invalid path on Windows #9018

Closed
bashtage opened this issue Mar 19, 2021 · 2 comments
Closed

BUG: posixpath.normal path returns invalid path on Windows #9018

bashtage opened this issue Mar 19, 2021 · 2 comments
Labels
Milestone

Comments

@bashtage
Copy link

bashtage commented Mar 19, 2021

Describe the bug

The use of posixpath.normalpath

in

        return (posixpath.normpath(rel_fn),
                path.normpath(path.join(self.srcdir, rel_fn)))

breaks windows builds when the source and build directory are not nested.

The reason this happen is that path.join inserts windows seperators that posixpath doesn't understand.

To Reproduce

Any project with a structure like

doc/ doc/source/conf.py doc/build/ <build dir>

breaks since this fix assumes that build is under source.

Heading into the function, rel_fn has a value like

bootstrap\\../../build/.doctrees/nbsphinx/bootstrap_bootstrap_examples_15_0.png

This needs to be converted to

../../build/.doctrees/nbsphinx/bootstrap_bootstrap_examples_15_0.png

which is the correct location but

is instead converted to

build/.doctrees/nbsphinx/bootstrap_bootstrap_examples_15_0.png

which is wrong.

Expected behavior
Get the correct path on windows so docs can build

Your project

https://github.com/bashtage/arch/tree/main/doc

Fix

The fix is to replace

posixpath.normpath(rel_fn)

with

posixpath.relpath(rel_fn, self.srcdir)
@bashtage
Copy link
Author

bashtage commented Mar 19, 2021

An even better fix

Only change is to add in pathlib.Path(rel_fn).as_posix() to ensure that the window path looks like a posix path.

    def relfn2path(self, filename: str, docname: str = None) -> Tuple[str, str]:
        """Return paths to a file referenced from a document, relative to
        documentation root and absolute.

        In the input "filename", absolute filenames are taken as relative to the
        source dir, while relative filenames are relative to the dir of the
        containing document.
        """
        if filename.startswith('/') or filename.startswith(os.sep):
            rel_fn = filename[1:]
        else:
            docdir = path.dirname(self.doc2path(docname or self.docname,
                                                base=None))
            rel_fn = path.join(docdir, filename)

        return (posixpath.normpath(pathlib.Path(rel_fn).as_posix()),
                path.normpath(path.join(self.srcdir, rel_fn)))

@bashtage bashtage changed the title BUG: posixpath.normal path returns invalid path BUG: posixpath.normal path returns invalid path on Windows Mar 19, 2021
@tk0miya
Copy link
Member

tk0miya commented Mar 19, 2021

I think your problem will be resolved by #8967. Could you check it please? If fine, I'll ship a bugfix release soon.
Thanks,

@tk0miya tk0miya added this to the 3.5.3 milestone Mar 19, 2021
@tk0miya tk0miya closed this as completed Mar 20, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants