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

Submit to PyPI? #148

Closed
sunweilun opened this issue Oct 20, 2017 · 9 comments
Closed

Submit to PyPI? #148

sunweilun opened this issue Oct 20, 2017 · 9 comments

Comments

@sunweilun
Copy link

Dear authors,

Is there any plans to submit tinyobjloader to the the Python Package Index?
It would be awesome if we can simply install it using 'pip'.

@syoyo
Copy link
Collaborator

syoyo commented Oct 20, 2017

I have no idea how to register python binding of tinyobjloader to PIP.

Your contribution is always welcome!

@Ododo
Copy link

Ododo commented Nov 17, 2017

Could be done but i really don't know if it worth it since the module is not so clean and all that plus i don't know what is PIP's policy about that. However if you are reading this post and you also think that it would be a good thing to have this module on PyPI, thumbs up the thread and i will find the time to do it.

@patrikhuber
Copy link

It would probably be quite easy to do using pybind11. It would probably be a bit of a hassle to bind your custom data types but if you used Eigen for that (e.g. Eigen::Vector3f for the vertex coordinates, etc.), then those convert "natively" (integrated into pybind11) to and from Python.

A simple objreader would certainly be very welcome in pip - last time I tried a few, the existing ones were not very feature-complete and pyassimp is quite a hassle to install.

@syoyo
Copy link
Collaborator

syoyo commented Mar 14, 2019

It would probably be quite easy to do using pybind11.

Do you have any good tutorial on register pybind11 + C++ project to PyPI?

@patrikhuber Is this close to what you are thinking about?

https://stackoverflow.com/questions/42656388/how-to-put-a-swig-pybind11-c-project-on-pypi

@patrikhuber
Copy link

"register" is a bit the wrong word I'd say. It works like this:

  • You can copy setup.py from pybind11's cmake example. Just adjust the very bottom part (put your library name, version etc.).
  • Now you can run python setup.py sdist (creates a source distribution) and python setup.py bdist_wheel (creates a binary .whl).
  • Open an account on https://pypi.org/
  • You can upload the previously created files with twine upload dist/<filename> -u <user> -p <password>.

You can also locally run pip install ./tinyobjloader_repo_dir to test the whole process locally.

But of course you first need to also write the actual bindings. As mentioned in my previous post, if you were willing to use Eigen for your vector types, or std::array/std::vector, it would be easy, it's basically a one-liner to bind each function and class. If you want to keep your custom vector types, you need type-casters for those, which is also not too hard but takes a bit of an effort.

You could have a look at this file from my library how I bind my custom Mesh class, and its members (e.g. the vertices data) are bound "automagically" because they consist of std/Eigen types.

@syoyo
Copy link
Collaborator

syoyo commented Mar 14, 2019

@patrikhuber Thank you.

I've glimpsed pybind11's setup.py. It just copies header files.

What I meant is building tinyobj parser as module(.so) and provide thin python wrapper API on top of it, so eos' setup.py is much worth to see for me.

For example, an user can load .obj and access its data like a following way

$ pip install tinyobjloader

$ python
import tinyobjloader
attrib, shapes, ... = tinyobjloader.LoadObj(filename, ...)

print(attrib.vertives[0], attrib.vertives[1], attrib.vertices[2])
...
...

I don't want depending on third party library like Eigen, so I'd like to just wrap tinyobjloader library with pybind11.

FYI, there is already a python binding of tinyobjloader using python.h here:

https://github.com/syoyo/tinyobjloader/tree/master/python

I will investigate how things goes easy by using pybind11

@patrikhuber
Copy link

I see! So if you've already got a setup.py, then I think you can just follow the steps I outlined above to build bdist_wheel and sdist and upload to PyPI.

The "only" (actually quite big) thing that pybind11 would then give you is that instead of all this hand-written, version-specific, hard-to-maintain C bindings code, it abstracts all of that away and you can write the bindings in a few simple lines of modern C++.

@syoyo
Copy link
Collaborator

syoyo commented Mar 24, 2019

I found I need to implement object-oriented API in C++ layer for pybind11, so implemented some classes suitable for pybind11 in pypi branch.

https://github.com/syoyo/tinyobjloader/tree/pypi/python

@patrikhuber Do you think this approach of API binding is good? If so, I'll implement remaining API bindings(and also implement some C++ classes).

Now you can call tinyobj method from python like this

import sys
import tinyobjloader

filename = "../models/cornell_box.obj";

config = tinyobjloader.ObjLoaderConfig()

loader = tinyobjloader.ObjLoader()

ret = loader.Load(filename, config)

if ret == False:
    print("Failed to load : ", filename)
    sys.exit(-1)

attrib = loader.GetAttrib()
print("attrib.vertices = ", len(attrib.vertices))
for v in attrib.vertices:
    print(v)

@syoyo
Copy link
Collaborator

syoyo commented May 17, 2019

https://pypi.org/project/tinyobjloader/

Uploaded to PyPi. Not perfect but most features should work well.

@syoyo syoyo closed this as completed May 17, 2019
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

4 participants