[Numpy-discussion] whitespace in git repo

Peter numpy-discussion at maubp.freeserve.co.uk
Wed Oct 27 12:00:43 EDT 2010


On Wed, Oct 27, 2010 at 4:49 PM, Friedrich Romstedt
<friedrichromstedt at gmail.com> wrote:
>
> Hi Peter,
>
> 2010/10/27 Peter <numpy-discussion at maubp.freeserve.co.uk>:
>> I'm interested since we also use git (and github) for a Python
>> project which is developed and tested on Linux, Mac OS X
>> and Windows. We haven't done anything special with the
>> repository settings about line endings... but so far it seems
>> to be working with the defaults.
>
> I can only guess, but I bet that you're using vim or any other editor
> which can handle both.  Since Python has universal newline support, it
> can also read both.  Seems that you're lucky that it's Python .....
> :-)
>
> You might use the od -c on Linux and Mac to check which files were
> created on Win and which on LF OSes ... supposed that I'm right at
> all.
>
> Would be a good check of my assumptions.
>
> Friedrich

Why use od when I can use Python ;)  (see below)

I've just tested a checkout of our repository on Mac OS X,
and found a single Python file with Windows newlines (CRLF)
but I'm pretty sure that happened before we moved to git.

Peter

--

#Quick script to check for potential new line issues
#or tab indentation instead of spaces
import os

def check(filename):
    #load in binary mode as I want to see any \r
    handle = open(filename, "rb")
    for line in handle:
        if "\t" in line or "\r" in line:
            print filename, repr(line)
    handle.close()

for dirpath, dirnames, filenames in os.walk("."):
    for f in filenames:
        if f.endswith(".py"):
            check(os.path.join(dirpath,f))
print "Done"



More information about the NumPy-Discussion mailing list