Giter VIP home page Giter VIP logo

mini-extension's People

Contributors

abravalheri avatar firefoxmetzger avatar gpongelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mini-extension's Issues

some features and fixes

Hi @FirefoxMetzger , thanks for this example repo, I'm approaching building with poetry and it's very useful!

I'm focusing only on shared_library example, but probably those things I'm reporting can be found also on other examples.

Just some thing to improve:

  1. on README.md example, due to the ctype function definition, the correct call is print(hello_world().decode()) because it returns c_char_p
  2. to have hello_world.py a little more os-independent, the following implementation run in windows and in linux
import platform
import os
import re

from ctypes import cdll, c_char_p
from pathlib import Path

# load the library using ctypes
_extension = ''
if platform.system() == ' Windows':
    _extension = 'dll'
if platform.system() == 'Linux':
    _extension = 'so'

_base_path = Path(__file__).parent.absolute().joinpath('lib')
# linux do put 'lib' as name prefix and can put the version after the extension (e.g. libhello_library.so.0.1.0 )
res = [f for f in os.listdir(_base_path) if re.search(rf'[a-z]*hello_library[a_z]*.{_extension}[.0-9]*', f)]

# just one library should be into the folder, otherwise exception is raised
lib_shared_hello = cdll.LoadLibrary(str(_base_path.joinpath(res[0])))

# expose the hello function as hello_world in python
# Note: returns a bytes object, not a python string
hello_world = lib_shared_hello.hello
hello_world.restype = c_char_p

Thank you to have spotted the way to build C-project into poetry-managed project!

C extensions not compiled on `poetry install` if module is a dependency

Hey there @FirefoxMetzger !

Thanks a lot for you example of how to compile c-extensions when working with poetry!

I managed to compile my C-extension locally. By locally I mean while working on the package itself.

Both poetry build and poetry install are compiling the objects to the desired place.

However when I try to use said package as a dependency to another package nothing gets compiled.

I tried with your shared_library_with_ctypes that I listed as one of my dependency in my pyproject..toml:

[tool.poetry.dependencies]
python = "3.10.*"
extension = { git = "[email protected]:FirefoxMetzger/mini-extension.git", subdirectory="shared_library_with_ctypes"}

After doing poetry install I get the error: FileNotFoundError for the extension/lib directory.

Am I missing something ? Any help would really be welcome!

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.