Пример #1
0
    def changelog(self, arguments: list = sys.argv[2:]):
        """Display changelog of current version"""
        parser = argparse.ArgumentParser(
            prog='ti changelog', description=f"{self.changelog.__doc__}")
        import taichi as ti
        if ti.is_release():
            args = parser.parse_args(arguments)
            changelog_md = os.path.join(ti.package_root(), 'CHANGELOG.md')
            with open(changelog_md) as f:
                print(f.read())
        else:
            parser.add_argument(
                'version',
                nargs='?',
                type=str,
                default='master',
                help="A version (tag) that git can use to compare diff with")
            parser.add_argument(
                '-s',
                '--save',
                action='store_true',
                help="Save changelog to CHANGELOG.md instead of print to stdout"
            )
            args = parser.parse_args(arguments)

            from . import make_changelog
            res = make_changelog.main(args.version, ti.core.get_repo_dir())
            if args.save:
                changelog_md = os.path.join(ti.core.get_repo_dir(),
                                            'CHANGELOG.md')
                with open(changelog_md, 'w') as f:
                    f.write(res)
            else:
                print(res)
Пример #2
0
    def _get_examples_dir() -> Path:
        """Get the path to the examples directory."""
        import taichi as ti

        root_dir = ti.package_root()
        examples_dir = Path(root_dir) / 'examples'
        return examples_dir
Пример #3
0
    def _test_python(args):
        print("\nRunning Python tests...\n")
        import taichi as ti
        import pytest
        if ti.is_release():
            root_dir = ti.package_root()
            test_dir = os.path.join(root_dir, 'tests')
        else:
            root_dir = ti.get_repo_directory()
            test_dir = os.path.join(root_dir, 'tests', 'python')
        pytest_args = []

        # TODO: use pathlib to deal with suffix and stem name manipulation
        if args.files:
            # run individual tests
            for f in args.files:
                # auto-complete file names
                if not f.startswith('test_'):
                    f = 'test_' + f
                if not f.endswith('.py'):
                    f = f + '.py'
                pytest_args.append(os.path.join(test_dir, f))
        else:
            # run all the tests
            pytest_args = [test_dir]
        if args.verbose:
            pytest_args += ['-s', '-v']
        if args.rerun:
            pytest_args += ['--reruns', args.rerun]
        if args.keys:
            pytest_args += ['-k', args.keys]
        if args.marks:
            pytest_args += ['-m', args.marks]
        if args.failed_first:
            pytest_args += ['--failed-first']
        if args.fail_fast:
            pytest_args += ['--exitfirst']
        try:
            if args.coverage:
                pytest_args += ['--cov-branch', '--cov=python/taichi']
            if args.cov_append:
                pytest_args += ['--cov-append']
        except AttributeError:
            pass

        try:
            from multiprocessing import cpu_count
            threads = min(8, cpu_count())  # To prevent running out of memory
        except NotImplementedError:
            threads = 2

        if not os.environ.get('TI_DEVICE_MEMORY_GB'):
            os.environ['TI_DEVICE_MEMORY_GB'] = '0.5'  # Discussion: #769

        env_threads = os.environ.get('TI_TEST_THREADS', '')
        threads = args.threads or env_threads or threads
        print(f'Starting {threads} testing thread(s)...')
        if int(threads) > 1:
            pytest_args += ['-n', str(threads)]
        return int(pytest.main(pytest_args))
Пример #4
0
def test_python(test_files=(), verbose=False):
  print("\nRunning python tests...\n")
  import taichi as ti
  import pytest
  test_dir = None
  if ti.is_release():
    test_dir = ti.package_root()
  else:
    test_dir = ti.get_repo_directory()
  test_dir = os.path.join(test_dir, 'tests', 'python')
  args = []
  if len(test_files):
    # run individual tests
    for f in test_files:
      # auto-compelete
      if not f.startswith('test_'):
        f = 'test_' + f
      if not f.endswith('.py'):
        f = f + '.py'
      args.append(os.path.join(test_dir, f))
  else:
    # run all the tests
    args = [test_dir]
  if verbose:
    args += ['-s']
  if len(test_files) == 0 or len(test_files) > 4:
    if int(pytest.main(['misc/empty_pytest.py', '-n1'])) == 0: # if pytest has xdist
      try:
        from multiprocessing import cpu_count
        cpu_count = cpu_count()
      except:
        cpu_count = 2
      print(f'Starting {cpu_count} testing thread(s)...')
      args += ['-n', str(cpu_count)]
  return int(pytest.main(args))
Пример #5
0
def get_examples_dir() -> Path:
    """Get the path to the examples directory."""
    import taichi as ti

    root_dir = ti.package_root() if ti.is_release() else ti.get_repo_directory(
    )
    examples_dir = Path(root_dir) / 'examples'
    return examples_dir
Пример #6
0
def test_python():
  print("\nRunning python tests...\n")
  import taichi as ti
  import pytest
  if ti.is_release():
    return int(pytest.main([os.path.join(ti.package_root(), 'tests')]))
  else:
    return int(pytest.main([os.path.join(ti.get_repo_directory(), 'tests')]))
Пример #7
0
    def _test_python(args):
        print("\nRunning Python tests...\n")
        import taichi as ti
        import pytest
        if ti.is_release():
            root_dir = ti.package_root()
            test_dir = os.path.join(root_dir, 'tests')
        else:
            root_dir = ti.get_repo_directory()
            test_dir = os.path.join(root_dir, 'tests', 'python')
        pytest_args = []

        # TODO: use pathlib to deal with suffix and stem name manipulation
        if args.files:
            # run individual tests
            for f in args.files:
                # auto-complete file names
                if not f.startswith('test_'):
                    f = 'test_' + f
                if not f.endswith('.py'):
                    f = f + '.py'
                pytest_args.append(os.path.join(test_dir, f))
        else:
            # run all the tests
            pytest_args = [test_dir]
        if args.verbose:
            pytest_args += ['-s', '-v']
        if args.rerun:
            if int(
                    pytest.main([
                        os.path.join(root_dir, 'misc/empty_pytest.py'),
                        '--reruns', '2', '-q'
                    ])) != 0:
                sys.exit(
                    "Plugin pytest-rerunfailures is not available for Pytest!")
            pytest_args += ['--reruns', args.rerun]
        # TODO: configure the parallel test runner in setup.py
        # follow https://docs.pytest.org/en/latest/example/simple.html#dynamically-adding-command-line-options
        if int(
                pytest.main([
                    os.path.join(root_dir, 'misc/empty_pytest.py'), '-n1', '-q'
                ])) == 0:  # test if pytest has xdist or not
            try:
                from multiprocessing import cpu_count
                threads = min(8,
                              cpu_count())  # To prevent running out of memory
            except NotImplementedError:
                threads = 2
            os.environ['TI_DEVICE_MEMORY_GB'] = '0.5'  # Discussion: #769

            env_threads = os.environ.get('TI_TEST_THREADS', '')
            threads = args.threads or env_threads or threads
            print(f'Starting {threads} testing thread(s)...')
            if int(threads) > 1:
                pytest_args += ['-n', str(threads)]
        else:
            print("[Warning] Plugin pytest-xdist is not available for Pytest!")
        return int(pytest.main(pytest_args))
Пример #8
0
def test_python(args):
    print("\nRunning python tests...\n")
    test_files = args.files
    import taichi as ti
    import pytest
    if ti.is_release():
        root_dir = ti.package_root()
        test_dir = os.path.join(root_dir, 'tests')
    else:
        root_dir = ti.get_repo_directory()
        test_dir = os.path.join(root_dir, 'tests', 'python')
    pytest_args = []
    if len(test_files):
        # run individual tests
        for f in test_files:
            # auto-complete file names
            if not f.startswith('test_'):
                f = 'test_' + f
            if not f.endswith('.py'):
                f = f + '.py'
            pytest_args.append(os.path.join(test_dir, f))
    else:
        # run all the tests
        pytest_args = [test_dir]
    if args.verbose:
        pytest_args += ['-s', '-v']
    if args.rerun:
        pytest_args += ['--reruns', args.rerun]
    if int(
            pytest.main(
                [os.path.join(root_dir, 'misc/empty_pytest.py'), '-n1',
                 '-q'])) == 0:  # test if pytest has xdist or not
        try:
            from multiprocessing import cpu_count
            threads = min(8, cpu_count())  # To prevent running out of memory
        except:
            threads = 2
        os.environ['TI_DEVICE_MEMORY_GB'] = '0.5'  # Discussion: #769
        arg_threads = None
        if args.threads is not None:
            arg_threads = int(args.threads)
        env_threads = os.environ.get('TI_TEST_THREADS', '')
        if arg_threads is not None:
            threads = arg_threads
        elif env_threads:
            threads = int(env_threads)
        print(f'Starting {threads} testing thread(s)...')
        if threads > 1:
            pytest_args += ['-n', str(threads)]
    return int(pytest.main(pytest_args))
Пример #9
0
def test_python(verbose=False):
  print("\nRunning python tests...\n")
  import taichi as ti
  import pytest
  if ti.is_release():
    test_dir = os.path.join(ti.package_root(), 'tests')
  else:
    test_dir = os.path.join(ti.get_repo_directory(), 'tests')

  args = [test_dir]
  if verbose:
    args += ['-s']

  return int(pytest.main(args))
Пример #10
0
def test_python(test_files=(), verbose=False):
    print("\nRunning python tests...\n")
    import taichi as ti
    import pytest
    if ti.is_release():
        root_dir = ti.package_root()
        test_dir = os.path.join(root_dir, 'tests')
    else:
        root_dir = ti.get_repo_directory()
        test_dir = os.path.join(root_dir, 'tests', 'python')
    args = []
    if len(test_files):
        # run individual tests
        for f in test_files:
            # auto-compelete
            if not f.startswith('test_'):
                f = 'test_' + f
            if not f.endswith('.py'):
                f = f + '.py'
            args.append(os.path.join(test_dir, f))
    else:
        # run all the tests
        args = [test_dir]
    if verbose:
        args += ['-s']
    if len(test_files) == 0 or len(test_files) > 4:
        if int(
                pytest.main(
                    [os.path.join(root_dir, 'misc/empty_pytest.py'),
                     '-n1'])) == 0:  # if pytest has xdist
            try:
                from multiprocessing import cpu_count
                threads = min(8,
                              cpu_count())  # To prevent running out of memory
            except:
                threads = 2
            env_threads = os.environ.get('TI_TEST_THREADS', '')
            if env_threads:
                threads = int(env_threads)
                print(
                    f'Following TI_TEST_THREADS to use {threads} testing thread(s)...'
                )
            print(f'Starting {threads} testing thread(s)...')
            if threads > 1:
                args += ['-n', str(threads)]
    return int(pytest.main(args))
Пример #11
0
def test_python(test_files=None, verbose=False):
  print("\nRunning python tests...\n")
  import taichi as ti
  import pytest
  test_dir = None
  if ti.is_release():
    test_dir = ti.package_root()
  else:
    test_dir = ti.get_repo_directory()
  test_dir = os.path.join(test_dir, 'tests', 'python')
  args = []
  if test_files:
    # run individual tests
    for f in test_files:
      args.append(os.path.join(test_dir, f))
  else:
    # run all the tests
    args = [test_dir]
  if verbose:
    args += ['-s']

  return int(pytest.main(args))
Пример #12
0
 def changelog(self, arguments: list = sys.argv[2:]):
     """Display changelog of current version"""
     changelog_md = os.path.join(ti.package_root(), 'CHANGELOG.md')
     with open(changelog_md) as f:
         print(f.read())