diff --git a/copyright.py b/copyright.py index 3a44af5d3bcb48d2653771f0fb22eda4e591f2d7..7b106692cf7ab632ef9ae56425a06d89bdd9b47f 100644 --- a/copyright.py +++ b/copyright.py @@ -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") diff --git a/setup.py b/setup.py index 63b6f6ed815a69c835044281d143dac4082af405..f8afae1695c513e218836d7da406bb94734bbb5f 100755 --- a/setup.py +++ b/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' ],