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

Remove "dotted files" package format #2686

Closed
scoder opened this issue Oct 27, 2018 · 6 comments
Closed

Remove "dotted files" package format #2686

scoder opened this issue Oct 27, 2018 · 6 comments

Comments

@scoder
Copy link
Contributor

scoder commented Oct 27, 2018

Cython contains some special casing code that compiles a file named pkg.mod.pyx into a package qualified module. This complicates the module search code and leads users to weird directory setups instead of just sticking to the normal Python package layout:

pkg/
  __init__.py
  mod.pyx

All code that searches for pkg.mod.pyx, or that extracts package and module name from such a filename should be removed.

@mattip
Copy link
Contributor

mattip commented Sep 22, 2019

I am willing to take a look at this. What exactly is the proposal - the description is a little terse. Is this a compilation change, a change in the layout of the Include files, or a change to tests?

@mattip
Copy link
Contributor

mattip commented Feb 11, 2020

@scoder could you remove the blocker label or better define the problem?

@scoder
Copy link
Contributor Author

scoder commented Feb 11, 2020

Sorry, I had missed your comment.
This is a blocker because it removes an existing feature (which I consider an unnecessary mis-feature). I'll update the description.

@mattip
Copy link
Contributor

mattip commented Feb 14, 2020

There actually is nothing cython does special. It is enough to create a distutils.extension.Extension with a dot in the name outer_package.inner_module, and distutils will automatically create it in outer_package/inner_module. This is slightly documented in the name docstring:

    Instance attributes:
      name : string
        the full name of the extension, including any packages -- ie.
        *not* a filename or pathname, but Python dotted name

All cython could do is start to check for a name that contains dot and raise an error.

@mattip
Copy link
Contributor

mattip commented Feb 14, 2020

I started writing a srctree test with

PYTHON setup.py build_ext --inplace

######## setup.py ########

from Cython.Build.Dependencies import cythonize
from distutils.core import setup

setup(ext_modules = cythonize("outer_package.inner_module.pyx", language_level=3)

####### outer_package.inner_module.pyx ########

def test():
    pass

The generated module lives in TEST_TMP/errors/package_dot_module/outer_package/inner_module.cpython-36m-x86_64-linux-gnu.so and has code like this in outer_package.inner_module.c:

/* Module declarations from "outer_package.inner_module" */
#if !CYTHON_COMPILING_IN_LIMITED_API
#endif
#define __Pyx_MODULE_NAME "outer_package.inner_module"
extern int __pyx_module_is_main_outer_package__inner_module;
int __pyx_module_is_main_outer_package__inner_module = 0;

/* Implementation of "outer_package.inner_module" */
static const char __pyx_k_main[] = "__main__";
static const char __pyx_k_name[] = "__name__";
static const char __pyx_k_test[] = "test";
static const char __pyx_k_test_2[] = "__test__";
static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback";
static const char __pyx_k_outer_package_inner_module[] = "outer_package.inner_module";
static const char __pyx_k_outer_package_inner_module_pyx[] = "outer_package.inner_module.pyx";
#if !CYTHON_COMPILING_IN_LIMITED_API
static PyObject *__pyx_n_s_cline_in_traceback;
#endif
#if !CYTHON_COMPILING_IN_LIMITED_API
static PyObject *__pyx_n_s_main;
#endif
#if !CYTHON_COMPILING_IN_LIMITED_API
static PyObject *__pyx_n_s_name;
#endif
#if !CYTHON_COMPILING_IN_LIMITED_API
static PyObject *__pyx_n_s_outer_package_inner_module;

@scoder
Copy link
Contributor Author

scoder commented Feb 16, 2020

I added a deprecation warning for this feature. I think that's enough for 3.0.

jschwe added a commit to jschwe/cbindgen that referenced this issue Sep 3, 2023
Since Cython 3.0 using dots appart from the extension is
a hard error. See issue: cython/cython#2686
emilio pushed a commit to mozilla/cbindgen that referenced this issue Sep 4, 2023
Since Cython 3.0 using dots appart from the extension is
a hard error. See issue: cython/cython#2686
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants