Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Add windows testing for python in CI #3562

Merged
merged 4 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ jobs:

# Separate build job for Python since we use a test matrix (will run in parallell)
build-python:
runs-on: ubuntu-latest
strategy:
matrix:
platform: [ubuntu-latest, windows-latest]
python-version: ["3.10", 3.11, 3.12]
runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v2
Expand All @@ -108,9 +109,14 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Fable Library - Python
- name: Fable Library - Python (linux)
if: matrix.platform == 'ubuntu-latest'
run: ./build.sh fable-library --python

- name: Fable Library - Python (Windows)
if: matrix.platform == 'windows-latest'
run: .\build.bat fable-library --python

- name: Install dependencies
run: |
pip install poetry
Expand Down
4 changes: 3 additions & 1 deletion src/fable-library-py/fable_library/Native.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ module Helpers =
let inline pushImpl (array: 'T []) (item: 'T) : int = !! array?append (item)

// Typed arrays not supported, only dynamic ones do
let inline insertImpl (array: 'T []) (index: int) (item: 'T) : 'T [] = !! array?insert(index, item)
let inline insertImpl (array: 'T []) (index: int) (item: 'T) : 'T [] =
!! array?insert(index, item)
array

// Typed arrays not supported, only dynamic ones do
let spliceImpl (array: 'T []) (start: int) (deleteCount: int) : 'T [] =
Expand Down
4 changes: 1 addition & 3 deletions src/fable-library-py/fable_library/bit_converter.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import struct
import sys

from typing import Optional


def get_bytes_char(value: str) -> bytes:
return bytes(value, "UTF-8")
Expand Down Expand Up @@ -110,7 +108,7 @@ def to_double(bytes: bytearray, offset: int) -> float:
return number


def to_string(bytes: bytearray, offset: int = 0, count: Optional[int] = None) -> str:
def to_string(bytes: bytearray, offset: int = 0, count: int | None = None) -> str:
count = len(bytes) if count is None else count
return "-".join([f"{x:02x}" for x in bytes[offset : offset + count]])

Expand Down
30 changes: 13 additions & 17 deletions src/fable-library-py/fable_library/map_util.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import re
from __future__ import annotations

import re
from collections.abc import ByteString, Iterable, MutableSequence
from enum import IntEnum
from re import Match
from typing import (
TYPE_CHECKING,
Any,
ByteString,
Dict,
Iterable,
List,
Match,
MutableSequence,
NoReturn,
Set,
TypeVar,
)

Expand Down Expand Up @@ -57,22 +53,22 @@ def change_case(string: str, case_rule: CaseRules) -> str:

if TYPE_CHECKING:

class FSharpMap(Dict[_K, _V]):
class FSharpMap(dict[_K, _V]):
...

else:
from .map import FSharpMap


def add_to_set(v: _V, st: Set[_V]) -> bool:
def add_to_set(v: _V, st: set[_V]) -> bool:
if v in st:
return False

st.add(v)
return True


def add_to_dict(di: Dict[_K, _V], k: _K, v: _V) -> None:
def add_to_dict(di: dict[_K, _V], k: _K, v: _V) -> None:
if k in di:
raise Exception(
"An item with the same key has already been added. Key: " + str(k)
Expand All @@ -81,7 +77,7 @@ def add_to_dict(di: Dict[_K, _V], k: _K, v: _V) -> None:
di[k] = v


def remove_from_dict(di: Dict[_K, Any], k: _K) -> bool:
def remove_from_dict(di: dict[_K, Any], k: _K) -> bool:
if k in di:
del di[k]
return True
Expand All @@ -99,19 +95,19 @@ def try_get_value(
return False


def get_item_from_dict(map: Dict[_K, _V], key: _K) -> _V:
def get_item_from_dict(map: dict[_K, _V], key: _K) -> _V:
if key in map:
return map[key]
else:
raise Exception(f"The given key '{key}' was not present in the dictionary.")


def contains_value(v: _V, map: Dict[Any, _V]) -> bool:
def contains_value(v: _V, map: dict[Any, _V]) -> bool:
return v in map.values()


def key_value_list(fields: Iterable[Any], case_rule: CaseRules = CaseRules.Ignore):
obj: Dict[str, Any] = {}
obj: dict[str, Any] = {}
defined_case_rule = case_rule

def fail(kvPair: Any) -> NoReturn:
Expand All @@ -129,10 +125,10 @@ def assign(key: str, case_rule: CaseRules, value: Any):
# Deflate unions and use the defined case rule
if isinstance(kv_pair, Union):
name = kv_pair.cases()[kv_pair.tag]
kv_pair = name if len(kv_pair.fields) == 0 else [name] + kv_pair.fields
kv_pair = name if len(kv_pair.fields) == 0 else [name, *kv_pair.fields]
case_rule = defined_case_rule

if isinstance(kv_pair, (List, MutableSequence, ByteString)):
if isinstance(kv_pair, list | MutableSequence | ByteString):
length = len(kv_pair)
if length == 0:
fail(kv_pair)
Expand Down
1 change: 0 additions & 1 deletion src/fable-library-py/fable_library/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ def interpolate(string: str, values: list[Any]) -> str:
matchIndex = match.start() + len(match[1] or "")
result += string[strIdx:matchIndex].replace("%%", "%")
[_, flags, padLength, precision, format] = match.groups()
# print(match.groups())
result += format_replacement(
values[valIdx], flags, padLength, precision, format
)
Expand Down
Loading