Coords包
starbug.coords的Python项目详细描述
python boost包装器
starbug.com coordinate Python wrappers
此模块包含用于为 使用升压在libCoords中的C++类。这个 图书馆被认为是先建的。coords.cpp包含 用于生成包装器的boost宏。setup.py生成 他们。
与manual版本有些不同, 就像没有coords.error异常但是使用runtimeerror 相反静态单元向量也从coords.ux移走了 到coords.cartesian.ux。对uy、uz和uo也一样。
建造
在命令行上使用make完成构建。有目标 用于清洁和测试。有关详细信息,请参见makefile。
此生成文件不会生成libCoords必须在这之前完成。
setup.py希望在libcoords和boost中找到libcoords.dylib 在/usr/本地。有关详细信息,请参见setup.py
生成工具
Boost
必须先安装Boost Python库,然后才能执行此生成 工作
在带有brew的OS X上
我发现在OSX上安装和维护Boost的最简单方法是 使用homebrew打开增压Python瓶。这个 python包装纸不在“常规”增压瓶中。
$ brew install boost-python --with-python3
在带有Yum的Centos上
sudo yum install boost-devel
在带有apt get的ubuntu上
sudo apt-get install libboost-all-dev
源代码
sudo yum install boost-devel
sudo apt-get install libboost-all-dev
源代码
从 boost source,在/usr/local中解压tar ball
cd /usr/local/boost_1_56_0
./bootstrap.sh
./b2
sudo ./b2 install
boost文件现在位于/usr/local/include/boost和 /usr/local/lib/libboost\u*python/boost/setup.py将boost根设置为 指向那里在OS X上,brew医生会注意到并抱怨这一点
setenv.sh的运行时环境
在本地主机上,相对于此目录,运行时环境 希望建立libcoords。
在OSX上,这需要在dyld_library_路径上。 在Linux上,这需要在ld_library_路径上。
Python身上必须有助推器
setenv.sh将使用uname检测平台并设置适当的 库路径和使用coords_origin环境变量查找 好吧如果未设置坐标原点,则假定坐标原点是相对的 到这个目录。
交互式会议
您可以使用pylaunch.sh设置交互式会话
这里我用地球半径的球坐标 纬度(需要转换为 正Z轴)和经度两个位置来计算 他们之间的距离。
$ ./pylaunch.sh
# COORDS_ROOT not set. Using ../..
# coords.so: ../../python/Boost/build/lib.macosx-10.9-intel-2.7/coords.so
# DYLD_LIBRARY_PATH :../../libCoords
# PYTHONPATH :../../python/Boost/build/lib.macosx-10.9-intel-2.7
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import coords
>>> keplers = coords.spherical(6371, coords.angle(90) - coords.angle(37, 27, 13), coords.angle(-122, 10, 55))
>>> booksinc = coords.spherical(6371, coords.angle(90) - coords.angle(37, 23, 32.4852), coords.angle(-122, 4, 46.2252))
>>> print keplers - booksinc
<spherical><r>11.3235</r><theta>61.4649</theta><phi>123.282</phi></spherical>
使用pylaunch.sh测试组件
使用pylaunch.sh调用setenv.sh。 unittest脚本,例如test_cartesian.py,以及通常的命令 行选项,如-v
$ ./pylaunch.sh test_angle.py -v
# COORDS_ROOT not set. Using ../..
# coords.so: ../../Python/Boost/build/lib.macosx-10.9-intel-2.7/coords.so
# DYLD_LIBRARY_PATH :../../libCoords
# PYTHONPATH :../../Python/Boost/build/lib.macosx-10.9-intel-2.7
test_accessors_1 (__main__.TestAngle)
Test value accessors 1 ... ok
test_accessors_1b (__main__.TestAngle)
Test value accessor exception ... skipped 'TODO Boost.Python.ArgumentError'
test_accessors_2 (__main__.TestAngle)
Test radians accessor negative ... ok
test_accessors_2a (__main__.TestAngle)
Test radians accessor exception ... skipped 'TODO Boost.Python.ArgumentError'
test_angle1_eq_angle1 (__main__.TestAngle)
Test richcompare operator==() ... ok
...
Test latitude += latitude ... ok
test_inplace_add_2 (__main__.TestLatitude)
Test latitude += angle ... ok
test_inplace_add_over_limit (__main__.TestLatitude)
Test latitude += latitude ... ok
----------------------------------------------------------------------
Ran 49 tests in 0.003s
OK (skipped=5)
运行单个单元测试
在命令行中,传入unittest测试线束和测试名称, 例如,TestCartesian,测试脚本的test_default_构造函数
$ ./pylaunch.sh test_Cartesian.py -v TestCartesian.test_default_constructor
# COORDS_ROOT not set. Using ../..
# coords.so: ../../Python/Boost/build/lib.macosx-10.9-intel-2.7/coords.so
# DYLD_LIBRARY_PATH :../../libCoords
# PYTHONPATH :../../Python/Boost/build/lib.macosx-10.9-intel-2.7
test_default_constructor (__main__.TestCartesian)
Test default constructor ... ok
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
测试所有部件
$ ./test_coords.sh -v
PyPI区
将Makefile作为dist目标来构建python分发文件
$ pwd
.../Coordinates/Python/Boost
$ make dist
env ARCHFLAGS="-arch x86_64" python setup.py build
/Users/lrm/.pyenv/versions/3.7.0/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'long_description_content_type'
warnings.warn(msg)
待办事项:它抱怨长描述内容类型,但没有它就不能正确呈现。
把它们清理干净
$ make clean
rm -f -r build dist coords.egg-info
派皮
我用packaging python projects instructions 将构建推送到pypi发行版。
您需要增加setup.py中的版本号来推送新包
使用捆绳上载分发内容
测试PyPI
$ twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Enter your username: lrmcfarland
Enter your password:
Uploading distributions to https://pypi.org/
Uploading coords-1.0.1-cp37-cp37m-macosx_10_13_x86_64.whl
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 129k/129k [00:02<00:00, 58.4kB/s]
Uploading coords-1.0.1.tar.gz
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 13.8k/13.8k [00:01<00:00, 7.83kB/s]
安装测试分发版
$ pip install -i https://test.pypi.org/simple/ starbug.coords
Looking in indexes: https://test.pypi.org/simple/
Collecting coords
Downloading https://test-files.pythonhosted.org/packages/e3/6f/0476d2792045eb0185e039e52b29991fc32bb9c4ceabc178053d11c276e0/coords-1.0-cp37-cp37m-macosx_10_13_x86_64.whl (123kB)
100% |████████████████████████████████| 133kB 1.4MB/s
Installing collected packages: coords
Successfully installed coords-1.0
去派皮
$ twine upload dist/*
安装测试分发版
$ pip install -i https://pypi.org/project/ starbug.coords
使用
(test-coords) $ python
Python 3.7.0 (default, Jul 1 2018, 12:43:10)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import starbug.coords as coords
>>> keplers = coords.spherical(6371, coords.angle(90) - coords.angle(37, 27, 13), coords.angle(-122, 10, 55))
>>> booksinc = coords.spherical(6371, coords.angle(90) - coords.angle(37, 23, 32.4852), coords.angle(-122, 4, 46.2252))
>>> str(keplers - booksinc)
'<spherical><r>11.3235</r><theta>61.4649</theta><phi>123.282</phi></spherical>'