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

Maturin build doesn't include the entry_points in setup.py? #623

Closed
WestXu opened this issue Sep 15, 2021 · 12 comments
Closed

Maturin build doesn't include the entry_points in setup.py? #623

WestXu opened this issue Sep 15, 2021 · 12 comments
Labels
wontfix This will not be worked on

Comments

@WestXu
Copy link

WestXu commented Sep 15, 2021

  • Your python version (python -V): Python 3.8.10
  • Your pip version (pip -V): pip 21.2.4 from /home/coder/miniconda/lib/python3.8/site-packages/pip (python 3.8)
  • The version of the bindings you're using, if any (e.g. pyo3, rust-cpython or cffi): pyo3
  • Does cargo build work? Yes.

So here is my project structure:

myproject/__init__.py
myproject/api.py
src/lib.rs
src/main.rs
setup.py
.gitignore
Cargo.toml

And my setup.py:

import setuptools

setuptools.setup(
    name="myproject",
    version="0.0.1",
    author='WestXu',
    author_email='[email protected]',
    packages=setuptools.find_packages(),
    entry_points={
        'console_scripts': [
            'mycli = myproject.api:cli',
        ],
    },
)

When install using maturin develop --release && pip install -e ., everything works fine with my cli. While when install using maturin build --release && pip install target/wheels/myproject-0.1.0-cp38-cp38-linux_x86_64.whl, my cli does not work, and running mycli in terminal gives sh: mycli: command not found.

@WestXu
Copy link
Author

WestXu commented Sep 15, 2021

And the reason why I use setup.py instead of pyproject.toml is that I really need the pip install --editable. Can anyone share some tricks to make maturin and editable installation both work?

BTW, happen to find this while searching for solutions: https://www.python.org/dev/peps/pep-0660/
Will maturin support this?

@WestXu WestXu changed the title Maturin build doesn't include the entry_points? Maturin build doesn't include the entry_points in setup.py? Sep 15, 2021
@messense
Copy link
Member

maturin only works with PEP 517 so it doesn't read setup.py.
Even if we implemented PEP 660, it still would require pypa/pip#8212 to land first.

@WestXu
Copy link
Author

WestXu commented Sep 16, 2021

Ok. Looks like pypa/pip#8212 will be finished soon.

And I've tried using maturin develop to replace pip install -e ., thought this could be a more legit way to achive this, but the entry_points is not working either. So it's by #213 I guess.

Either of them working will get my problem solved.

@WestXu
Copy link
Author

WestXu commented Sep 16, 2021

Also I tried this popular shim, from https://stackoverflow.com/questions/62983756/what-is-pyproject-toml-file-for:

#!/usr/bin/env python

import setuptools

if __name__ == "__main__":
    setuptools.setup()

Then pip install -e . gives:

    ERROR: Command errored out with exit status 1:
     command: /home/lxuwsl/miniconda3/envs/newenv/bin/python3.8 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/mnt/d/git-project/jzgateway/setup.py'"'"'; __file__='"'"'/mnt/d/git-project/jzgateway/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps
         cwd: /mnt/d/git-project/jzgateway/
    Complete output (3 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ModuleNotFoundError: No module named 'setuptools'

@messense
Copy link
Member

Add setuptools to build-system.requires list of pyproject.toml.

@WestXu
Copy link
Author

WestXu commented Sep 16, 2021

Thanks. I can pip install -e . now, but entry_points defined in pyproject.toml still won't work this way. command not found.

@messense
Copy link
Member

maturin will never support reading metadata from setup.py, so I'm closing this issue. Opened #624 to track PEP 660 support.

@messense messense added the wontfix This will not be worked on label Sep 16, 2021
@messense
Copy link
Member

BTW, it would be great if you want to work #213

@WestXu
Copy link
Author

WestXu commented Sep 16, 2021

Wish I could contribute, but after reading the source code for a while, I conclude that maybe it's beyond my capacity.

I guess python packaging stuff is just too complicated for me to make full sense of it.

@messense
Copy link
Member

messense commented Sep 16, 2021

Basically we need to generate a script based on this template https://github.com/pypa/pip/blob/0de0b8dd9f21642dc6d0e00bfa8913f4964b1706/src/pip/_vendor/distlib/scripts.py#L41-L48 and put it in virtualenv's bin directory.

bin directory path can be obtained by calling sysconfig.get_path('scripts')

@messense
Copy link
Member

I've partially implemented #213 in #633 (Windows support is lacking). Please give it a try, you can install the pre-release version by pip install -U --pre maturin.

@WestXu
Copy link
Author

WestXu commented Sep 22, 2021

Works like a charm. Appreciate it.

This is my daily python driver now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants