如何在Mac OS X 10.8上安装hg convert所需的python颠覆绑定? [英] How to install python subversion bindings needed by hg convert on Mac OS X 10.8?
问题描述
我正在寻找一种解决方案,最好是干净且简单的方法,以使hg convert
能够在具有SVN存储库的OS X 10.8上运行.
I am looking for a solution, preferably clean and simple, to enable hg convert
to work on OS X 10.8 with SVN repositories.
当前,如果您尝试转换SVN存储库,则会出现could not load Subversion python bindings
错误.
Currently, if you try to convert a SVN repository you will get a could not load Subversion python bindings
error.
注意:Alex Martelli在另一个答案中建议为OS X安装CollabNet Subversion发行版,但似乎最新的CollabNet版本不能安装在OS X 10.8上(安装程序锁定).
Note: Alex Martelli recommended in another answer to install CollabNet subversion distribution for OS X, still it seems that the latest CollabNet version cannot be installed on OS X 10.8 (the installer locks).
推荐答案
使用自制软件
最简单的方法是从源代码安装subversion
使用 homebrew
和--with-python
标志.
首先,请确保您已安装命令行工具.与小牛
和Xcode 5,即使cc
工具尚未完全安装.如果您没有/usr/include
目录,
然后首先您需要运行
First, make sure you have your command-line tools installed. With Mavericks
and Xcode 5, most commands like cc
just work even though the command-line
tools aren’t fully installed. If you don’t have a /usr/include
directory,
then first you need to run
$ xcode-select --install
一旦安装了命令行工具,请运行:
Once your command-line tools are installed, run:
$ brew install subversion --with-python
$ mkdir -p ~/Library/Python/2.7/lib/python/site-packages
$ echo $(brew --cellar)/subversion/1.8.5/lib/svn-python \
> ~/Library/Python/2.7/lib/python/site-packages/svn.pth
您可以通过运行单元测试来测试绑定:
You can test the bindings by running the unit tests:
$ svn co http://svn.apache.org/repos/asf/subversion/tags/1.8.5/subversion/bindings/swig/python/tests
$ cd tests && python run_all.py
使用Apple的源代码
这适用于Mountain Lion,但需要对Mavericks进行调整,并在 单元测试失败;参见西蒙·赖特(Simon Wright)对这个问题的回答.
Using Apple’s source code
This works for Mountain Lion, but needs tweaks for Mavericks and results in failing unit tests; see Simon Wright’s answer to this question.
是
可以使用Apple版本的Subversion源代码为Python构建Subversion绑定.生成的模块
将完全兼容并链接到所有系统库.然后hg convert
就可以了.
It is
possible to build the subversion bindings for Python using Apple’s version of the subversion source code. The resulting module
will be exactly compatible and link against all the system libraries. And then hg convert
will just work.
操作方法如下:
解压缩并配置它:
cd subversion-52/subversion && ./configure
在subversion/bindings/swig/python
中,请确保添加此Makefile
将制表符前导空格更改为
In subversion/bindings/swig/python
, add this Makefile, being sure
to change leading whitespace to tabs:
SHELL = /bin/bash -eu
CC = gcc -g -O2
CFLAGS = -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK \
-I ../proxy \
-I ../../.. \
-I ../../../include \
-I /usr/include/apr-1 \
-I libsvn_swig_py \
-I /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 \
LDFLAGS = \
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib \
/usr/lib/libsvn_*-1.0.dylib \
/usr/lib/libapr-1.dylib \
.PHONY: build egg test clean install
test: egg
mkdir -p tmp && cd tmp \
&& PYTHONPATH=../egg python -S -m svn.tests.run_all
DESTDIR=$(HOME)/Library/Python/2.7/lib/python/site-packages
install: egg
mkdir -p "${DESTDIR}"
rm -rf "$(DESTDIR)/svn.egg"
cp -R egg "$(DESTDIR)/svn.egg"
echo './svn.egg' > "$(DESTDIR)/svn.pth"
egg: build
rm -rf egg
mkdir egg
cp -R svn egg
cp -R tests egg/svn
touch egg/svn/tests/__init__.py
mkdir egg/libsvn
cp *.py egg/libsvn
cp *.so *.dylib egg/libsvn
# https://blogs.oracle.com/dipol/entry/dynamic_libraries_rpath_and_mac
for F in egg/libsvn/*.so; do \
install_name_tool -change libsvn_swig_py.dylib \
'@loader_path/libsvn_swig_py.dylib' "$$F"; \
done
strip -x egg/libsvn/*.so
touch egg/libsvn/__init__.py
mkdir -p egg/EGG-INFO
echo 'Version: 1.6.8' > egg/EGG-INFO/PKG-INFO
build: libsvn_swig_py.dylib _client.so _core.so _delta.so _diff.so _fs.so _ra.so _repos.so _wc.so
libsvn_swig_py.dylib:
$(CC) $(CFLAGS) -shared -dynamic libsvn_swig_py/swigutil_py.c -o $@ $(LDFLAGS)
_client.so: svn_client.c
_core.so: core.c
_delta.so: svn_delta.c
_diff.so: svn_diff.c
_fs.so: svn_fs.c
_repos.so: svn_repos.c
_wc.so: svn_wc.c
_%.so: svn_%.c libsvn_swig_py.dylib
$(CC) $(CFLAGS) -bundle $^ -o $@ $(LDFLAGS)
_%.so: %.c libsvn_swig_py.dylib
$(CC) $(CFLAGS) -bundle $^ -o $@ $(LDFLAGS)
clean:
rm -rf *.o *.so *.dylib *.dSYM
然后在该目录中运行make
.
如果在最后一步中通过了单元测试,那么您现在可以使用全部功能
用于颠覆的Python绑定!如果您满意,请运行make install
,然后
hg convert
将开始工作.
If the unit tests passed in the last step, you now have fully-functional
Python bindings for subversion! Run make install
if you’re happy, and
hg convert
will start working.
通常情况下,从中重写构建系统更加容易 而不是找出现有的方法.
As is so often the case, it was easier to rewrite the build system from scratch than to figure out the existing one.
Apple和Subversion的所有脚本确实使它复杂化,但是您真正需要做的就是复制.py
文件,使用通用代码构建一个共享库,然后构建每个C语言Python模块.弄清楚要使用的包含文件和库很简单:尝试在不包含任何包含或库的情况下开始构建它,并且当构建失败时,添加对导致构建失败的缺少包含路径或库的引用.棘手的部分是告诉诸如_core.so
的C语言模块在哪里可以找到通用代码的动态库.
All the scripts from Apple and Subversion really complicate it, but all you really need to do is copy the .py
files, build a shared library with the common code, and then build each C-language Python module. Figuring out which include files and libraries to use is straightforward: try to build it starting without any includes or libraries, and when the build fails, add a reference to the missing include path or library that is causing the build failure. The tricky part is telling the C-language modules like _core.so
where to find the dynamic library of common code.
这篇关于如何在Mac OS X 10.8上安装hg convert所需的python颠覆绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!