~andyc/oils

640bc11d741344bbff9176275829e85c2d90add5 — Andy C 2 months ago d536c22
[build/deps] Use a different version of typed_ast, for Fedora

The version of MyPy we're using for mycpp depends on typed_ast

However it is pinned to an older version that has this bug

https://github.com/python/typed_ast/issues/169

The compile error happens on Fedora (but not Debian or Alpine)

So we patch mypy-requirements.txt to use the new version, and it seems
to work.

TODO: Rebuild my wedge locally to test it.

---

Also add comments about potential algorithmic slowness for
value.SparseArray, which uses Dict[BigInt, str].
2 files changed, 63 insertions(+), 3 deletions(-)

M build/deps.sh
M builtin/func_misc.py
M build/deps.sh => build/deps.sh +24 -0
@@ 528,6 528,8 @@ install-py3-libs-in-venv() {
  # Avoids a warning, but doesn't fix typed_ast
  #time python3 -m pip install --find-links $package_dir wheel

  upgrade-typed-ast $mypy_dir/mypy-requirements.txt

  # for mycpp/
  time python3 -m pip install --find-links $package_dir -r $mypy_dir/test-requirements.txt



@@ 535,6 537,28 @@ install-py3-libs-in-venv() {
  time python3 -m pip install --find-links $package_dir pexpect
}

upgrade-typed-ast() {
  local file=$1
  sed -i 's/typed_ast.*/typed_ast==1.5.0/' $file
}

test-typed-ast() {
  local dir=~/wedge/oils-for-unix.org/pkg/mypy/0.780

  cp -v $dir/mypy-requirements.txt _tmp

  local file=_tmp/mypy-requirements.txt
  cat $file
  #echo

  # 1.5.0 fixed this bug
  # https://github.com/python/typed_ast/issues/169 

  upgrade-typed-ast $file
  echo
  cat $file
}

install-py3-libs-from-cache() {

  # As well as end users

M builtin/func_misc.py => builtin/func_misc.py +39 -3
@@ 481,6 481,9 @@ class FromJson8(vm._Callable):


class BashArrayToSparse(vm._Callable):
    """
    value.BashArray -> value.SparseArray, for testing
    """

    def __init__(self):
        # type: () -> None


@@ 494,14 497,17 @@ class BashArrayToSparse(vm._Callable):

        # List[str] with holes -> Dict[int, str]
        result = value.SparseArray({})
        for i, item in enumerate(strs):
            if item is not None:
                result.d[mops.IntWiden(i)] = item
        for i, s in enumerate(strs):
            if s is not None:
                result.d[mops.IntWiden(i)] = s

        return result


class DictToSparse(vm._Callable):
    """
    value.Dict -> value.SparseArray, for testing
    """

    def __init__(self):
        # type: () -> None


@@ 526,6 532,9 @@ class DictToSparse(vm._Callable):


class SparseOp(vm._Callable):
    """
    All ops on value.SparseArray, for testing performance
    """

    def __init__(self):
        # type: () -> None


@@ 564,6 573,21 @@ class SparseOp(vm._Callable):
            return value.Int(mops.ZERO)

        elif op_name == 'subst':  # "${a[@]}"
            # Algorithm to expand a Dict[BigInt, Str]
            #
            # 1. Copy the integer keys into a new List
            # 2. Sort them in numeric order
            # 3. Create a List[str] that's the same size as the keys
            # 4. Loop through sorted keys, look up value, and populate list
            #
            # There is another possible algorithm:
            #
            # 1. Copy the VALUES into a new list
            # 2. Somehow sort them by the CORRESPONDING key, which depends on
            #    Slab<> POSITION.  I think this does not fit within the
            #    std::sort() model.  I think we would have to write a little custom
            #    sort algorithm.

            keys = d.keys()
            mylib.BigIntSort(keys)
            # Pre-allocate


@@ 586,6 610,18 @@ class SparseOp(vm._Callable):

            # Pre-allocate
            items2 = [no_str] * n  # type: List[str]

            # Iterate from start to end.  Note that this algorithm is
            # theoretically slower than bash in the case where the array is
            # sparse (in the part selected by the slice)
            #
            # e.g. if you do ${a[@]:1:1000} e.g. to SHIFT, and there are only 3
            # elements, OSH will iterate through 999 integers and do 999 dict
            # lookups, while bash will follow 3 pointers.
            #
            # However, in practice, I think iterating through integers is
            # cheap.

            j = 0
            i = start
            while mops.Greater(end, i):  # i < end