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.
Related
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.
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!
I have a git hook, "commit-msg"
and it looks something like:
#!/bin/sh
python .git/hooks/Foo.py
Inside my Foo.py
I have:
import git
# doing some stuff based on git (evaluating latest changes)
when I commit using sourcetree if fails to run the hook ( also it does not commit )
//...
Traceback (most recent call last):
File ".git/hooks/Foo.py", line 2, in <module>
import git
ImportError: No module named git
//...
but if I commit directly from the terminal the hook works as expected.
Any suggestions to fix the commit on source tree?
Try to add this to your git hook file:
export PATH=/usr/local/bin:$PATH
See this SourceTree issue
I am trying to push a Python (3.6.5) app via Flask to Cloud Foundry (cf version 6.36.1+e3799ad7e.2018-04-04). The application takes a POST request (text file), does some text transformation, saves the new file, and returns a confirmation message. It works locally (tested via Postman). However, when attempting to push it to CF, it gives the following error -
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ygzuah5g/logging/
Could you please let me know how I can go about solving this issue? Thanks in advance. The entire files together are ~ 350 MB. I am using a manifest.yml
---
applications:
- name: textsum
memory: 512M
command: python server.py
buildpack: https://github.com/cloudfoundry/buildpack-python.git
PS - Not sure if this is helpful, I do have import queue in one of my files. If I change it to import Queue (Py 2x compatible) and use Py 2.7.15 runtime, the cf push is successful, but it throws runtime errors
ERROR in app: Exception on / [POST]
File "/home/vcap/deps/0/python/lib/python2.7/subprocess.py", line 1047, in _execute_child
ERR raise child_exception
ERR OSError: [Errno 2] No such file or directory
ERR 10.0.65.11 - - [12/Jun/2018 20:56:16] "POST / HTTP/1.1" 500 -
First. Don't do this in your manifest.yml:
buildpack: https://github.com/cloudfoundry/buildpack-python.git
This is telling Cloud Foundry to use the master branch of the buildpack which can change quite frequently and there are no guarantees of it's fitness (i.e. it could even be broken).
Instead, make sure that you are using a release. Releases are tested and the code won't change out from under you.
You can do this by using the platform supplied Python buildpack, simply remove this line or put python_buildpack as the name, or you can point to buildpack: https://github.com/cloudfoundry/buildpack-python.git#v1.6.17 where v1.6.17 is a release from here.
https://github.com/cloudfoundry/python-buildpack/releases
Second, it seems like you need to tell Cloud Foundry & the buildpack which version of Python you want. If you need Python 3, then you should tell it that. See here for instructions on doing that.
https://stackoverflow.com/a/50837696/1585136
Third, this error:
ERR OSError: [Errno 2] No such file or directory
Seems like you're trying to write to a location that does not exist. Where are you trying to write your file? The paths will be different on your local machine vs running on Cloud Foundry. Typically on Cloud Foundry, you would write temporary files to /home/vcap/tmp or /app/tmp (/app is a symlink to /home/vcap) or $HOME/tmp. They all point to the same place.
I'm specifically mentioning temporary files here because you don't want to write permanent files to the local file system on Cloud Foundry. The local file system is ephemeral and your data will not persist for very long. See here for details.
https://docs.cloudfoundry.org/devguide/deploy-apps/prepare-to-deploy.html#filesystem
Hope that helps!
Im running a solaris server which uses supervisor to monitor some Python applications.
Previously, I could run the command:
paster serve /opt/pyapps/menuadmin/prod.ini
from any directory on the server. There were some recent issues and the /opt folder was restored from a previous backup. This folder contained all of the applications including supervisor.
Now we are facing issues where supervisor will not start the applications because of "version conflicts" in Pylons.
This is where it gets weird and it makes no sense why these errors would occur.
If I run the paster command from outside of the program directory, it will throw the version conflict error. eg:
cd /
paster serve /opt/pyapps/menuadmin/prod.ini
Traceback (most recent call last):
File "/opt/csw/bin/paster", line 8, in <module>
load_entry_point('PasteScript==1.7.5', 'console_scripts', 'paster')()
File "/opt/csw/lib/python2.6/site-packages/PasteScript-1.7.5-py2.6.egg/paste/script/command.py", line 93, in run
commands = get_commands()
File "/opt/csw/lib/python2.6/site-packages/PasteScript-1.7.5-py2.6.egg/paste/script/command.py", line 135, in get_commands
plugins = pluginlib.resolve_plugins(plugins)
File "/opt/csw/lib/python2.6/site-packages/PasteScript-1.7.5-py2.6.egg/paste/script/pluginlib.py", line 82, in resolve_plugins
pkg_resources.require(plugin)
File "/opt/csw/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg/pkg_resources.py", line 626, in require
File "/opt/csw/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg/pkg_resources.py", line 528, in resolve
pkg_resources.VersionConflict: (Pylons 0.9.7 (/opt/csw/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg), Requirement.parse('Pylons>=0.10'))
But if I run the command from inside the program directory, it will run fine. eg:
cd /opt/pyapps/menuadmin/
paster serve /opt/pyapps/menuadmin/prod.ini
Starting server in PID 29902.
serving on http://127.0.0.1:3002
I absolutely cannot get my head around why this would happen!
Any thoughts or comments at all are appreciated!!!!
Based upon what you have said it seems you are running two different version of paster. The first version is running the older Pylons package 0.9.7, whilst the second has the more up to date version that meets or exceeds your app's requirements.
What I would do is first check which version of paster you are running. From outside of the project just run:
which paster
Then run the same command again within the project directory and compare the results. I suspect that you will find that the paths differ. If that is the case then all you need to do is update the version of pylons for the first version, which I'm guessing is the global install.
However, as others have commented it would be better to run apps within virtualenv, especially if as you seem to indicate you have multiple virtualenv and thus multiple projects. Trust me when I say it will save you from loads of headaches later on, from someone that didn't do this originally.