Skip to content
Snippets Groups Projects
Commit 9a0ee891 authored by Denis Arrivault's avatar Denis Arrivault
Browse files

Correct utf8 version reading bug

parent efe5e612
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -8,32 +8,35 @@ import fileinput
def findFiles(directory, files=[]):
"""scan a directory for py, pyx, pxd extension files."""
for file in os.listdir(directory):
path = os.path.join(directory, file)
for filename in os.listdir(directory):
path = os.path.join(directory, filename)
if os.path.isfile(path) and (path.endswith(".py") or
path.endswith(".pyx") or
path.endswith(".pxd")):
if file != "__init__.py" and file != "version.py":
if filename != "__init__.py" and filename != "version.py":
files.append(path)
elif os.path.isdir(path):
findFiles(path, files)
return files
def fileUnStamping(file):
def fileUnStamping(filename):
""" Remove stamp from a file """
is_stamp = False
for line in fileinput.input(file, inplace=1):
for line in fileinput.input(filename, inplace=1):
if line.find("# COPYRIGHT #") != -1:
is_stamp = not is_stamp
elif not is_stamp:
print(line, end="")
def fileStamping(file, stamp):
""" Write a stamp on a file """
def fileStamping(filename, stamp):
""" Write a stamp on a file
WARNING : The stamping must be done on an default utf8 machine !
"""
old_stamp = False # If a copyright already exist over write it.
for line in fileinput.input(file, inplace=1):
for line in fileinput.input(filename, inplace=1):
if line.find("# COPYRIGHT #") != -1:
old_stamp = not old_stamp
elif line.startswith("# -*- coding: utf-8 -*-"):
......@@ -70,8 +73,8 @@ def writeStamp():
stamp = getStamp(*getVersionsAndDate())
files = findFiles(os.path.join(os.path.dirname(os.path.abspath(__file__)),
"ltfatpy"))
for file in files:
fileStamping(file, stamp)
for filename in files:
fileStamping(filename, stamp)
fileStamping("setup.py", stamp)
......@@ -79,8 +82,8 @@ def eraseStamp():
""" Erase a copyright stamp from all files """
files = findFiles(os.path.join(os.path.dirname(os.path.abspath(__file__)),
"ltfatpy"))
for file in files:
fileUnStamping(file)
for filename in files:
fileUnStamping(filename)
fileUnStamping("setup.py")
......
......@@ -5,7 +5,6 @@ from __future__ import print_function, division
import sys
import os
import shutil
import fileinput
import distutils.spawn as ds
import distutils.dir_util as dd
......@@ -50,10 +49,13 @@ def get_version():
########################
def set_version(ltfat_dir, VERSION):
filename = os.path.join(ltfat_dir, '__init__.py')
for line in fileinput.input(filename, inplace=1):
buf = ""
for line in open(filename):
if not line.startswith("__version__ ="):
print(line, end="")
open(filename, 'a').write('__version__ = "%s"\n' % VERSION)
buf += line
f = open(filename, "w", encoding="utf-8")
f.write(buf)
f.write('__version__ = "%s"\n' % VERSION)
#################
......@@ -164,8 +166,8 @@ def read(*paths):
#####################################
def findpyxfiles(directory, files=[]):
"""scan a directory for pyx extension files."""
for file in os.listdir(directory):
path = os.path.join(directory, file)
for filename in os.listdir(directory):
path = os.path.join(directory, filename)
if os.path.isfile(path) and path.endswith(".pyx"):
files.append(path.replace(os.path.sep, ".")[:-4])
elif os.path.isdir(path):
......@@ -220,7 +222,10 @@ class m_clean(clean):
# Custom sdist command
##############################
class m_sdist(sdist):
""" Build source package """
""" Build source package
WARNING : The stamping must be done on an default utf8 machine !
"""
def run(self):
if USE_COPYRIGHT:
......@@ -285,7 +290,6 @@ def setup_package():
'Programming Language :: C',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Topic :: Software Development',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Scientific/Engineering'
],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment