realpython / realpython/materials

Mac Mojave and Python 3.8 working branch

オープン
#108 コメント 8 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Jupyter Notebook
スター
5.2k
フォーク
5.3k
平均マージ
4日 10時間
マージ済み PR(30日)
10

説明

Hi, I have a branch to push to you with a working version of the python binding module
with Mac Mojave and Python 3.8 using python.org version of python, (not brew)

Cheers Dave.

Notes here;

help on python c binding

dependencies

install python3.8 from python.org

pip3 install pybind11
pip3 install invoke
pip3 install Cython

security block

mac mojave blocks relative pathed libraries, here is the fix

install_name_tool

def install_name_tool(dependent=None, depends=[]):
    '''
    make the lib full path to get around security blocking relative paths
    '''
    for dependson in depends:
        full_path = os.path.abspath(dependson)
        shell_str='install_name_tool -change {0} {1} {2}'.format(dependson, full_path, dependent)
        print('    install_name_tool: {0}'.format(dependson))
        invoke.run(shell_str)

mac G++ missing symbols

mac compile gets upset about missing symbols

ignore missing symbols on a mac

On Mac OS: the build command is almost the same but it also requires passing the -undefined dynamic_lookup flag so as to ignore missing symbols when building the module:

in task.py

def compile_python_module(cpp_name, extension_name):
    invoke.run(
        "g++ -O3 -Wall -Werror -shared -std=c++11 -fPIC "
        "`python3.8-config --includes` "
        "`python3 -m pybind11 --includes` "
        "-undefined dynamic_lookup "
        "-I . "
        "{0} "
        "-o {1}`python3.8-config --extension-suffix` "
        "-L. -lcppmult -Wl,-rpath,.".format(cpp_name, extension_name)
    )

compile and test

here is the output from a good compile and test run

$ invoke all
==================================================
= Building C Library 
* Complete
==================================================
= Testing ctypes Module 
    In cmult : int: 6 float 2.3 returning  13.8
    In Python: int: 6 float 2.3 return val 48.0

    In cmult : int: 6 float 2.3 returning  13.8
    In Python: int: 6 float 2.3 return val 13.8
==================================================
= Building CFFI Module 
    install_name_tool: libcmult.so
* Complete
==================================================
= Testing CFFI Module 
    In cmult : int: 6 float 2.3 returning  13.8
    In Python: int: 6 float 2.3 return val 13.8
==================================================
= Building C++ Library 
    install_name_tool: libcmult.so
    install_name_tool: cffi_example.cpython-38-darwin.so
* Complete
==================================================
= Building PyBind11 Module 
    install_name_tool: libcmult.so
    install_name_tool: cffi_example.cpython-38-darwin.so
    install_name_tool: libcppmult.so
* Complete
==================================================
= Testing PyBind11 Module 
    In cppmul: int: 6 float 2.3 returning  13.8
    In Python: int: 6 float 2.3 return val 13.8
==================================================
= Building Cython Module 
    install_name_tool: libcmult.so
    install_name_tool: cffi_example.cpython-38-darwin.so
    install_name_tool: libcppmult.so
* Complete
==================================================
= Testing Cython Module 
    In cppmul: int: 6 float 2.3 returning  13.8
    In Python: int: 6 float 2.3 return val 13.8

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

task.py と文書化された invoke all ワークフローから始め、続いて C、C++、CFFI、PyBind11、Cython モジュールのビルド方法とテスト方法を確認します。報告された Python 3.8 と Mac Mojave のセットアップを再現します。要求されたブランチまたは文書化された変更が統合され、一覧にあるすべてのモジュールのビルドとテストが成功すれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
cpp, python
領域
build-system, devtools
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
28/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。