[Cython] Why does embed-position use relative filenames?

Erik Bray erik.m.bray at gmail.com
Wed Oct 25 08:42:27 EDT 2017


On Wed, Oct 25, 2017 at 2:24 PM, Jeroen Demeyer <jdemeyer at cage.ugent.be> wrote:
> When Cython is run with the --embed-position option (or when
> Cython.Compiler.Options.embed_pos_in_docstring is true), Cython writes
> headers in the docstring like
>
> File: sage/rings/integer.pyx (starting at line 358)
>
> The filenames that Cython uses here are always made relative to the current
> working directory. This is annoying for tools which extract this information
> for introspection. It would be more useful to just write the path as-is
> instead of making it relative.
>
> It would be easy to change this behaviour in Cython but I was wondering if
> there is a specific reason for these relative paths.

IMO the relative paths make more sense in a way, because when the
module is installed the path is relative to the file's location
relative to its `sys.path` entry.

If it defaulted to absolute paths then it would get
`/path/to/my/source/code/package/module.py` baked into it, which is
deceptive if the module is then installed, say, to `site-packages`.

That's just my guess as to why it's a relative path by default.  I'm
not saying it's always necessarily the best choice--it would be nice
if there were a compiler directive to change this.

Erik


More information about the cython-devel mailing list