GitPython debug logs not available - python

In case I run a simple git command like
git fetch origin
remote: Counting objects: 26, done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 26 (delta 13), reused 12 (delta 12), pack-reused 8
Unpacking objects: 100% (26/26), done.
From https://github.com/edorado93/jocular
* branch master -> FETCH_HEAD
ed17d20..6e70ecd master -> origin/master
I want similar logs while executing this command using GitPython module. So the command goes something like this
git.fetch('origin')
I set the environment variable type(repo.git).GIT_PYTHON_TRACE="full" . Still on executing my script, I don't get any git logs on the console.
What am I missing here ?

You're missing the logging, without which GitPython doesn't seem to want to log anything:
import logging
logging.basicConfig(level=logging.INFO)
An example after this:
from git.cmd import Git
g = Git()
type(g).GIT_PYTHON_TRACE="full"
g.fetch('origin')
which outputs:
INFO:git.cmd:git fetch origin -> 0
''

Related

problem pushing changes to GitHub because of file that's not really there

I have been trying to push changes to my GitHub repo but been facing this problem:
Uploading LFS objects: 100% (164/164), 153 MB | 0 B/s, done.
Enumerating objects: 25977, done.
Counting objects: 100% (25968/25968), done.
Delta compression using up to 4 threads
Compressing objects: 100% (18133/18133), done.
Writing objects: 100% (25955/25955), 146.83 MiB | 232.00 KiB/s, done.
Total 25955 (delta 6561), reused 25816 (delta 6463)
remote: Resolving deltas: 100% (6561/6561), completed with 4 local objects.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: error: Trace: 9f797e9b5f7a1c01fca6706ad62e21ba
remote: error: See http://git.io/iEPt8g for more information.
remote: error: File venv/lib/python3.6/site-packages/tensorflow_core/python/_pywrap_tensorflow_internal.so is 225.31 MB; this exceeds GitHub's file size limit of 100.00 MB
To https://github.com/yovelcohen/nba-stats.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/yovelcohen/nba-stats.git'
(base) yovel#the-beastpad:~$ cd venv/lib/python3.6/site-packages/tensorflow_core/python/
bash: cd: venv/lib/python3.6/site-packages/tensorflow_core/python/_pywrap_tensorflow_internal.so: No such file or directory
I imported TensorFlow to the project but then removed it, when trying to delete it from the terminal it's not there (and when looking for it manually).
any help would be appreactied!
Since you should not push any generated binary file anyway, start first by removing them locally, commit and push:
git rm -r '*.so' -f
echo '*.so' >> .gitignore
But if that still fails, it means you are trying to push past commits (not just the latest one) with *.so files, even though the last commit no longer includes any such files.
If that is the case, since git filter-branch is soon deprecated, consider newren/git-filter-repo to remove any large files like those *.so ones, before pushing (or force pushing of that rewrites the content of past commits previously pushed).

Git script is running differently when I run it through subprocess.check_output?

When I run this Bash script
#!/bin/bash
cd /srv/http
unset GIT_DIR
git commit -am "design changes"
git push -u origin master
git checkout dev
git merge master
git commit -am "design changes"
git checkout master
through the command line, I get this output
[master 914422f] design changes
1 file changed, 17 deletions(-)
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 334 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
To https://blah#bitbucket.org/blah/blah.git
562207f..914422f master -> master
Branch master set up to track remote branch master from origin.
Switched to branch 'dev'
Updating 562207f..914422f
Fast-forward
save-design | 17 -----------------
1 file changed, 17 deletions(-)
On branch dev
nothing to commit, working directory clean
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
but when I run it through Python using
subprocess.check_output('./save-design', shell=True)
I get this output
M save-design
Already up-to-date.
M save-design
Your branch is up-to-date with 'origin/master'.
Why does this happen?
I still don't know why it's happening, but I fixed it by running it by sshing to localhost:
subprocess.check_output('ssh localhost "/srv/http/save-design"', shell=True)
could it be that you aren't setting the working directory for subprocess.check_output and so git is picking up whatever random working directory gets set?
subprocess.check_output('./save-design', cwd='/my/working/dir/', shell=True)

Fabric show print after executing commands

I have a post-receive hook on my git bare repo that excute this fabfile.py:
def deploy():
print(cyan('Pulling changes to local server'))
with cd('/var/www')
local('git pull')
It executes fine, but it shows the output for the local command before the print, like this:
remote: From /media/projetos/repositorios/test
remote: b057a4b..02d85b3 master -> origin/master
remote: Updating b057a4b..02d85b3
remote: Fast-forward
remote: .../test/template/catalog/product/list.phtml | 98 +++++++++++-----------
remote: 1 file changed, 47 insertions(+), 51 deletions(-)
remote: Pulling changes to local server
If i just ssh on the server and run fab deploy it works normal.
Add a sys.stdout.flush() call after printing, so that even if output is fully buffered (as it is on a pipe, which is the case when running under a git hook), it is sent to the output stream at that point, before running another command.

Deploy pure python to heroku

I "finished" a little python project and I want to deploy it on heroku
GitHub page.
I want to execute: python2 main.py -i json-rpc
in order to have the json-rpc server listening for connections
but I get the following error when pushing to heroku:
$ git push heroku master Counting objects: 153, done. Delta
compression using up to 8 threads. Compressing objects: 100% (87/87),
done. Writing objects: 100% (153/153), 43.42 KiB, done. Total 153
(delta 61), reused 153 (delta 61)
-----> Heroku receiving push ! Heroku push rejected, no Cedar-supported app detected
To git#heroku.com:panager.git ! [remote rejected] master -> master
(pre-receive hook declined) error: failed to push some refs to
'git#heroku.com:panager.git'
What you might want to try doing is creating a Procfile. The full filename is Procfile, no extension, and it goes in the main directory of your project folder.
The content of that file would be:
web: python main.py -i json-rpc
Give that a shot and see if it works.
Alternatively, you may have forgotten to create a virtualenv for your app.
You should follow the instructions in Heroku's guide Getting Started with Python on Heroku
Update:
Having finally tested this myself on a fresh Heroku app, what you're missing is a requirements.txt. Even though you don't have any dependencies, you still need it. Within your virtualenv in the main project folder, run pip freeze > requirements.txt, and then git add . then git commit -m "added requirements.txt", and then push to Heroku and it should work.
Also, make sure that requirements.txt is saved with ANSI encoding, not Unicode or UTF-8! If you're a total n00b like me you can simply open requirements.txt in Notepad, choose SAVE AS and change the "Encoding" from the drop down. I tried all of the recommendations above but my error was due to this simple encoding problem.

How to download the Enthought Tool Suite python script?

I have Python downloaded already, but want to contribute code to the Enthought Tool Suite (ETS). According to this site (http://code.enthought.com/source/):
it says to download the following python script: https://raw.github.com/enthought/ets/master/ets.py
I put the ets.py into the python script, save as...and in the Python Shell, I typed in "import ets"
However, nothing happens.
Also, the site says to run the following commands:
$ mkdir ets
$ cd ets # and copy ets.py here
$ python ets.py clone
Typing those lines in Python Shell gives me the message: "SyntaxError: invalid syntax"
As you can see, I'm new to Python, and I don't know what I'm doing. How do I download the ETS script and run the commands??
Those last commands aren't meant to be entered into the Python console, they're meant to be entered at the terminal shell.
localhost-2:tmp $ mkdir ets
localhost-2:tmp $ cd ets
localhost-2:ets $ cp ../ets.py .
This last command assumes that ets.py was in the original directory. Now we can run it [edit: make sure you have git installed, or this won't work]:
localhost-2:ets $ python ets.py clone
Cloning package encore
URL: https://github.com/enthought/encore.git
Cloning into encore...
remote: Counting objects: 1081, done.
remote: Compressing objects: 100% (483/483), done.
remote: Total 1081 (delta 729), reused 942 (delta 592)
Receiving objects: 100% (1081/1081), 981.12 KiB | 1.80 MiB/s, done.
Resolving deltas: 100% (729/729), done.
Cloning package traits
URL: https://github.com/enthought/traits.git
Cloning into traits...
[etc.]
Cloning package etsproxy
URL: https://github.com/enthought/etsproxy.git
Cloning into etsproxy...
remote: Counting objects: 3577, done.
remote: Compressing objects: 100% (2243/2243), done.
remote: Total 3577 (delta 1053), reused 3571 (delta 1047)
Receiving objects: 100% (3577/3577), 369.81 KiB, done.
Resolving deltas: 100% (1053/1053), done.
After this, you need to install everything (this will look different depending on your operating system):
localhost-2:ets $ python ets.py develop
Running command ['/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python', 'setup.py', 'develop'] in package encore
running develop
running egg_info
creating encore.egg-info
writing encore.egg-info/PKG-INFO
[long build process removed]

Categories

Resources