Comments (10)
There seems to be only very few information online about ext_package
. Could you describe a bit more in detail how this argument would change the structure of the wheel or unpacked package?
from maturin.
@konstin of course! It isn't well documented, you are right. An example is here: python/typed_ast#85. Essentially it moves the _ast27
and _ast3
modules into a typed_ast
package. So instead of import _ast3
one must from typed_ast import _ast3
, which means your extension modules end up namespaced as they probably should be.
from maturin.
I believe this shouldn't be too hard to accomplish similar to how distutils does it, which is to just create an additional directory between the files to be installed and the toplevel. I can work on a PR.
from maturin.
I've built typed_ast and got the following wheels:
Without ext_package:
├── _ast27.cpython-36m-x86_64-linux-gnu.so
├── _ast3.cpython-36m-x86_64-linux-gnu.so
├── typed_ast
│ ├── _ast27.cpython-36m-x86_64-linux-gnu.so
│ ├── ast27.py
│ ├── _ast3.cpython-36m-x86_64-linux-gnu.so
│ ├── ast3.py
│ ├── conversions.py
│ ├── __init__.py
│ └── tests
│ └── test_basics.py
└── typed_ast-1.3.2.dev0.dist-info
├── LICENSE
├── METADATA
├── RECORD
├── top_level.txt
└── WHEEL
With ext_package:
├── typed_ast
│ ├── _ast27.cpython-36m-x86_64-linux-gnu.so
│ ├── ast27.py
│ ├── _ast3.cpython-36m-x86_64-linux-gnu.so
│ ├── ast3.py
│ ├── conversions.py
│ ├── __init__.py
│ └── tests
│ └── test_basics.py
└── typed_ast-1.3.2.dev0.dist-info
├── LICENSE
├── METADATA
├── RECORD
├── top_level.txt
└── WHEEL
So what happens is that python_ast without ext_package installs two top-level modules that don't match the package name, which it shouldn't.
This doesn't happen with pyo3-pack, because the shared libraries module name is equal to the distribution name. What we could do however is to put the shared libraries into a folder of the same module name and reexport everything through __init__.py
, so we get more consistency with other packages and the pyo3-pack's cffi wheels.
from maturin.
So what happens is that python_ast without ext_package installs two top-level modules that don't match the package name, which it shouldn't.
Sorry I'm not sure I understand what you are saying. Are you saying it shouldn't install the extension modules into the global namespace? I agree, but that is unfortunately the default (and I think there is a reason for this? Otherwise where should they go if there are multiple packages...).
What we could do however is to put the shared libraries into a folder of the same module name and reexport everything through
__init__.py
, so we get more consistency with other packages and the pyo3-pack's cffi wheels.
Hm, I'm not sure this allows me to accomplish what I want, which is native extensions alongside Python code in a single package.
from maturin.
Sorry I'm not sure I understand what you are saying. Are you saying it shouldn't install the extension modules into the global namespace? I agree, but that is unfortunately the default (and I think there is a reason for this? Otherwise where should they go if there are multiple packages...).
What I meant is that a package foo
should only be installing a module called foo
in the top-level namespace not also a module called bar
, i.e. after pip install foo
I shouldn't be able to import bar
. This is enforced in other languages, but unfortunately changing would break backwards compatibility with many wheels.
Hm, I'm not sure this allows me to accomplish what I want, which is native extensions alongside Python code in a single package.
Oh, that's totally different story and than wheel layout switches like ext_package
. Unfortunately mixing python and rust in a single package is currently not supported. I've written #88 with a proposal how that could work. In the meantime setuptools-rust can do that.
from maturin.
What I meant is that a package
foo
should only be installing a module calledfoo
in the top-level namespace not also a module calledbar
, i.e. afterpip install foo
I shouldn't be able toimport bar
. This is enforced in other languages, but unfortunately changing would break backwards compatibility with many wheels.
Ah ok, this is what I thought you mean, but I was unsure.
Oh, that's totally different story and than wheel layout switches like
ext_package
. Unfortunately mixing python and rust in a single package is currently not supported. I've written #88 with a proposal how that could work. In the meantime setuptools-rust can do that.
Yeah, #88 seems like a plausible solution to this, I just want to make sure that with your example, if the lib name is say "test" then one would import my_proj.test
, and not be able to import test
? If so we can close this in favor of #88.
from maturin.
@konstin I think this issue should remain open, as #88 seems to have been differed/abandoned. I would still like to be able to namespace the final binary only modifying a Cargo.toml
. The current solution seems to be to use setuptools-rust, which I'd like to avoid if possible.
from maturin.
I've implemented #88, which will be part of the next release, so there shouldn't be any need for namespacing anymore.
from maturin.
Ah, apologies, I missed the linked PR, thanks for implementing that!
from maturin.
Related Issues (20)
- Trying to publish sdist only HOT 3
- Fails with "unsupported Python interpreter" HOT 8
- Improve self including check for sdist
- maturin fails if sitecustomize / usercustomize print to stdout HOT 3
- `maturin develop` requires pip to be available HOT 2
- Hash table capacity overflow on x86_64 FreeBSD HOT 10
- Add dynamic = ["version"] to pyproject.toml
- Add support for jenkins as CI provider HOT 5
- macOS: incorrect wheel names HOT 2
- Generated source distribution does not handle aliased dependencies correctly HOT 5
- Cannot find the Python interpreter HOT 2
- Allow offline mode via environment variable HOT 4
- `build` command ignores `build-system.requires` specifier HOT 12
- maturin 1.3.0 panics on `develop` with 'called `Option::unwrap()` on a `None` value' HOT 2
- sdist fails to build if crate is in a subdirectory of a workspace HOT 1
- `MACOSX_DEPLOYMENT_TARGET` causing spurious rebuilds due to `objc-sys` HOT 1
- 1.3.0 release build failed to run against python 3.12 HOT 2
- maturin fails if `sys.stdout` is an `io.StringIO` object HOT 5
- does `maturin build --target x86_64-pc-windows-msvc` support custom CA ? HOT 4
- maturin 1.3 produces invalid source distributions for workspace packages HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from maturin.