All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dennis Kaarsemaker <dennis@kaarsemaker.net>
To: Junio C Hamano <gitster@pobox.com>,
	Luke Diamand <luke@diamand.org>,
	Lars Schneider <larsxschneider@gmail.com>
Cc: Etienne Girard <etienne.g.girard@gmail.com>,
	Git Users <git@vger.kernel.org>
Subject: [PATCH] git-p4: import the ctypes module
Date: Tue, 20 Oct 2015 21:31:46 +0200	[thread overview]
Message-ID: <1445369506.8543.10.camel@kaarsemaker.net> (raw)
In-Reply-To: <xmqqy4ex8r8k.fsf@gitster.mtv.corp.google.com>

The ctypes module is used on windows to calculate free disk space, so it
must be imported.

Signed-off-by: Dennis Kaarsemaker <dennis@kaarsemaker.net>
---
 git-p4.py | 1 +
 1 file changed, 1 insertion(+)

On di, 2015-10-20 at 09:00 -0700, Junio C Hamano wrote:
> Luke Diamand <luke@diamand.org> writes:
> 
> > On 20 October 2015 at 11:34, Etienne Girard <
> > etienne.g.girard@gmail.com> wrote:
> > > Hello,
> > > 
> > > Git-p4 fail when I try to rebase with the error: "NameError:
> > > global
> > > name 'ctypes' is not defined". The error occurs when I use python
> > > 2.7.2 that is installed by default on my company's computers (it
> > > goes
> > > without saying that everything works fine with python 2.7.10).
> > > 
> > > I'm a beginner in python, but simply importing ctypes at the
> > > beginning
> > > of the script does the trick. I was wondering if submitting a
> > > patch
> > > for this issue is worth the trouble, when a satisfying solution
> > > is not
> > > using a 4 years old version of python.
> > 
> > If you're able to submit a patch that would be great!
> 
> Lars's  (git-p4: check free space during streaming,
> 2015-09-26) introduced two references to ctypes.* and there is no
> 'import ctypes' anywhere in the script.
> 
> I do not follow Python development, but does the above mean that
> with recent 2.x you can say ctypes without first saying "import
> ctypes"?  It feels somewhat non-pythonesque that identifiers like
> this is given to you without you asking with an explicit 'import',
> so I am puzzled.

No, you cannot do that. The reason others may not have noticed this bug is that
in git-p4.py, ctypes is only used on windows.

 111     if platform.system() == 'Windows':
 112         free_bytes = ctypes.c_ulonglong(0)
 113         ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(os.getcwd()), None, None, ctypes.pointer(free_bytes))

The fact that it works for the OP with 2.7.10 is puzzling (assuming that it's
on the same system). But this patch should help.

diff --git a/git-p4.py b/git-p4.py
index daa60c6..212ef2b 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -24,6 +24,7 @@ import shutil
 import stat
 import zipfile
 import zlib
+import ctypes
 
 try:
     from subprocess import CalledProcessError
-- 
2.6.2-323-g60bd420

  parent reply	other threads:[~2015-10-20 19:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-20 10:34 Git-p4 fails with NameError with python 2.7.2 Etienne Girard
2015-10-20 13:57 ` Luke Diamand
2015-10-20 16:00   ` Junio C Hamano
2015-10-20 16:42     ` Manlio Perillo
2015-10-20 19:31     ` Dennis Kaarsemaker [this message]
2015-10-20 19:36       ` [PATCH] git-p4: import the ctypes module Junio C Hamano
2015-10-20 23:00         ` Luke Diamand
2015-10-21  8:23           ` Etienne Girard
2015-10-21  9:54             ` Etienne Girard
2015-10-21 20:00             ` Lars Schneider

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1445369506.8543.10.camel@kaarsemaker.net \
    --to=dennis@kaarsemaker.net \
    --cc=etienne.g.girard@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=larsxschneider@gmail.com \
    --cc=luke@diamand.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.