Skip to content

top-level __init__.py confuses cython; can we remove? #367

Closed
@gojomo

Description

The top-level __init__.py seems to confuse cython – which apparently climbs the dir tree to find the 'package' directory. When my gensim clone is named something with a '-' (as is common, eg 'gensim-develop') cython fails with a message like "'gensim-develop.gensim.models.doc2vec_inner' is not a valid module name". My workaround has been to temporarily rename the directory for each compilation.

But that leads to path cruft in the compiled C, and cython remains confused about the proper project-relative paths to things – which makes sharing definitions/functions (even between the sibling files word2vec_inner & doc2vec_inner) impossible.

I was baffled by the behavior for a long time, and only after a post to cython-users did someone point me at the __init__.py as the issue. (See https://groups.google.com/d/msg/cython-users/d-3Clm2EkHs/G7CJish_c4kJ.) After locally removing __init__.py, I can skip the workaround and finally cimport a function from word2vec_inner to doc2vec_inner (rather than cut & paste).

It looks like the file is a workaround from ~4 years ago; the commit comment from @dedan says: "fix the module import when linking to the git root instead of module – for some application I need to link to the gensim folder which is also the root of the repository. This script helps python to find the actual sourcecode of the module and had to be changed because radim moved the source within the repo".

That seems a pretty narrow need that may have expired. (Any thoughts, @dedan?) But I'd also be interested to know if there's another workaround others who've been preparing cython-compiled C files have used...

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions