Skip to content

Windows build fails when using slashes in site_name #143

@GionRubitschung

Description

@GionRubitschung

I have a monorepo setup. Since I have quite a lot of packages the documentation started to get messy and I wanted to break it down a bit more. This is how in a submodule the mkdocs.yml looks like:

site_name: instruments/midas-adam-switch

This works without problems on linux systems, however we also have devs on windows and there it seems the slash is causing problems:

ERROR   -  Error reading page 'instruments/midas-adam-switch/api/adam.md': join() missing 1 required positional argument: 'path'
Traceback (most recent call last):
      ...
  File "C:\Users\rubigi\git\midas\.venv\lib\site-packages\mkdocs_monorepo_plugin\edit_uri.py", line 39, in __get_page_dir_alias
    alias = path.join(*parts)
TypeError: join() missing 1 required positional argument: 'path'

So the error originates from here.

I added some print statements to the file in my venv to have some example output:

    def __get_page_dir_alias(self):
        parts = self.page.url.split("/")
        print(f'{self.plugin.aliases.keys()=}')
        while True:
            print(f'{parts=}')
            parts.pop()
            alias = path.join(*parts)
            print(f'{alias=}')
            if alias in self.plugin.aliases:
                return alias

Which outputs:

self.plugin.aliases.keys()=dict_keys(['instruments/midas-adam-switch'])
parts=['instruments', 'midas-adam-switch', 'api', 'adam', '']
alias='instruments\\midas-adam-switch\\api\\adam'
parts=['instruments', 'midas-adam-switch', 'api', 'adam']
alias='instruments\\midas-adam-switch\\api'
parts=['instruments', 'midas-adam-switch', 'api']
alias='instruments\\midas-adam-switch'
parts=['instruments', 'midas-adam-switch']
alias='instruments'
parts=['instruments']

The fix is actually quite simple, normalize the windows backslashes:

def __get_page_dir_alias(self):
        parts = self.page.url.split("/")
        while True:
            parts.pop()
            alias = path.join(*parts).replace("\\", "/")
            if alias in self.plugin.aliases:
                return alias

Which fixes the pathing on windows. I tested the fix on both linux and windows and it worked for me in both cases. I would be willing to open a pr to address this, but wanted to create an issue first to discuss 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions