From ef9c42dc2cd6c00dd9e91f410c1eff92910f1de9 Mon Sep 17 00:00:00 2001 From: Garrett-R Date: Sat, 27 Jun 2015 15:11:12 -0700 Subject: [PATCH 1/3] DOC: Add warning for newbs not to edit auto-generated file --- pandas/src/generate_code.py | 14 ++++++++++++++ pandas/src/generated.pyx | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/pandas/src/generate_code.py b/pandas/src/generate_code.py index 5d4b18b36050f..dfba54842dbe5 100644 --- a/pandas/src/generate_code.py +++ b/pandas/src/generate_code.py @@ -1,3 +1,10 @@ +"""This file generates `generated.pyx` which is then included in `../algos.pyx` +during building. To regenerate `generated.pyx`, just run: + + `python2 generate_code.py`. + +""" + from __future__ import print_function # we only need to be able to run this file on 2.7 # don't introduce a pandas/pandas.compat import @@ -7,6 +14,12 @@ _int64_max = np.iinfo(np.int64).max +warning_to_new_contributors = """ +# DO NOT EDIT THIS FILE: This file was autogenerated from generate_code.py, so +# please edit that file and then run `python2 generate_code.py` to re-generate +# this file. +""" + header = """ cimport numpy as np cimport cython @@ -2528,6 +2541,7 @@ def generate_from_template(template, exclude=None): def generate_take_cython_file(path='generated.pyx'): with open(path, 'w') as f: + print(warning_to_new_contributors, file=f) print(header, file=f) print(generate_ensure_dtypes(), file=f) diff --git a/pandas/src/generated.pyx b/pandas/src/generated.pyx index 83dfacba45211..b67d99146e664 100644 --- a/pandas/src/generated.pyx +++ b/pandas/src/generated.pyx @@ -1,4 +1,9 @@ +# DO NOT EDIT THIS FILE: This file was autogenerated from generate_code.py, so +# please edit that file and then run `python2 generate_code.py` to re-generate +# this file. + + cimport numpy as np cimport cython From e34795866f3cdbc0fd06bc80af12fd73fd250652 Mon Sep 17 00:00:00 2001 From: Garrett-R Date: Sun, 28 Jun 2015 20:38:36 -0700 Subject: [PATCH 2/3] Make generate_code.py Py3-friendly --- pandas/src/generate_code.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pandas/src/generate_code.py b/pandas/src/generate_code.py index dfba54842dbe5..6681255fa0a3b 100644 --- a/pandas/src/generate_code.py +++ b/pandas/src/generate_code.py @@ -1,15 +1,12 @@ """This file generates `generated.pyx` which is then included in `../algos.pyx` during building. To regenerate `generated.pyx`, just run: - `python2 generate_code.py`. + `python generate_code.py`. """ from __future__ import print_function -# we only need to be able to run this file on 2.7 -# don't introduce a pandas/pandas.compat import -# or we get a bootstrapping problem -from StringIO import StringIO +from pandas.compat import StringIO import numpy as np _int64_max = np.iinfo(np.int64).max From 03bc0a1d03b2ab6919699a2e2afdf18569528d1f Mon Sep 17 00:00:00 2001 From: Garrett-R Date: Sun, 28 Jun 2015 20:48:11 -0700 Subject: [PATCH 3/3] Allow running `generate_code.py` from anywhere Previously you had to run it from inside the same directory, but it's less likely to mess up newbs if you can run it from anywhere. --- pandas/src/generate_code.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pandas/src/generate_code.py b/pandas/src/generate_code.py index 6681255fa0a3b..0a488a778cc6b 100644 --- a/pandas/src/generate_code.py +++ b/pandas/src/generate_code.py @@ -6,6 +6,7 @@ """ from __future__ import print_function +import os from pandas.compat import StringIO import numpy as np @@ -2536,7 +2537,12 @@ def generate_from_template(template, exclude=None): take_2d_multi_template] -def generate_take_cython_file(path='generated.pyx'): +def generate_take_cython_file(): + # Put `generated.pyx` in the same directory as this file + directory = os.path.dirname(os.path.realpath(__file__)) + filename = 'generated.pyx' + path = os.path.join(directory, filename) + with open(path, 'w') as f: print(warning_to_new_contributors, file=f) print(header, file=f)