<commit_before>#!/usr/bin/env python
from os import listdir, rmdir
from os.path import isfile, join
import shlex
import shutil
import subprocess
import sys
from tempfile import mkdtemp
from zipfile import ZipFile

__version__ = '1.0'
__name__ = 'pystallone'

# prefer setuptools in favor of distutils
try:
    from setuptools.core import setup
    from setuptools.command.build import compile
    from setuptools.command.install import install
    from setuptools.command.clean import clean
    print "using setuptools"
except ImportError:
    from distutils.core import setup
    from distutils.command.build import build   
    from distutils.command.install import install
    from distutils.command.clean import clean
    print "using distutils"

stallone_api_jar = 'stallone-1.0-SNAPSHOT-api.jar'

lib_dir = 'libs/'

def create_include_jar_list():
    jars = [ f for f in listdir('libs/') if isfile(join('libs/', f)) ]
    cp_string = ''.join("--include " + lib_dir + "%s " \
                        % ''.join(map(str, x)) for x in jars)
    return cp_string

def create_packages(packages):
    cp_string = ''.join("--package %s " \
                        % ''.join(map(str, x)) for x in packages)
    return cp_string

def jcc_run(extra_args):
        """
            will generate a string containing the invocation of apache jcc
            to build a wrapper for the given stallone api jar. All depedencies
            of stallone will be included in the distribution 
            (added to java classpath).
        """
        call = sys.executable + ' -m jcc --jar ' + stallone_api_jar \
             + ' ' + create_include_jar_list() \
             + " --python " + __name__ + ' ' \
             + " --version " + __version__ + " --reserved extern" \
             + " --module util/ArrayWrapper" \
             + ' --files 2 '\
             + ' ' + extra_args 
        return call
    
class mybuild(build):
    """
    invokes apache jcc to build a wrapper for the public api of stallone 
    """
    def run(self):
        call = jcc_run('--build')
        print 'invoking: ', call
        return subprocess.call(shlex.split(call))

class myinstall(install):
    def run(self):
        # install to users home directory, because we know its writeable
        call = jcc_run('--install --extra-setup-arg --user')
        print 'invoking: ', call
        return subprocess.call(shlex.split(call))
            
class myclean(clean):
    def run(self):
        shutil.rmtree('build', ignore_errors=True)
        shutil.rmtree('dist', ignore_errors=True)
        shutil.rmtree('libs', ignore_errors=True)
        shutil.rmtree(__name__ + ".egg-info", ignore_errors=True)
    
setup(name=__name__,
      version=__version__,
      cmdclass=dict(build=mybuild,
                    install=myinstall,
                    clean=myclean),
      # runtime dependencies
      requires=['jcc (>=1.6)'])
<commit_msg>added possibility to add more required packages to wrapper generation list<commit_after>#!/usr/bin/env python
from os import listdir, rmdir
from os.path import isfile, join
import shlex
import shutil
import subprocess
import sys
from tempfile import mkdtemp
from zipfile import ZipFile

__version__ = '1.0'
__name__ = 'pystallone'

# prefer setuptools in favor of distutils
try:
    from setuptools.core import setup
    from setuptools.command.build import compile
    from setuptools.command.install import install
    from setuptools.command.clean import clean
    print "using setuptools"
except ImportError:
    from distutils.core import setup
    from distutils.command.build import build   
    from distutils.command.install import install
    from distutils.command.clean import clean
    print "using distutils"

stallone_api_jar = 'stallone-1.0-SNAPSHOT-api.jar'

lib_dir = 'libs/'

def create_include_jar_list():
    jars = [ f for f in listdir(lib_dir) if isfile(join(lib_dir, f)) ]
    cp_string = ''.join("--include " + lib_dir + "%s " \
                        % ''.join(map(str, x)) for x in jars)
    return cp_string

def create_packages(packages):
    cp_string = ''.join("--package %s " \
                        % ''.join(map(str, x)) for x in packages)
    return cp_string

def jcc_run(extra_args):
        """
            will generate a string containing the invocation of apache jcc
            to build a wrapper for the given stallone api jar. All depedencies
            of stallone will be included in the distribution 
            (added to java classpath).
        """
        
        """
            these are currently needed, since the markov model factory 
            depends on them
        """
        additional_packages = ['stallone.mc', 
                               'stallone.algebra',
                               'stallone.cluster']
        #additional_packages = '[]'
        
        call = sys.executable + ' -m jcc --jar ' + stallone_api_jar \
             + ' ' + create_include_jar_list() \
             + ' ' + create_packages(additional_packages) \
             + " --python " + __name__ + ' ' \
             + " --version " + __version__ + " --reserved extern" \
             + " --module util/ArrayWrapper.py" \
             + ' --files 2 '\
             + ' ' + extra_args
        return call
    
class mybuild(build):
    """
    invokes apache jcc to build a wrapper for the public api of stallone 
    """
    def run(self):
        call = jcc_run('--build')
        print 'invoking: ', call
        return subprocess.call(shlex.split(call))

class myinstall(install):
    def run(self):
        # install to users home directory, because we know its writeable
        call = jcc_run('--install --extra-setup-arg --user')
        print 'invoking: ', call
        return subprocess.call(shlex.split(call))
            
class myclean(clean):
    def run(self):
        shutil.rmtree('build', ignore_errors=True)
        shutil.rmtree('dist', ignore_errors=True)
        shutil.rmtree('libs', ignore_errors=True)
        shutil.rmtree(__name__ + ".egg-info", ignore_errors=True)
    
setup(name=__name__,
      version=__version__,
      cmdclass=dict(build=mybuild,
                    install=myinstall,
                    clean=myclean),
      # runtime dependencies
      requires=['jcc (>=1.6)'])

{'fraction_non_alphanumeric': 0.1035964353914704, 'fraction_numerical': 0.0022278803309993636, 'mean_word_length': 2.2531055900621118, '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': '5481621', 'n_tokens_mistral': 1869, 'n_tokens_neox': 1821, 'n_words': 516}