Changeset 7601:9546de5282e1
Legend:
- Unmodified
- Added
- Removed
-
.hgignore
r7564 r7601 114 114 ^c_lib/.sconsign.dblite$ 115 115 ^c_lib/libcsage.so$ 116 ^.cython_dependencies$ -
setup.py
r7599 r7601 9 9 from distutils.extension import Extension 10 10 from Cython.Distutils import build_ext 11 12 11 13 12 14 ## Choose cblas library -- note -- make sure to update sage/misc/cython.py … … 919 921 ###################################################################### 920 922 921 def get_dependencies(filename):923 def check_dependencies( filename, outfile ): 922 924 """ 923 computes everything that this file depends on 925 INPUT: 926 filename -- The name of a .pyx, .pxd, or .pxi to check dependencies in the SAGE source. 927 outfile -- The output file for which we are determining out-of-date-ness 928 929 OUTPUT: 930 bool -- whether or not outfile must be regenerated. 924 931 """ 925 li = [] 932 if is_older(filename, outfile): 933 print "\nBuilding %s because it depends on %s."%(outfile, filename) 934 return True 935 926 936 # Now we look inside the file to see what it cimports or include. 927 937 # If any of these files are newer than outfile, we rebuild … … 961 971 # Check to see if a/b/c/d.pxd exists and is newer than filename. 962 972 # If so, we have to regenerate outfile. If not, we're safe. 963 A = os.path.normpath(A) 964 if os.path.exists(A): 965 li.extend(get_dependencies(A)) 966 li.append(A) 973 if os.path.exists(A) and check_dependencies(A, outfile): 974 return True # yep we must rebuild 967 975 968 976 # OK, next we move on to include pxi files. … … 992 1000 A = R # restore 993 1001 # Finally, check to see if filename is older than A 994 A = os.path.normpath(A) 995 if os.path.exists(A): 996 li.extend(get_dependencies(A)) 997 li.append(A) 998 999 # if we get here, this file depends on nothing 1000 return li 1001 1002 def check_dependencies(filename, outfile, deps_of): 1003 """ 1004 INPUT: 1005 filename -- The name of a .pyx, .pxd, or .pxi to check dependencies in the SAGE source. 1006 outfile -- The output file for which we are determining out-of-date-ness 1007 1008 OUTPUT: 1009 bool -- whether or not outfile must be regenerated. 1010 """ 1011 # add filename to depend on filename 1012 try: 1013 deps = deps_of[filename] 1014 except KeyError: 1015 return True 1016 1017 for dep in deps: 1018 if is_older(dep, outfile): 1019 print "\nBuilding %s because it depends on %s."%(outfile, dep) 1002 if os.path.exists(A) and check_dependencies(A, outfile): 1020 1003 return True 1021 1004 1022 def need_to_cython(filename, outfile, deps): 1005 1006 def need_to_cython(filename, outfile): 1023 1007 """ 1024 1008 INPUT: 1025 1009 filename -- The name of a cython file in the SAGE source tree. 1026 1010 outfile -- The name of the corresponding c or cpp file in the build directory. 1027 deps -- a structure containing dependency information1028 1011 1029 1012 OUTPUT: … … 1034 1017 pxd = base+'.pxd' 1035 1018 1036 if check_dependencies(filename, outfile , deps):1019 if check_dependencies(filename, outfile): 1037 1020 return True 1038 if os.path.exists(pxd) and check_dependencies(pxd, outfile, deps):1021 elif os.path.exists(pxd) and check_dependencies(pxd, outfile): 1039 1022 return True 1040 return False 1041 1042 def process_cython_file(f, m, deps_of): 1023 else: 1024 return False 1025 1026 def process_cython_file(f, m): 1043 1027 """ 1044 1028 INPUT: … … 1048 1032 # This is a cython file, so process accordingly. 1049 1033 pyx_inst_file = '%s/%s'%(SITE_PACKAGES, f) 1050 # if f is *more recent* than the pyx_install_file1051 1034 if is_older(f, pyx_inst_file): 1052 1035 print "%s --> %s"%(f, pyx_inst_file) 1053 1036 os.system('cp %s %s 2>/dev/null'%(f, pyx_inst_file)) 1054 # we need to recompute the dependencies, here1055 deps_list = get_dependencies(f)1056 try:1057 deps_of[f].extend(deps_list)1058 except KeyError:1059 deps_of[f] = deps_list1060 1037 outfile = f[:-4] + ".c" 1061 1038 if m.language == 'c++': 1062 1039 outfile += 'pp' 1063 1040 1064 if need_to_cython(f, outfile , deps_of):1041 if need_to_cython(f, outfile): 1065 1042 # Insert the -o parameter to specify the output file (particularly for c++) 1066 cmd = "cython --embed-positions --incref-local-binop -I%s -o %s %s"%(os.getcwd(), outfile, f )1043 cmd = "cython --embed-positions --incref-local-binop -I%s -o %s %s"%(os.getcwd(), outfile, f) 1067 1044 print cmd 1068 1045 ret = os.system(cmd) … … 1070 1047 print "sage: Error running cython." 1071 1048 sys.exit(1) 1072 1073 1049 return [outfile] 1074 1050 1075 1051 1076 1052 def cython(ext_modules): 1077 import pickle1078 deps_filename = SAGE_DEVEL + 'sage/.cython_dependencies'1079 # check if the cached dependency information is there1080 if os.path.exists(deps_filename):1081 deps_file = open(deps_filename, 'r')1082 deps_of = pickle.load(deps_file)1083 deps_file.close()1084 deps_file = None1085 compute_all_deps = False1086 else:1087 compute_all_deps = True1088 deps_of = {}1089 1090 tot = 01091 1053 for m in ext_modules: 1092 1054 m.extra_compile_args += extra_compile_args … … 1095 1057 for i in range(len(m.sources)): 1096 1058 f = m.sources[i] 1097 if compute_all_deps: 1098 deps_list = get_dependencies(f) 1099 try: 1100 deps_of[f].extend(deps_list) 1101 except KeyError: 1102 deps_of[f] = deps_list 1103 pxd_file = f[:-4] + '.pxd' 1104 if os.path.exists(pxd_file): 1105 deps_list = get_dependencies(pxd_file) 1106 try: 1107 deps_of[pxd_file].extend(deps_list) 1108 except KeyError: 1109 deps_of[pxd_file] = deps_list 1110 1059 # s = open(f).read() 1111 1060 if f[-4:] == ".pyx": 1112 # run cython, to output the corresponding c/cpp file, 1113 # if needed 1114 new_sources += process_cython_file(f, m, deps_of) 1061 new_sources += process_cython_file(f, m) 1115 1062 else: 1116 1063 new_sources.append(f) 1117 1118 1064 m.sources = new_sources 1119 tot += len(m.sources) 1120 1121 # now cache the dependencies if we just computed them 1122 deps_file = open(deps_filename, 'w') 1123 pickle.dump(deps_of, deps_file) 1124 deps_file.close() 1065 1066 1125 1067 1126 1068 if not sdist:
Note: See TracChangeset
for help on using the changeset viewer.
