Esempio n. 1
0
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 core.pyx.
    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 = get_pkg_version_module('astropy')

        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
        except:
            log.warn("WARNING: jinja2 could not be imported, so the existing "
                     "ERFA core.py and core.pyx files will be used")
            return

    name = 'erfa_generator'
    filename = os.path.join(ERFAPKGDIR, 'erfa_generator.py')

    try:
        from importlib import machinery as import_machinery
        loader = import_machinery.SourceFileLoader(name, filename)
        gen = loader.load_module()
    except ImportError:
        import imp
        gen = imp.load_source(name, filename)

    gen.main(gen.DEFAULT_ERFA_LOC,
             os.path.join(ERFAPKGDIR, 'core.py'),
             gen.DEFAULT_TEMPLATE_LOC,
             verbose=False)
Esempio n. 2
0
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 core.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 = get_pkg_version_module('astropy')

        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 core.c files will be used")
            return

    name = 'erfa_generator'
    filename = os.path.join(ERFAPKGDIR, 'erfa_generator.py')

    try:
        from importlib import machinery as import_machinery
        loader = import_machinery.SourceFileLoader(name, filename)
        gen = loader.load_module()
    except ImportError:
        import imp
        gen = imp.load_source(name, filename)

    gen.main(gen.DEFAULT_ERFA_LOC,
             os.path.join(ERFAPKGDIR, 'core.py'),
             gen.DEFAULT_TEMPLATE_LOC,
             verbose=False)
Esempio n. 3
0
def preprocess_source():
    # TODO: Move this to setup_helpers

    # Generating the wcslib 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 core.c.
    if all(os.path.exists(filename) for filename in GEN_FILES):
        # Determine modification times
        src_mtime = max(os.path.getmtime(filename) for filename in SRC_FILES)
        gen_mtime = min(os.path.getmtime(filename) for filename in GEN_FILES)

        version = get_pkg_version_module('astropy')

        if gen_mtime > src_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.modeling._projections 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:
            log.warn("WARNING: jinja2 could not be imported, so the existing "
                     "modeling _projections.c file will be used")
            return

    from jinja2 import Environment, FileSystemLoader

    #Prepare the jinja2 templating environment
    env = Environment(loader=FileSystemLoader(MODELING_SRC))

    c_in = env.get_template('projections.c.templ')
    c_out = c_in.render(projections=projections)

    with open(join(MODELING_SRC, 'projections.c'), 'w') as fd:
        fd.write(c_out)
Esempio n. 4
0
def preprocess_source():
    # TODO: Move this to setup_helpers

    # Generating the wcslib 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 core.c.
    if all(os.path.exists(filename) for filename in GEN_FILES):
        # Determine modification times
        src_mtime = max(os.path.getmtime(filename) for filename in SRC_FILES)
        gen_mtime = min(os.path.getmtime(filename) for filename in GEN_FILES)

        version = get_pkg_version_module('astropy')

        if gen_mtime > src_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.modeling._projections 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 "
                     "modeling _projections.c file will be used")
            return

    from jinja2 import Environment, FileSystemLoader

    #Prepare the jinja2 templating environment
    env = Environment(loader=FileSystemLoader(MODELING_SRC))

    c_in = env.get_template('projections.c.templ')
    c_out = c_in.render(projections=projections)

    with open(join(MODELING_SRC, 'projections.c'), 'w') as fd:
        fd.write(c_out)