Anki build fails with "protoc_wrapper failed" - python

I'm on an arch linux machine and trying to compile anki from source, despite following the instructions, I seem to get the following error no matter what I do:
ERROR: /home/b3nj4m1n/Documents/Github/anki/pylib/anki/BUILD.bazel:111:9: Action pylib/anki/backend_pb2.py failed: (Exit 1): protoc_wrapper failed: error executing command bazel-out/k8-opt-exec-2B5CBBC6/bin/pylib/tools/protoc_wrapper external/protoc_bin_linux_x86_64/bin/protoc bazel-out/k8-opt-exec-2B5CBBC6/bin/pylib/tools/protoc-gen-mypy ... (remaining 20 arguments skipped)
Use --sandbox_debug to see verbose messages from the sandbox
Traceback (most recent call last):
File "/home/b3nj4m1n/.cache/bazel/_bazel_b3nj4m1n/ee6625df9ac32592700069683600f2ec/sandbox/linux-sandbox/288/execroot/ankidesktop/bazel-out/k8-opt-exec-2B5CBBC6/bin/pylib/tools/protoc_wrapper.runfiles/ankidesktop/pylib/tools/protoc_wrapper.py", line 23, in <module>
subprocess.run(
File "/home/b3nj4m1n/.cache/bazel/_bazel_b3nj4m1n/ee6625df9ac32592700069683600f2ec/external/python/lib/python3.9/subprocess.py", line 528, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['external/protoc_bin_linux_x86_64/bin/protoc', '--plugin=protoc-gen-mypy=bazel-out/k8-opt-exec-2B5CBBC6/bin/pylib/tools/protoc-gen-mypy', '--python_out=bazel-out/k8-fastbuild/bin/pylib', '--mypy_out=bazel-out/k8-fastbuild/bin/pylib', '-Iproto/', '-Iexternal/ankidesktop/proto/', 'proto/anki/backend.proto', 'proto/anki/card_rendering.proto', 'proto/anki/cards.proto', 'proto/anki/collection.proto', 'proto/anki/config.proto', 'proto/anki/deckconfig.proto', 'proto/anki/decks.proto', 'proto/anki/generic.proto', 'proto/anki/i18n.proto', 'proto/anki/import_export.proto', 'proto/anki/links.proto', 'proto/anki/media.proto', 'proto/anki/notes.proto', 'proto/anki/notetypes.proto', 'proto/anki/scheduler.proto', 'proto/anki/search.proto', 'proto/anki/stats.proto', 'proto/anki/sync.proto', 'proto/anki/tags.proto']' returned non-zero exit status 1.
Target //qt:runanki failed to build
Use --verbose_failures to see the command lines of failed build steps.
ERROR: /home/b3nj4m1n/Documents/Github/anki/qt/BUILD.bazel:123:10 Middleman _middlemen/qt_Srunanki-runfiles failed: (Exit 1): protoc_wrapper failed: error executing command bazel-out/k8-opt-exec-2B5CBBC6/bin/pylib/tools/protoc_wrapper external/protoc_bin_linux_x86_64/bin/protoc bazel-out/k8-opt-exec-2B5CBBC6/bin/pylib/tools/protoc-gen-mypy ... (remaining 20 arguments skipped)
Just for testing purposes, I wrote a dockerfile which tries to build anki in an isolated environment. This works without issues. (Here's the dockerfile)
I verified that I have all the dependencies from the dockerfile installed on my main machine, but I still get the same error.
I also tried clearing the bazel cache without any success.

Please confirm if you have followed these steps
Install Xubuntu (xubuntu-20.04.3-desktop-amd64.iso) into a new VM.
Install VirtualBox Guest Additions and the automatic Xubuntu updates.
Install these packages and bazel according to linux.md.
Kindly refer to this document on how to build Anki from source.Thank you!

Related

VSCode python debugging quits on Mac with isort error

I was working along in Python in Visual Studio code 1.73.1 on my Mac (OS 11.6, Python 3.9), and after successfully starting a debug session more than 30 times, suddenly it wouldn't. I tried several times. Shortly I noticed this message: "the isort server has crashed 3 times in 5 minutes. It will not be restarted." Clicking through, I discovered the existence of the isort extension and began trying solutions:
Turn off the isort extension. Result: the little horizontal progress line in the upper left corner moves for about half a second and then vanishes. No command appears in the terminal. The same result follows the next several steps:
Delete the extension.
Replace it with a competing isort from someone else.
Replace the Python extension with a more trusted version as described here:
https://learn.microsoft.com/en-us/answers/questions/724858/vscode-debugger-not-working-for-python.html
Uninstall and re-download Visual Studio code.
At last I really went all the way:
Trash the application and empty the trash.
Delete all relevant files as listed here [https://stackoverflow.com/questions/42603103/how-to-completely-uninstall-vs-code-on-mac] :
rm -fr ~/Library/Preferences/com.microsoft.VSCode.helper.plist
rm -fr ~/Library/Preferences/com.microsoft.VSCode.plist
rm -fr ~/Library/Caches/com.microsoft.VSCode
rm -fr ~/Library/Caches/com.microsoft.VSCode.ShipIt/
rm -fr ~/Library/Application\ Support/Code/
rm -fr ~/Library/Saved\ Application\ State/com.microsoft.VSCode.savedState/
rm -fr ~/.vscode/
Reinstall Visual Studio code. This got me back to the place where, while failing to start a debug session, it said "the isort server has crashed 3 times in 5 minutes. It will not be restarted." (How do you clear that flag so that it will try again, anyway?)
It would seem that VSCode debugging has been wrecked by an automatic update to something else that is not actually part of VSCode. Has anyone seen this? Is this a known problem that could be fixed by installing a different version of something?
Logs that may be related to the isort problem:
tail of 1-Python.log:
/usr/lib/python2.7 ~/.vscode/extensions/ms-python.python-2022.19.13251009/pythonFiles/get_output_via_markers.py ~/.vscode/extensions/ms-python.python-2022.19.13251009/pythonFiles/interpreterInfo.py
[ERROR 2022-11-2 10:16:36.608]: [Error: Command failed: /usr/lib/python2.7 /Users/ken/.vscode/extensions/ms-python.python-2022.19.13251009/pythonFiles/get_output_via_markers.py /Users/ken/.vscode/extensions/ms-python.python-2022.19.13251009/pythonFiles/interpreterInfo.py
/bin/sh: /usr/lib/python2.7: is a directory
at ChildProcess.exithandler (node:child_process:408:12)
at ChildProcess.emit (node:events:526:28)
at maybeClose (node:internal/child_process:1092:16)
at ChildProcess._handle.onexit (node:internal/child_process:302:5)] {
killed: false,
code: 126,
signal: null,
cmd: '/usr/lib/python2.7 /Users/ken/.vscode/extensions/ms-python.python-2022.19.13251009/pythonFiles/get_output_via_markers.py /Users/ken/.vscode/extensions/ms-python.python-2022.19.13251009/pythonFiles/interpreterInfo.py'
}
Starting Pylance language server.
tail of 4-isort.log (this block of text repeated several times):
Traceback (most recent call last):
File "/Users/ken/.vscode/extensions/ms-python.isort-2022.8.0/bundled/tool/server.py", line 744, in
LSP_SERVER.start_io()
File "/Users/ken/.vscode/extensions/ms-python.isort-2022.8.0/bundled/libs/pygls/server.py", line 226, in start_io
self.loop.run_until_complete(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/Users/ken/.vscode/extensions/ms-python.isort-2022.8.0/bundled/libs/pygls/server.py", line 57, in aio_readline
header = await loop.run_in_executor(executor, rfile.readline)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 814, in run_in_executor
executor.submit(func, *args), loop=self)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/thread.py", line 170, in submit
self._adjust_thread_count()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/concurrent/futures/thread.py", line 193, in _adjust_thread_count
t.start()
TypeError: start() missing 1 required positional argument: 'sessionID'
Error in atexit._run_exitfuncs:
TypeError: stop_all_processes() missing 1 required positional argument: 'self'
[Error - 10:10:30 AM] Connection to server got closed. Server will not be restarted.

build v8 error when using command " python tools\dev\v8gen.py x64.release "

i try build v8 in the following steps:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
set PATH=C:\v8\depot_tools;%PATH%
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
set GYP_MSVS_VERSION=2017
fetch v8
6 .cd v8
python tools\dev\v8gen.py x64.release
ninja -C out.gn\x64.release
my computer enviroment:
Visual Studio 2017,community
Windows SDK (15063)
python 2.7
error:
E:\work_space\Technology_related\V88888\v8>python tools\dev\v8gen.py x64.release -vv
################################################################################
C:\Python27\python.exe -u tools\mb\mb.py gen -f infra\mb\mb_config.pyl -m developer_default -b x64.release out.gn/x64.release
Writing """\
dcheck_always_on = false
is_debug = false
target_cpu = "x64"
""" to E:\work_space\Technology_related\V88888\v8\out.gn\x64.release\args.gn.
E:\work_space\Technology_related\V88888\v8\buildtools\win\gn.exe gen out.gn/x64.release --check
-> returned 1
ERROR at //build/config/win/visual_studio_version.gni:27:7: Script returned non-zero exit code.
exec_script("../../vs_toolchain.py", [ "get_toolchain_dir" ], "scope")
^----------
Current dir: E:/work_space/Technology_related/V88888/v8/out.gn/x64.release/
Command: C:/Users/moush/AppData/Local/Microsoft/WindowsApps/python3.exe E:/work_space/Technology_related/V88888/v8/build/vs_toolchain.py get_toolchain_dir
Returned 9009.
See //build/config/win/BUILD.gn:11:1: whence it was imported.
import("//build/config/win/visual_studio_version.gni")
^----------------------------------------------------
See //build/config/BUILDCONFIG.gn:355:5: which caused the file to be included.
"//build/config/win:lean_and_mean",
^---------------------------------
GN gen failed: 1
Traceback (most recent call last):
File "tools\dev\v8gen.py", line 309, in <module>
sys.exit(gen.main())
File "tools\dev\v8gen.py", line 303, in main
return self._options.func()
File "tools\dev\v8gen.py", line 169, in cmd_gen
gn_outdir,
File "tools\dev\v8gen.py", line 213, in _call_cmd
stderr=subprocess.STDOUT,
File "C:\Python27\lib\subprocess.py", line 573, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['C:\\Python27\\python.exe', '-u', 'tools\\mb\\mb.py', 'gen', '-f', 'infra\\mb\\mb_config.pyl', '-m', 'developer_default', '-b', 'x64.release', 'out.gn/x64.release']' returned non-zero exit status 1
I don't know how to fix this bug,Can someone help me?thanks
From the verbose output, you can see that the command C:/Users/moush/AppData/Local/Microsoft/WindowsApps/python3.exe E:/work_space/Technology_related/V88888/v8/build/vs_toolchain.py get_toolchain_dir failed. You can try running that on its own to see if it reports any additional details, which might help you figure out what's wrong and how to fix it.
From the fact that "it failed" alone, I would guess that it somehow didn't detect your Visual Studio and/or Windows SDK installation. FWIW, the official instructions how to install VS are here (linked from the V8 docs). It looks like your SDK might simply be too old.
You can also try the convenience workflow based on tools/dev/gm.py to see if that avoids this issue, but I'd guess that it will probably run into the same problem.

How to run paramiko demo_server.py?

https://raw.githubusercontent.com/paramiko/paramiko/master/demos/demo_server.py
I see the above demo_server of paramiko. But I don't see the instructions on how to run it. I run the following ./demo_server.py command. But once I run ssh robey#127.0.0.1 -p 2200, the server fails. Could anybody let me know the complete steps on how to run this example? Thanks.
$ python3 ./demo_server.py
Read key: 60733844cb5186657fdedaa22b5a57d5
Listening for connection ...
Got a connection!
*** Caught exception: <class 'ImportError'>: Unable to import a GSS-API / SSPI module!
Traceback (most recent call last):
File "./demo_server.py", line 140, in <module>
t = paramiko.Transport(client, gss_kex=DoGSSAPIKeyExchange)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/paramiko/transport.py", line 445, in __init__
self.kexgss_ctxt = GSSAuth("gssapi-keyex", gss_deleg_creds)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/paramiko/ssh_gss.py", line 107, in GSSAuth
raise ImportError("Unable to import a GSS-API / SSPI module!")
ImportError: Unable to import a GSS-API / SSPI module!
$ ssh robey#127.0.0.1 -p 2200
kex_exchange_identification: read: Connection reset by peer
I managed to get it to work, make sure to go through these steps (Thank you Sandeep for the pip insight), chances are you may be missing the Kerberos dependencies:
You may need to perform pip install gssapi in the CLI if that has not already been done (I'm using the Windows Command Prompt, Linux/WSL might need pip3 instead depending on your version of python)
From there you will need to import the gssapi library into the code at the top with the other imported libraries, so just call
import gssapi in demo_server.py
After running demo_server.py again, the CLI should eventually say something like it is missing files located in Program Files\ MIT\ Kerberos\ bin, as Kerberos is a dependency for gssapi, you can install it from here:
https://web.mit.edu/KERBEROS/dist/
Make sure you do custom install if you're not sure where it will be downloaded, so that you can set up the file location where the CLI says is missing in step 3 (Should automatically say Program Files\ MIT). I unchecked the boxes for auto-start and tickets, but not sure as to what your preferences may be. After all that, a computer restart is required.

Error Compiling Tensorflow From Source - No module named 'keras_applications'

I am attempting to build tensorflow from source with MKL optimizations on an Intel CPU setup. I have followed the official instructions here up until the command bazel build --config=mkl --config=opt //tensorflow/tools/pip_package:build_pip_package.
Unfortunately, the compilation runs for some period of time and then fails. I'd appreciate any help with this matter.
Updated Output log (using bazel --verbose_failures):
ERROR: /home/jok/build/tensorflow/tensorflow/BUILD:584:1: Executing genrule //tensorflow:tensorflow_python_api_gen failed (Exit 1): bash failed: error executing command
(cd /home/jok/.cache/bazel/_bazel_jok120/737f8d6dbadde71050b1e0783c31ea62/execroot/org_tensorflow && \
exec env - \
LD_LIBRARY_PATH=LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64/:/usr/local/cuda-9.0/extras/CUPTI/lib64 \
PATH=/home/jok/.conda/envs/tf_mkl/bin:/home/jok/bin:/opt/anaconda3/bin:/usr/local/bin:/bin:/usr/bin:/snap/bin:/home/jok/bin \
/bin/bash -c 'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/host/bin/tensorflow/create_tensorflow.python_api --root_init_template=tensorflow/api_template.__init__.py --apidir=bazel-out/host/genfiles/tensorflow --apiname=tensorflow --apiversion=1 --package=tensorflow.python --output_package=tensorflow bazel-out/host/genfiles/tensorflow/__init__.py bazel-out/host/genfiles/tensorflow/app/__init__.py bazel-out/host/genfiles/tensorflow/bitwise/__init__.py bazel-out/host/genfiles/tensorflow/compat/__init__.py bazel-out/host/genfiles/tensorflow/data/__init__.py bazel-out/host/genfiles/tensorflow/debugging/__init__.py bazel-out/host/genfiles/tensorflow/distributions/__init__.py bazel-out/host/genfiles/tensorflow/dtypes/__init__.py bazel-out/host/genfiles/tensorflow/errors/__init__.py bazel-out/host/genfiles/tensorflow/feature_column/__init__.py bazel-out/host/genfiles/tensorflow/gfile/__init__.py bazel-out/host/genfiles/tensorflow/graph_util/__init__.py bazel-out/host/genfiles/tensorflow/image/__init__.py bazel-out/host/genfiles/tensorflow/io/__init__.py bazel-out/host/genfiles/tensorflow/initializers/__init__.py bazel-out/host/genfiles/tensorflow/keras/__init__.py bazel-out/host/genfiles/tensorflow/keras/activations/__init__.py bazel-out/host/genfiles/tensorflow/keras/applications/__init__.py bazel-out/host/genfiles/tensorflow/keras/applications/densenet/__init__.py bazel-out/host/genfiles/tensorflow/keras/applications/inception_resnet_v2/__init__.py bazel-out/host/genfiles/tensorflow/keras/applications/inception_v3/__init__.py bazel-out/host/genfiles/tensorflow/keras/applications/mobilenet/__init__.py bazel-out/host/genfiles/tensorflow/keras/applications/mobilenet_v2/__init__.py bazel-out/host/genfiles/tensorflow/keras/applications/nasnet/__init__.py bazel-out/host/genfiles/tensorflow/keras/applications/resnet50/__init__.py bazel-out/host/genfiles/tensorflow/keras/applications/vgg16/__init__.py bazel-out/host/genfiles/tensorflow/keras/applications/vgg19/__init__.py bazel-out/host/genfiles/tensorflow/keras/applications/xception/__init__.py bazel-out/host/genfiles/tensorflow/keras/backend/__init__.py bazel-out/host/genfiles/tensorflow/keras/callbacks/__init__.py bazel-out/host/genfiles/tensorflow/keras/constraints/__init__.py bazel-out/host/genfiles/tensorflow/keras/datasets/__init__.py bazel-out/host/genfiles/tensorflow/keras/datasets/boston_housing/__init__.py bazel-out/host/genfiles/tensorflow/keras/datasets/cifar10/__init__.py bazel-out/host/genfiles/tensorflow/keras/datasets/cifar100/__init__.py bazel-out/host/genfiles/tensorflow/keras/datasets/fashion_mnist/__init__.py bazel-out/host/genfiles/tensorflow/keras/datasets/imdb/__init__.py bazel-out/host/genfiles/tensorflow/keras/datasets/mnist/__init__.py bazel-out/host/genfiles/tensorflow/keras/datasets/reuters/__init__.py bazel-out/host/genfiles/tensorflow/keras/estimator/__init__.py bazel-out/host/genfiles/tensorflow/keras/initializers/__init__.py bazel-out/host/genfiles/tensorflow/keras/layers/__init__.py bazel-out/host/genfiles/tensorflow/keras/losses/__init__.py bazel-out/host/genfiles/tensorflow/keras/metrics/__init__.py bazel-out/host/genfiles/tensorflow/keras/models/__init__.py bazel-out/host/genfiles/tensorflow/keras/optimizers/__init__.py bazel-out/host/genfiles/tensorflow/keras/preprocessing/__init__.py bazel-out/host/genfiles/tensorflow/keras/preprocessing/image/__init__.py bazel-out/host/genfiles/tensorflow/keras/preprocessing/sequence/__init__.py bazel-out/host/genfiles/tensorflow/keras/preprocessing/text/__init__.py bazel-out/host/genfiles/tensorflow/keras/regularizers/__init__.py bazel-out/host/genfiles/tensorflow/keras/utils/__init__.py bazel-out/host/genfiles/tensorflow/keras/wrappers/__init__.py bazel-out/host/genfiles/tensorflow/keras/wrappers/scikit_learn/__init__.py bazel-out/host/genfiles/tensorflow/layers/__init__.py bazel-out/host/genfiles/tensorflow/linalg/__init__.py bazel-out/host/genfiles/tensorflow/logging/__init__.py bazel-out/host/genfiles/tensorflow/losses/__init__.py bazel-out/host/genfiles/tensorflow/manip/__init__.py bazel-out/host/genfiles/tensorflow/math/__init__.py bazel-out/host/genfiles/tensorflow/metrics/__init__.py bazel-out/host/genfiles/tensorflow/nn/__init__.py bazel-out/host/genfiles/tensorflow/nn/rnn_cell/__init__.py bazel-out/host/genfiles/tensorflow/profiler/__init__.py bazel-out/host/genfiles/tensorflow/python_io/__init__.py bazel-out/host/genfiles/tensorflow/quantization/__init__.py bazel-out/host/genfiles/tensorflow/resource_loader/__init__.py bazel-out/host/genfiles/tensorflow/strings/__init__.py bazel-out/host/genfiles/tensorflow/saved_model/__init__.py bazel-out/host/genfiles/tensorflow/saved_model/builder/__init__.py bazel-out/host/genfiles/tensorflow/saved_model/constants/__init__.py bazel-out/host/genfiles/tensorflow/saved_model/loader/__init__.py bazel-out/host/genfiles/tensorflow/saved_model/main_op/__init__.py bazel-out/host/genfiles/tensorflow/saved_model/signature_constants/__init__.py bazel-out/host/genfiles/tensorflow/saved_model/signature_def_utils/__init__.py bazel-out/host/genfiles/tensorflow/saved_model/tag_constants/__init__.py bazel-out/host/genfiles/tensorflow/saved_model/utils/__init__.py bazel-out/host/genfiles/tensorflow/sets/__init__.py bazel-out/host/genfiles/tensorflow/sparse/__init__.py bazel-out/host/genfiles/tensorflow/spectral/__init__.py bazel-out/host/genfiles/tensorflow/summary/__init__.py bazel-out/host/genfiles/tensorflow/sysconfig/__init__.py bazel-out/host/genfiles/tensorflow/test/__init__.py bazel-out/host/genfiles/tensorflow/train/__init__.py bazel-out/host/genfiles/tensorflow/train/queue_runner/__init__.py bazel-out/host/genfiles/tensorflow/user_ops/__init__.py')
Traceback (most recent call last):
File "/home/jok/.cache/bazel/_bazel_jok120/737f8d6dbadde71050b1e0783c31ea62/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api.runfiles/org_tensorflow/tensorflow/python/tools/api/generator/create_python_api.py", line 27, in <module>
from tensorflow.python.tools.api.generator import doc_srcs
File "/home/jok/.cache/bazel/_bazel_jok120/737f8d6dbadde71050b1e0783c31ea62/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api.runfiles/org_tensorflow/tensorflow/python/__init__.py", line 81, in <module>
from tensorflow.python import keras
File "/home/jok/.cache/bazel/_bazel_jok120/737f8d6dbadde71050b1e0783c31ea62/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api.runfiles/org_tensorflow/tensorflow/python/keras/__init__.py", line 25, in <module>
from tensorflow.python.keras import applications
File "/home/jok/.cache/bazel/_bazel_jok120/737f8d6dbadde71050b1e0783c31ea62/execroot/org_tensorflow/bazel-out/host/bin/tensorflow/create_tensorflow.python_api.runfiles/org_tensorflow/tensorflow/python/keras/applications/__init__.py", line 21, in <module>
import keras_applications
ModuleNotFoundError: No module named 'keras_applications'
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 695.098s, Critical Path: 152.03s
INFO: 7029 processes: 7029 local.
FAILED: Build did NOT complete successfully
This appears to be a problem with Tensorflow 1.10 build. I recommend you check out the r1.9 branch as it builds totally fine. Either the dependency list needs to be updated or Tensorflow will fix this. If you are determined to run the r.1.10 api then run the following in terminal:
pip install keras_applications==1.0.4 --no-deps
pip install keras_preprocessing==1.0.2 --no-deps
pip install h5py==2.8.0
If you're just interested in the release version (git tag will show you all available releases), run git checkout v1.10.1 before the ./configure step. Then you can follow the official instructions without installing additional dependencies.
Currently, a master branch build will give me the following error in Keras code that worked previously (this is after calling model.fit_generator() from the stand alone version of Keras):
`steps_per_epoch=None` is only valid for a generator based on the `keras.utils.Sequence` class. Please specify `steps_per_epoch` or use the `keras.utils.Sequence` class.
Builds based on the 1.10.1 release version of TensorFlow don't cause this error.

GitPython post-receive git hook script fails after push

I have a client-side post-receive git hook that runs a Python script. The script uses GitPython to do a diff between HEAD and HEAD~1, figure out the names of files that have been changed, and then compose a tweet that updates followers about the change.
The hook itself is just a shell script that runs python wikitweet.py, where the Python script does the heavy lifting.
When I run the Python script on the remote side after a push, everything works fine. But when I push from the local side, I get the following error:
remote: Traceback (most recent call last):
remote: File "/home/wcm1/bin/wikitweet.py", line 21, in <module>
remote: most_recent_diff = repo.head.commit.diff('HEAD~1')
remote: File "/usr/lib/python2.6/site-packages/git/diff.py", line 111, in diff
remote: proc.wait()
remote: File "/usr/lib/python2.6/site-packages/git/cmd.py", line 309, in wait
remote: raise GitCommandError(self.args, status, self.proc.stderr.read())
remote: git.exc.GitCommandError: 'git diff c43a0b831612eb97f097458816d41aaa0506147d HEAD~1 --abbrev=40 --full-index -M --raw --no-color' returned with exit code 129
remote: stderr: 'usage: git diff [--no-index] <path> <path>
remote: '
After which the push to master and update of working of copy completes just fine. I can tell from the commit hash in that error message that the script is successfully getting the new HEAD commit, so it doesn't seem to be an issue (I don't think) of when the hook is being run.
I'm guessing that I'm either misunderstanding hooks, or doing something wrong in my Python script, but am having difficulty understanding why it runs on the remote side but fails after push. Here are the relevant lines in wikitweet.py that seem to be causing problems:
repo = git.Repo('/path/to/repo')
most_recent_diff = repo.head.commit.diff('HEAD~1')
changed_files = []
for x in most_recent_diff:
if x.a_blob.path not in changed_files:
changed_files.append(x.a_blob.path)
if x.b_blob is not None and x.b_blob.path not in changed_files:
changed_files.append(x.b_blob.path)
[...]
I also have different versions of Python running on remote and local, though I don't see why that would cause a problem.
I was getting a standard error because of an environment variable that git sets when using a post-receive hook. The solution was to add this line to my hook:
unset GIT_DIR
This page offers some helpful tips about hooks and environment variables that helped me figure out the problem.

Categories