def get_wcslib_cfg(cfg, wcslib_files, include_paths): debug = import_file(os.path.join(WCSROOT, '..', 'version.py')).debug cfg['include_dirs'].append('numpy') cfg['define_macros'].extend([ ('ECHO', None), ('WCSTRIG_MACRO', None), ('ASTROPY_WCS_BUILD', None), ('_GNU_SOURCE', None)]) if (not setup_helpers.use_system_library('wcslib') or sys.platform == 'win32'): write_wcsconfig_h(include_paths) wcslib_path = join("cextern", "wcslib") # Path to wcslib wcslib_cpath = join(wcslib_path, "C") # Path to wcslib source files cfg['sources'].extend(join(wcslib_cpath, x) for x in wcslib_files) cfg['include_dirs'].append(wcslib_cpath) else: wcsconfig_h_path = join(WCSROOT, 'include', 'wcsconfig.h') if os.path.exists(wcsconfig_h_path): os.unlink(wcsconfig_h_path) cfg.update(setup_helpers.pkg_config(['wcslib'], ['wcs'])) if debug: cfg['define_macros'].append(('DEBUG', None)) cfg['undef_macros'].append('NDEBUG') if (not sys.platform.startswith('sun') and not sys.platform == 'win32'): cfg['extra_compile_args'].extend(["-fno-inline", "-O0", "-g"]) else: # Define ECHO as nothing to prevent spurious newlines from # printing within the libwcs parser cfg['define_macros'].append(('NDEBUG', None)) cfg['undef_macros'].append('DEBUG') if sys.platform == 'win32': # These are written into wcsconfig.h, but that file is not # used by all parts of wcslib. cfg['define_macros'].extend([ ('YY_NO_UNISTD_H', None), ('_CRT_SECURE_NO_WARNINGS', None), ('_NO_OLDNAMES', None), # for mingw32 ('NO_OLDNAMES', None), # for mingw64 ('__STDC__', None) # for MSVC ]) if sys.platform.startswith('linux'): cfg['define_macros'].append(('HAVE_SINCOS', None)) # Squelch a few compilation warnings in WCSLIB if setup_helpers.get_compiler_option() in ('unix', 'mingw32'): if not get_distutils_build_option('debug'): cfg['extra_compile_args'].extend([ '-Wno-strict-prototypes', '-Wno-unused-function', '-Wno-unused-value', '-Wno-uninitialized'])
def preprocess_source(): # Generating the ERFA wrappers should only be done if needed. This also # ensures that it is not done for any release tarball since those will # include core.py and ufunc.c. if all(os.path.exists(filename) for filename in GEN_FILES): # Determine modification times erfa_mtime = max(os.path.getmtime(filename) for filename in SRC_FILES) gen_mtime = min(os.path.getmtime(filename) for filename in GEN_FILES) version = import_file(os.path.join(ERFAPKGDIR, '..', 'version.py')) if gen_mtime > erfa_mtime: # If generated source is recent enough, don't update return elif version.release: # or, if we're on a release, issue a warning, but go ahead and use # the wrappers anyway log.warn( 'WARNING: The autogenerated wrappers in astropy._erfa ' 'seem to be older than the source templates used to ' 'create them. Because this is a release version we will ' 'use them anyway, but this might be a sign of some sort ' 'of version mismatch or other tampering. Or it might just ' 'mean you moved some files around or otherwise ' 'accidentally changed timestamps.') return # otherwise rebuild the autogenerated files # If jinja2 isn't present, then print a warning and use existing files try: import jinja2 # pylint: disable=W0611 except ImportError: log.warn("WARNING: jinja2 could not be imported, so the existing " "ERFA core.py and ufunc.c files will be used") return gen = import_file(os.path.join(ERFAPKGDIR, 'erfa_generator.py')) gen.main(verbose=False)
def preprocess_source(): # Generating the ERFA wrappers should only be done if needed. This also # ensures that it is not done for any release tarball since those will # include core.py and ufunc.c. if all(os.path.exists(filename) for filename in GEN_FILES): # Determine modification times erfa_mtime = max(os.path.getmtime(filename) for filename in SRC_FILES) gen_mtime = min(os.path.getmtime(filename) for filename in GEN_FILES) version = import_file(os.path.join(ERFAPKGDIR, '..', 'version.py')) if gen_mtime > erfa_mtime: # If generated source is recent enough, don't update return elif version.release: # or, if we're on a release, issue a warning, but go ahead and use # the wrappers anyway log.warn('WARNING: The autogenerated wrappers in astropy._erfa ' 'seem to be older than the source templates used to ' 'create them. Because this is a release version we will ' 'use them anyway, but this might be a sign of some sort ' 'of version mismatch or other tampering. Or it might just ' 'mean you moved some files around or otherwise ' 'accidentally changed timestamps.') return # otherwise rebuild the autogenerated files # If jinja2 isn't present, then print a warning and use existing files try: import jinja2 # pylint: disable=W0611 except ImportError: log.warn("WARNING: jinja2 could not be imported, so the existing " "ERFA core.py and ufunc.c files will be used") return gen = import_file(os.path.join(ERFAPKGDIR, 'erfa_generator.py')) gen.main(verbose=False)
# Licensed under a 3-clause BSD style license - see LICENSE.rst from __future__ import absolute_import import os from os.path import join from distutils.core import Extension from distutils import log from astropy.extern import six from astropy_helpers import setup_helpers, utils from astropy_helpers.version_helpers import get_pkg_version_module wcs_setup_package = utils.import_file( join('astropy', 'wcs', 'setup_package.py')) MODELING_ROOT = os.path.relpath(os.path.dirname(__file__)) MODELING_SRC = join(MODELING_ROOT, 'src') SRC_FILES = [join(MODELING_SRC, 'projections.c.templ'), __file__] GEN_FILES = [join(MODELING_SRC, 'projections.c')] # This defines the set of projection functions that we want to wrap. # The key is the projection name, and the value is the number of # parameters. # (These are in the order that the appear in the WCS coordinate # systems paper). projections = { 'azp': 2, 'szp': 3, 'tan': 0,
def generate_c_docstrings(): docstrings = import_file(os.path.join(WCSROOT, 'docstrings.py')) docstrings = docstrings.__dict__ keys = [ key for key, val in docstrings.items() if not key.startswith('__') and isinstance(val, str) ] keys.sort() docs = {} for key in keys: docs[key] = docstrings[key].encode('utf8').lstrip() + b'\0' h_file = io.StringIO() h_file.write("""/* DO NOT EDIT! This file is autogenerated by astropy/wcs/setup_package.py. To edit its contents, edit astropy/wcs/docstrings.py */ #ifndef __DOCSTRINGS_H__ #define __DOCSTRINGS_H__ """) for key in keys: val = docs[key] h_file.write('extern char doc_{0}[{1}];\n'.format(key, len(val))) h_file.write("\n#endif\n\n") setup_helpers.write_if_different( join(WCSROOT, 'include', 'astropy_wcs', 'docstrings.h'), h_file.getvalue().encode('utf-8')) c_file = io.StringIO() c_file.write("""/* DO NOT EDIT! This file is autogenerated by astropy/wcs/setup_package.py. To edit its contents, edit astropy/wcs/docstrings.py The weirdness here with strncpy is because some C compilers, notably MSVC, do not support string literals greater than 256 characters. */ #include <string.h> #include "astropy_wcs/docstrings.h" """) for key in keys: val = docs[key] c_file.write('char doc_{0}[{1}] = {{\n'.format(key, len(val))) for i in range(0, len(val), 12): section = val[i:i + 12] c_file.write(' ') c_file.write(''.join('0x{0:02x}, '.format(x) for x in section)) c_file.write('\n') c_file.write(" };\n\n") setup_helpers.write_if_different(join(WCSROOT, 'src', 'docstrings.c'), c_file.getvalue().encode('utf-8'))
# Licensed under a 3-clause BSD style license - see LICENSE.rst from __future__ import absolute_import import os from os.path import join from distutils.core import Extension from distutils import log from astropy.extern import six from astropy_helpers import setup_helpers, utils from astropy_helpers.version_helpers import get_pkg_version_module wcs_setup_package = utils.import_file(join('astropy', 'wcs', 'setup_package.py')) MODELING_ROOT = os.path.relpath(os.path.dirname(__file__)) MODELING_SRC = join(MODELING_ROOT, 'src') SRC_FILES = [join(MODELING_SRC, 'projections.c.templ'), __file__] GEN_FILES = [join(MODELING_SRC, 'projections.c')] # This defines the set of projection functions that we want to wrap. # The key is the projection name, and the value is the number of # parameters. # (These are in the order that the appear in the WCS coordinate # systems paper). projections = { 'azp': 2,
def generate_c_docstrings(): docstrings = import_file(os.path.join(WCSROOT, 'docstrings.py')) docstrings = docstrings.__dict__ keys = [ key for key, val in docstrings.items() if not key.startswith('__') and isinstance(val, str)] keys.sort() docs = {} for key in keys: docs[key] = docstrings[key].encode('utf8').lstrip() + b'\0' h_file = io.StringIO() h_file.write("""/* DO NOT EDIT! This file is autogenerated by astropy/wcs/setup_package.py. To edit its contents, edit astropy/wcs/docstrings.py */ #ifndef __DOCSTRINGS_H__ #define __DOCSTRINGS_H__ """) for key in keys: val = docs[key] h_file.write('extern char doc_{0}[{1}];\n'.format(key, len(val))) h_file.write("\n#endif\n\n") setup_helpers.write_if_different( join(WCSROOT, 'include', 'astropy_wcs', 'docstrings.h'), h_file.getvalue().encode('utf-8')) c_file = io.StringIO() c_file.write("""/* DO NOT EDIT! This file is autogenerated by astropy/wcs/setup_package.py. To edit its contents, edit astropy/wcs/docstrings.py The weirdness here with strncpy is because some C compilers, notably MSVC, do not support string literals greater than 256 characters. */ #include <string.h> #include "astropy_wcs/docstrings.h" """) for key in keys: val = docs[key] c_file.write('char doc_{0}[{1}] = {{\n'.format(key, len(val))) for i in range(0, len(val), 12): section = val[i:i+12] c_file.write(' ') c_file.write(''.join('0x{0:02x}, '.format(x) for x in section)) c_file.write('\n') c_file.write(" };\n\n") setup_helpers.write_if_different( join(WCSROOT, 'src', 'docstrings.c'), c_file.getvalue().encode('utf-8'))