<commit_before>#!/usr/bin/env python

import  os

class Makefile ( object ) :

    def __init__( self, cxx, cxxflags ) :
        self.cxx      = cxx
        self.cxxflags = cxxflags

    def __repr__( self ) :
        output =  "# {}\n\n".format( self.__class__.__name__ )
        output += "{:10} = {}\n".format( "CXX"       , self.cxx      ) if self.cxx else ""
        output += "{:10} = {}\n".format( "CXXFLAGS"  , self.cxxflags )
        output += "\n"
        output += "none :\n\n"
        output += "test :\n"
        output += "\tcd testing && touch *.cc && make all && ./test-c3\n\n"
        output += "distclean :\n"
        output += "\tcd app/decam && make realclean\n"
        output += "\tcd testing && make deepclean\n"
        return output

class EdisonMakefile ( Makefile ) :

    @classmethod
    def is_match( cls ) :
        return os.environ.get( "NERSC_HOST", "" ) == "edison"

    def __init__( self, cxx = None, cxxflags = None ) :
        cxx      = cxx      or "CC"
        cxxflags = cxxflags or "-std=c++11 -fast -no-ipo"
        super( EdisonMakefile, self ).__init__( cxx, cxxflags )

class ClangMakefile ( Makefile ) :

    @classmethod
    def is_match( cls ) :
        uname = os.uname()
        return uname[ 0 ].lower() == "darwin"

    def __init__( self, cxx = None, cxxflags = None ) :
        cxx      = cxx      or "c++"
        cxxflags = cxxflags or "-std=c++11 -O3"
        super( ClangMakefile, self ).__init__( cxx, cxxflags )

class TravisMakefile ( Makefile ) :

    @classmethod
    def is_match( cls ) :
        return len( filter( lambda x : x.startswith( "TRAVIS_" ), os.environ.keys() ) ) > 0

    def __init__( self, cxx = None, cxxflags = None ) :
        cxxflags = cxxflags or "-std=c++11 -O3"
        super( TravisMakefile, self ).__init__( cxx, cxxflags )

class MakefileFactory ( object ) :

    def __init__( self, **kwargs ) :
        self.registry = kwargs

    def create( self, makefile_type = None, **kwargs ) :
        if makefile_type is None :
            for key, makefile_class in self.registry.iteritems() :
                if not makefile_class.is_match() :
                    continue
                makefile_type = key
        if makefile_type is None :
            raise NotImplementedError( "unrecognized environment" )
        makefile_class = self.registry[ makefile_type ]
        return makefile_class( kwargs )

if __name__ == "__main__" :

    factory  = MakefileFactory( edison = EdisonMakefile, clang = ClangMakefile, travis = TravisMakefile )
    makefile = factory.create()
    with open( "Makefile", "w" ) as stream :
        stream.write( "{}".format( makefile ) )
<commit_msg>Added cori, clone of edison.<commit_after>#!/usr/bin/env python

import  os

class Makefile ( object ) :

    def __init__( self, cxx, cxxflags ) :
        self.cxx      = cxx
        self.cxxflags = cxxflags

    def __repr__( self ) :
        output =  "# {}\n\n".format( self.__class__.__name__ )
        output += "{:10} = {}\n".format( "CXX"       , self.cxx      ) if self.cxx else ""
        output += "{:10} = {}\n".format( "CXXFLAGS"  , self.cxxflags )
        output += "\n"
        output += "none :\n\n"
        output += "test :\n"
        output += "\tcd testing && touch *.cc && make all && ./test-c3\n\n"
        output += "distclean :\n"
        output += "\tcd app/decam && make realclean\n"
        output += "\tcd testing && make deepclean\n"
        return output

class EdisonMakefile ( Makefile ) :

    @classmethod
    def is_match( cls ) :
        return os.environ.get( "NERSC_HOST", "" ) == "edison"

    def __init__( self, cxx = None, cxxflags = None ) :
        cxx      = cxx      or "CC"
        cxxflags = cxxflags or "-std=c++11 -fast -no-ipo"
        super( EdisonMakefile, self ).__init__( cxx, cxxflags )

class CoriMakefile ( Makefile ) :

    @classmethod
    def is_match( cls ) :
        return os.environ.get( "NERSC_HOST", "" ) == "cori"

    def __init__( self, cxx = None, cxxflags = None ) :
        cxx      = cxx      or "CC"
        cxxflags = cxxflags or "-std=c++11 -fast -no-ipo"
        super( CoriMakefile, self ).__init__( cxx, cxxflags )

class ClangMakefile ( Makefile ) :

    @classmethod
    def is_match( cls ) :
        uname = os.uname()
        return uname[ 0 ].lower() == "darwin"

    def __init__( self, cxx = None, cxxflags = None ) :
        cxx      = cxx      or "c++"
        cxxflags = cxxflags or "-std=c++11 -O3"
        super( ClangMakefile, self ).__init__( cxx, cxxflags )

class TravisMakefile ( Makefile ) :

    @classmethod
    def is_match( cls ) :
        return len( filter( lambda x : x.startswith( "TRAVIS_" ), os.environ.keys() ) ) > 0

    def __init__( self, cxx = None, cxxflags = None ) :
        cxxflags = cxxflags or "-std=c++11 -O3"
        super( TravisMakefile, self ).__init__( cxx, cxxflags )

class MakefileFactory ( object ) :

    def __init__( self, **kwargs ) :
        self.registry = kwargs

    def create( self, makefile_type = None, **kwargs ) :
        if makefile_type is None :
            for key, makefile_class in self.registry.iteritems() :
                if not makefile_class.is_match() :
                    continue
                makefile_type = key
        if makefile_type is None :
            raise NotImplementedError( "unrecognized environment" )
        makefile_class = self.registry[ makefile_type ]
        return makefile_class( kwargs )

if __name__ == "__main__" :

    factory  = MakefileFactory( edison = EdisonMakefile, clang = ClangMakefile, travis = TravisMakefile, cori = CoriMakefile )
    makefile = factory.create()
    with open( "Makefile", "w" ) as stream :
        stream.write( "{}".format( makefile ) )

{'fraction_non_alphanumeric': 0.13115612993363604, 'fraction_numerical': 0.005588543485853999, 'mean_word_length': 2.1432491767288693, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2661875', 'n_tokens_mistral': 1952, 'n_tokens_neox': 1896, 'n_words': 512}