<commit_before>import drake
import drake.cxx

class SDK:

  def __init__(self, root = None):

    if root is None:
      paths = [drake.Path('/usr'), drake.Path('/usr/local')]
    else:
      paths = [drake.Path(root)]
    self.__root = self.__search('bin/urbi', paths)
    self.__config = drake.cxx.Config()
    self.__config.add_system_include_path(self.__root / 'include')
    self.__config.lib('boost_system')

  def config(self):

    return self.__config

  def __search(self, what, where):

    what = drake.Path(what)
    for root in where:
      if (root / what).exists():
        return root
    if len(where) <= 1:
      desc = str(where[0])
    else:
      desc = '%s and %s' % (', '.join(map(str, where[:-1])), where[-1])
    raise drake.Exception('Unable to find %s in any of %s.' % (what, desc))

  def urbi(self):
    return self.__root / 'bin/urbi'

class UObject(drake.cxx.Module):

  def __init__(self, name, sources,
               urbi_sdk = None,
               cxx_toolkit = None,
               cxx_config = None):

    urbi_sdk = urbi_sdk or drake.urbi.SDK()
    cxx_toolkit = cxx_toolkit or drake.cxx.Toolkit()
    cxx_config = cxx_config or drake.cxx.Config()
    drake.cxx.Module.__init__(self, name, sources,
                              cxx_toolkit, cxx_config + urbi_sdk.config())
<commit_msg>Urbi: use the Configuration class, enable to require a version range.<commit_after>import drake
import drake.cxx

class SDK(drake.Configuration):

  def __init__(self, prefix = None, version = drake.Version()):
    if prefix is None:
      paths = [drake.Path('/usr'), drake.Path('/usr/local')]
    else:
      paths = [drake.Path(prefix)]
    self.__prefix = self._search('bin/urbi', paths)
    v = drake.cmd_output([str(self.urbi()), '--quiet', '--expression', 'System.version;shutdown;'])
    v = v.decode('utf-8').split(' ')[1].strip().split('"')[1].split('.')
    v = drake.Version(*map(int, v))
    if v not in version:
      raise Exception('Urbi SDK version (%s) does not match the requested version (%s).' % (v, version))
    self.__config = drake.cxx.Config()
    self.__config.add_system_include_path(self.__prefix / 'include')
    self.__config.lib('boost_system')

  def config(self):

    return self.__config

  def urbi(self):
    return self.__prefix / 'bin/urbi'

class UObject(drake.cxx.Module):

  def __init__(self, name, sources,
               urbi_sdk = None,
               cxx_toolkit = None,
               cxx_config = None):

    urbi_sdk = urbi_sdk or drake.urbi.SDK()
    cxx_toolkit = cxx_toolkit or drake.cxx.Toolkit()
    cxx_config = cxx_config or drake.cxx.Config()
    drake.cxx.Module.__init__(self, name, sources,
                              cxx_toolkit, cxx_config + urbi_sdk.config())

{'fraction_non_alphanumeric': 0.14456956047947694, 'fraction_numerical': 0.0025426807119505995, 'mean_word_length': 2.7777777777777777, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '3681731', 'n_tokens_mistral': 960, 'n_tokens_neox': 936, 'n_words': 215}