Fortran-FOSS-Programmers / ford

Automatically generates FORtran Documentation from comments within the code.
https://forddocs.readthedocs.io
GNU General Public License v3.0
410 stars 134 forks source link

Path.resolve can not resolve urls #648

Closed econwang closed 3 months ago

econwang commented 7 months ago

The relative_url function in output.py:

    link_str = str(entity)
    link = BeautifulSoup(link_str, features="html.parser").a
    if link is not None:
        link_path = str(pathlib.Path(str(link["href"])).resolve())
    else:
        link_path = link_str

will raise error for urls, such as INTRINSIC_MODS in settings.py.

ZedThree commented 4 months ago

Thanks for reporting this @econwang, sorry it's taken so long to take a look! Do you have an example that errors? The examples include e.g. use iso_fortran_env and the links work ok.

econwang commented 4 months ago

Yes, it works with PosixPath, so no problem on linux, but on windows, it will raise WinError 123 error.

In [1]: import pathlib

In [2]: url = 'https://github.com/Fortran-FOSS-Programmers/ford/issues/648'

In [3]: pathlib.Path(url).resolve()
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
Cell In[3], line 1
----> 1 pathlib.Path(url).resolve()

File C:\Intel\intelpython\lib\pathlib.py:1215, in Path.resolve(self, strict)
   1209 def resolve(self, strict=False):
   1210     """
   1211     Make the path absolute, resolving all symlinks on the way and also
   1212     normalizing it (for example turning slashes into backslashes under
   1213     Windows).
   1214     """
-> 1215     s = self._flavour.resolve(self, strict=strict)
   1216     if s is None:
   1217         # No symlink resolution => for consistency, raise an error if
   1218         # the path doesn't exist or is forbidden
   1219         self.stat()
ZedThree commented 4 months ago

Ah, yes I can see how that would be a problem! I think the obvious fix is just skip this for links already beginning with http