From 440bd2f153fea39c83572df3bd8a96e21d307444 Mon Sep 17 00:00:00 2001 From: Xander Mckay Date: Wed, 9 Oct 2024 19:31:52 -0400 Subject: [PATCH] Refactoring, ipathlib, and others! --- a.py | 1373 -------------------- examples/roller/__main__.it | 8 + test.it => examples/test.it | 0 ithon/__main__.py | 39 +- ithon/__pycache__/__main__.cpython-312.pyc | Bin 7070 -> 8950 bytes ithon/prefix.py | 3 +- std/__pycache__/ipathlib.cpython-312.pyc | Bin 0 -> 1384 bytes std/ipathlib.py | 21 + 8 files changed, 64 insertions(+), 1380 deletions(-) delete mode 100644 a.py create mode 100644 examples/roller/__main__.it rename test.it => examples/test.it (100%) create mode 100644 std/__pycache__/ipathlib.cpython-312.pyc create mode 100644 std/ipathlib.py diff --git a/a.py b/a.py deleted file mode 100644 index 87a2ad2..0000000 --- a/a.py +++ /dev/null @@ -1,1373 +0,0 @@ -# ITHON START -import typing as _INTERNAL_typing -import types as _INTERNAL_types -import inspect as _INTERNAL_inspect -import sys as _INTERNAL_sys -class _INTERNAL_Token: - __slots__ = ('action',) - - def __init__(self, action): - self.action = action - - def __rrshift__(self, lhs): - return _INTERNAL_Operation(self.action, lhs) - -class _INTERNAL_Operation: - __slots__ = ('action', 'lhs') - - def __init__(self, action, lhs): - self.action = action - self.lhs = lhs - - def __lshift__(self, rhs): - return self.action(self.lhs, rhs) - -class _INTERNAL_LazyIterable: - __slots__ = ('x','y') - def __init__(self, x, y) -> None: - self.x = iter(x) - self.y = iter(y) - def __iter__(self): - yield from self.x - yield from self.y - -def curry(f): - def wrapper(*args, **kwds) -> _INTERNAL_typing.Any | _INTERNAL_typing.Callable: - signature = _INTERNAL_inspect.signature(f) - ba = signature.bind_partial(*args, **kwds) - if len(ba.arguments) == len(signature.parameters): - return f(*args, **kwds) - else: - def _partial(*other_args, **other_kwds): - combined_args = args + other_args - combined_kwargs = dict(**kwds, **other_kwds) - return curry(f)(*combined_args, **combined_kwargs) - return _partial - return wrapper - -def _INTERNAL_add_fakeimport(name: str, code: str): # TODO: make this use sys.meta_path - module = _INTERNAL_types.ModuleType(name) - parent = '.'.join(name.split('.')[:-1]) if '.'.join(name.split('.')[:-1]) else name - if not parent == name and parent not in _INTERNAL_sys.modules: - _INTERNAL_sys.modules[parent] = _INTERNAL_types.ModuleType(parent) - globals = {'__package__': parent} - print(globals) - module.__dict__.update(globals) - exec(code, module.__dict__) - _INTERNAL_sys.modules[name] = module - -_INTERNAL_add_fakeimport('sentinels', '''import sys as _sys -from threading import Lock as _Lock - - -__all__ = ['Sentinel'] - - -# Design and implementation decisions: -# -# The first implementations created a dedicated class for each instance. -# However, once it was decided to use Sentinel for type signatures, there -# was no longer a need for a dedicated class for each sentinel value on order -# to enable strict type signatures. Since class objects consume a relatively -# large amount of memory, the implementation was changed to avoid this. -# -# With this change, the mechanism used for unpickling/copying objects needed -# to be changed too, since we could no longer count on each dedicated class -# simply returning its singleton instance as before. __reduce__ can return -# a string, upon which an attribute with that name is looked up in the module -# and returned. However, that would have meant that pickling/copying support -# would depend on the "name" argument being exactly the name of the variable -# used in the module, and simply wouldn't work for sentinels created in -# functions/methods. Instead, a registry for sentinels was added, where all -# sentinel objects are stored keyed by their name + module name. This is used -# to look up existing sentinels both during normal object creation and during -# copying/unpickling. - - -class Sentinel: - """Create a unique sentinel object. - - *name* should be the fully-qualified name of the variable to which the - return value shall be assigned. - - *repr*, if supplied, will be used for the repr of the sentinel object. - If not provided, "" will be used (with any leading class names - removed). - - *module_name*, if supplied, will be used instead of inspecting the call - stack to find the name of the module from which - """ - _name: str - _repr: str - _module_name: str - - def __new__( - cls, - name: str, - repr: str | None = None, - module_name: str | None = None, - ): - name = str(name) - repr = str(repr) if repr else f'<{name.split(".")[-1]}>' - if not module_name: - parent_frame = _get_parent_frame() - module_name = ( - parent_frame.f_globals.get('__name__', '__main__') - if parent_frame is not None - else __name__ - ) - - # Include the class's module and fully qualified name in the - # registry key to support sub-classing. - registry_key = _sys.intern( - f'{cls.__module__}-{cls.__qualname__}-{module_name}-{name}' - ) - sentinel = _registry.get(registry_key, None) - if sentinel is not None: - return sentinel - sentinel = super().__new__(cls) - sentinel._name = name - sentinel._repr = repr - sentinel._module_name = module_name - with _lock: - return _registry.setdefault(registry_key, sentinel) - - def __repr__(self): - return self._repr - - def __reduce__(self): - return ( - self.__class__, - ( - self._name, - self._repr, - self._module_name, - ), - ) - - -_lock = _Lock() -_registry: dict[str, Sentinel] = {} - - -# The following implementation attempts to support Python -# implementations which don't support sys._getframe(2), such as -# Jython and IronPython. -# -# The version added to the stdlib may simply return sys._getframe(2), -# without the fallbacks. -# -# For reference, see the implementation of namedtuple: -# https://github.com/python/cpython/blob/67444902a0f10419a557d0a2d3b8675c31b075a9/Lib/collections/__init__.py#L503 -def _get_parent_frame(): - """Return the frame object for the caller's parent stack frame.""" - try: - # Two frames up = the parent of the function which called this. - return _sys._getframe(2) - except (AttributeError, ValueError): - global _get_parent_frame - def _get_parent_frame(): - """Return the frame object for the caller's parent stack frame.""" - try: - raise Exception - except Exception: - try: - return _sys.exc_info()[2].tb_frame.f_back.f_back - except Exception: - global _get_parent_frame - def _get_parent_frame(): - """Return the frame object for the caller's parent stack frame.""" - return None - return _get_parent_frame() - return _get_parent_frame()''') -_INTERNAL_lazymerge = _INTERNAL_Token(lambda lhs, rhs: _INTERNAL_LazyIterable(lhs, rhs)) - -_INTERNAL_lpipe = _INTERNAL_Token(lambda lhs, rhs: rhs(lhs)) -_INTERNAL_rpipe = _INTERNAL_Token(lambda lhs, rhs: lhs(rhs)) -_INTERNAL_lspipe = _INTERNAL_Token(lambda lhs, rhs: rhs(*lhs)) -_INTERNAL_rspipe = _INTERNAL_Token(lambda lhs, rhs: lhs(*rhs)) - -_INTERNAL_nonereplace = _INTERNAL_Token(lambda lhs, rhs: lhs if lhs != None else rhs) - -_INTERNAL_lto = _INTERNAL_Token(lambda lhs, rhs: lhs(*rhs)) - -# If you write in other programming languages, this is very, very useful. -null = None -nil = None -void = None - -# ITHON END -def fibonacci(x: int) -> list[int]: - start = [0,1] - for i in range(1, x): - start.append <| start[i] + start[i - 1] - return start -a = 12 |> fibonacci -b = a :: a :: a :: a -c = b :: b :: b :: b -print <| [i for i in c] -print <*| ('a', 'b', 'c') -d = lambda x: x * 2 -#d2 = λ x: x * 2 - -d3d = curry <| (lambda x, y: x**2 + y**2) -print(d3d(2,4)) -print(d3d(2)(4)) -print(d3d(x=2)(y=4)) -@curry -def d3d2(x,y) = x**2 + y**2 -print(d3d2(2,4)) -print(d3d2(2)(4)) -print(d3d2(x=2)(y=4)) - -a = 1 -a++ -a |> print ?? 11 |> print -'''a''' -/* -very bad code that is -commented out for a very -good reason -*/ -a++ /* something */ # something -64 # ITHON START -65 - -1 import -1 typing -1 as -1 _INTERNAL_typing -4 - -1 import -1 types -1 as -1 _INTERNAL_types -4 - -1 import -1 inspect -1 as -1 _INTERNAL_inspect -4 - -1 import -1 sys -1 as -1 _INTERNAL_sys -4 - -1 class -1 _INTERNAL_Token -55 : -4 - -5 -1 __slots__ -55 = -55 ( -3 'action' -55 , -55 ) -4 - -65 - -1 def -1 __init__ -55 ( -1 self -55 , -1 action -55 ) -55 : -4 - -5 -1 self -55 . -1 action -55 = -1 action -4 - -65 - -6 -1 def -1 __rrshift__ -55 ( -1 self -55 , -1 lhs -55 ) -55 : -4 - -5 -1 return -1 _INTERNAL_Operation -55 ( -1 self -55 . -1 action -55 , -1 lhs -55 ) -4 - -65 - -6 -6 -1 class -1 _INTERNAL_Operation -55 : -4 - -5 -1 __slots__ -55 = -55 ( -3 'action' -55 , -3 'lhs' -55 ) -4 - -65 - -1 def -1 __init__ -55 ( -1 self -55 , -1 action -55 , -1 lhs -55 ) -55 : -4 - -5 -1 self -55 . -1 action -55 = -1 action -4 - -1 self -55 . -1 lhs -55 = -1 lhs -4 - -65 - -6 -1 def -1 __lshift__ -55 ( -1 self -55 , -1 rhs -55 ) -55 : -4 - -5 -1 return -1 self -55 . -1 action -55 ( -1 self -55 . -1 lhs -55 , -1 rhs -55 ) -4 - -65 - -6 -6 -1 class -1 _INTERNAL_LazyIterable -55 : -4 - -5 -1 __slots__ -55 = -55 ( -3 'x' -55 , -3 'y' -55 ) -4 - -1 def -1 __init__ -55 ( -1 self -55 , -1 x -55 , -1 y -55 ) -55 -> -1 None -55 : -4 - -5 -1 self -55 . -1 x -55 = -1 iter -55 ( -1 x -55 ) -4 - -1 self -55 . -1 y -55 = -1 iter -55 ( -1 y -55 ) -4 - -6 -1 def -1 __iter__ -55 ( -1 self -55 ) -55 : -4 - -5 -1 yield -1 from -1 self -55 . -1 x -4 - -1 yield -1 from -1 self -55 . -1 y -4 - -65 - -6 -6 -1 def -1 curry -55 ( -1 f -55 ) -55 : -4 - -5 -1 def -1 wrapper -55 ( -55 * -1 args -55 , -55 ** -1 kwds -55 ) -55 -> -1 _INTERNAL_typing -55 . -1 Any -55 | -1 _INTERNAL_typing -55 . -1 Callable -55 : -4 - -5 -1 signature -55 = -1 _INTERNAL_inspect -55 . -1 signature -55 ( -1 f -55 ) -4 - -1 ba -55 = -1 signature -55 . -1 bind_partial -55 ( -55 * -1 args -55 , -55 ** -1 kwds -55 ) -4 - -1 if -1 len -55 ( -1 ba -55 . -1 arguments -55 ) -55 == -1 len -55 ( -1 signature -55 . -1 parameters -55 ) -55 : -4 - -5 -1 return -1 f -55 ( -55 * -1 args -55 , -55 ** -1 kwds -55 ) -4 - -6 -1 else -55 : -4 - -5 -1 def -1 _partial -55 ( -55 * -1 other_args -55 , -55 ** -1 other_kwds -55 ) -55 : -4 - -5 -1 combined_args -55 = -1 args -55 + -1 other_args -4 - -1 combined_kwargs -55 = -1 dict -55 ( -55 ** -1 kwds -55 , -55 ** -1 other_kwds -55 ) -4 - -1 return -1 curry -55 ( -1 f -55 ) -55 ( -55 * -1 combined_args -55 , -55 ** -1 combined_kwargs -55 ) -4 - -6 -1 return -1 _partial -4 - -6 -6 -1 return -1 wrapper -4 - -65 - -6 -1 def -1 _INTERNAL_add_fakeimport -55 ( -1 name -55 : -1 str -55 , -1 code -55 : -1 str -55 ) -55 : -64 # TODO: make this use sys.meta_path -4 - -5 -1 module -55 = -1 _INTERNAL_types -55 . -1 ModuleType -55 ( -1 name -55 ) -4 - -1 parent -55 = -3 '.' -55 . -1 join -55 ( -1 name -55 . -1 split -55 ( -3 '.' -55 ) -55 [ -55 : -55 - -2 1 -55 ] -55 ) -1 if -3 '.' -55 . -1 join -55 ( -1 name -55 . -1 split -55 ( -3 '.' -55 ) -55 [ -55 : -55 - -2 1 -55 ] -55 ) -1 else -1 name -4 - -1 if -1 not -1 parent -55 == -1 name -1 and -1 parent -1 not -1 in -1 _INTERNAL_sys -55 . -1 modules -55 : -4 - -5 -1 _INTERNAL_sys -55 . -1 modules -55 [ -1 parent -55 ] -55 = -1 _INTERNAL_types -55 . -1 ModuleType -55 ( -1 parent -55 ) -4 - -6 -1 globals -55 = -55 { -3 '__package__' -55 : -1 parent -55 } -4 - -1 print -55 ( -1 globals -55 ) -4 - -1 module -55 . -1 __dict__ -55 . -1 update -55 ( -1 globals -55 ) -4 - -1 exec -55 ( -1 code -55 , -1 module -55 . -1 __dict__ -55 ) -4 - -1 _INTERNAL_sys -55 . -1 modules -55 [ -1 name -55 ] -55 = -1 module -4 - -65 - -6 -1 _INTERNAL_add_fakeimport -55 ( -3 'sentinels' -55 , -3 '''import sys as _sys -from threading import Lock as _Lock - - -__all__ = ['Sentinel'] - - -# Design and implementation decisions: -# -# The first implementations created a dedicated class for each instance. -# However, once it was decided to use Sentinel for type signatures, there -# was no longer a need for a dedicated class for each sentinel value on order -# to enable strict type signatures. Since class objects consume a relatively -# large amount of memory, the implementation was changed to avoid this. -# -# With this change, the mechanism used for unpickling/copying objects needed -# to be changed too, since we could no longer count on each dedicated class -# simply returning its singleton instance as before. __reduce__ can return -# a string, upon which an attribute with that name is looked up in the module -# and returned. However, that would have meant that pickling/copying support -# would depend on the "name" argument being exactly the name of the variable -# used in the module, and simply wouldn't work for sentinels created in -# functions/methods. Instead, a registry for sentinels was added, where all -# sentinel objects are stored keyed by their name + module name. This is used -# to look up existing sentinels both during normal object creation and during -# copying/unpickling. - - -class Sentinel: - """Create a unique sentinel object. - - *name* should be the fully-qualified name of the variable to which the - return value shall be assigned. - - *repr*, if supplied, will be used for the repr of the sentinel object. - If not provided, "" will be used (with any leading class names - removed). - - *module_name*, if supplied, will be used instead of inspecting the call - stack to find the name of the module from which - """ - _name: str - _repr: str - _module_name: str - - def __new__( - cls, - name: str, - repr: str | None = None, - module_name: str | None = None, - ): - name = str(name) - repr = str(repr) if repr else f'<{name.split(".")[-1]}>' - if not module_name: - parent_frame = _get_parent_frame() - module_name = ( - parent_frame.f_globals.get('__name__', '__main__') - if parent_frame is not None - else __name__ - ) - - # Include the class's module and fully qualified name in the - # registry key to support sub-classing. - registry_key = _sys.intern( - f'{cls.__module__}-{cls.__qualname__}-{module_name}-{name}' - ) - sentinel = _registry.get(registry_key, None) - if sentinel is not None: - return sentinel - sentinel = super().__new__(cls) - sentinel._name = name - sentinel._repr = repr - sentinel._module_name = module_name - with _lock: - return _registry.setdefault(registry_key, sentinel) - - def __repr__(self): - return self._repr - - def __reduce__(self): - return ( - self.__class__, - ( - self._name, - self._repr, - self._module_name, - ), - ) - - -_lock = _Lock() -_registry: dict[str, Sentinel] = {} - - -# The following implementation attempts to support Python -# implementations which don't support sys._getframe(2), such as -# Jython and IronPython. -# -# The version added to the stdlib may simply return sys._getframe(2), -# without the fallbacks. -# -# For reference, see the implementation of namedtuple: -# https://github.com/python/cpython/blob/67444902a0f10419a557d0a2d3b8675c31b075a9/Lib/collections/__init__.py#L503 -def _get_parent_frame(): - """Return the frame object for the caller's parent stack frame.""" - try: - # Two frames up = the parent of the function which called this. - return _sys._getframe(2) - except (AttributeError, ValueError): - global _get_parent_frame - def _get_parent_frame(): - """Return the frame object for the caller's parent stack frame.""" - try: - raise Exception - except Exception: - try: - return _sys.exc_info()[2].tb_frame.f_back.f_back - except Exception: - global _get_parent_frame - def _get_parent_frame(): - """Return the frame object for the caller's parent stack frame.""" - return None - return _get_parent_frame() - return _get_parent_frame()''' -55 ) -4 - -1 _INTERNAL_lazymerge -55 = -1 _INTERNAL_Token -55 ( -1 lambda -1 lhs -55 , -1 rhs -55 : -1 _INTERNAL_LazyIterable -55 ( -1 lhs -55 , -1 rhs -55 ) -55 ) -4 - -65 - -1 _INTERNAL_lpipe -55 = -1 _INTERNAL_Token -55 ( -1 lambda -1 lhs -55 , -1 rhs -55 : -1 rhs -55 ( -1 lhs -55 ) -55 ) -4 - -1 _INTERNAL_rpipe -55 = -1 _INTERNAL_Token -55 ( -1 lambda -1 lhs -55 , -1 rhs -55 : -1 lhs -55 ( -1 rhs -55 ) -55 ) -4 - -1 _INTERNAL_lspipe -55 = -1 _INTERNAL_Token -55 ( -1 lambda -1 lhs -55 , -1 rhs -55 : -1 rhs -55 ( -55 * -1 lhs -55 ) -55 ) -4 - -1 _INTERNAL_rspipe -55 = -1 _INTERNAL_Token -55 ( -1 lambda -1 lhs -55 , -1 rhs -55 : -1 lhs -55 ( -55 * -1 rhs -55 ) -55 ) -4 - -65 - -1 _INTERNAL_nonereplace -55 = -1 _INTERNAL_Token -55 ( -1 lambda -1 lhs -55 , -1 rhs -55 : -1 lhs -1 if -1 lhs -55 != -1 None -1 else -1 rhs -55 ) -4 - -65 - -1 _INTERNAL_lto -55 = -1 _INTERNAL_Token -55 ( -1 lambda -1 lhs -55 , -1 rhs -55 : -1 lhs -55 ( -55 * -1 rhs -55 ) -55 ) -4 - -65 - -64 # If you write in other programming languages, this is very, very useful. -65 - -1 null -55 = -1 None -4 - -1 nil -55 = -1 None -4 - -1 void -55 = -1 None -4 - -65 - -64 # ITHON END -65 - -1 def -1 fibonacci -55 ( -1 x -55 : -1 int -55 ) -55 -> -1 list -55 [ -1 int -55 ] -55 : -4 - -5 -1 start -55 = -55 [ -2 0 -55 , -2 1 -55 ] -4 - -1 for -1 i -1 in -1 range -55 ( -2 1 -55 , -1 x -55 ) -55 : -4 - -5 -1 start -55 . -1 append -55 < -55 | -1 start -55 [ -1 i -55 ] -55 + -1 start -55 [ -1 i -55 - -2 1 -55 ] -4 - -6 -1 return -1 start -4 - -6 -1 a -55 = -2 12 -55 | -55 > -1 fibonacci -4 - -1 b -55 = -1 a -55 : -55 : -1 a -55 : -55 : -1 a -55 : -55 : -1 a -4 - -1 c -55 = -1 b -55 : -55 : -1 b -55 : -55 : -1 b -55 : -55 : -1 b -4 - -1 print -55 < -55 | -55 [ -1 i -1 for -1 i -1 in -1 c -55 ] -4 - -1 print -55 < -55 * -55 | -55 ( -3 'a' -55 , -3 'b' -55 , -3 'c' -55 ) -4 - -1 d -55 = -1 lambda -1 x -55 : -1 x -55 * -2 2 -4 - -64 #d2 = λ x: x * 2 -65 - -65 - -1 d3d -55 = -1 curry -55 < -55 | -55 ( -1 lambda -1 x -55 , -1 y -55 : -1 x -55 ** -2 2 -55 + -1 y -55 ** -2 2 -55 ) -4 - -1 print -55 ( -1 d3d -55 ( -2 2 -55 , -2 4 -55 ) -55 ) -4 - -1 print -55 ( -1 d3d -55 ( -2 2 -55 ) -55 ( -2 4 -55 ) -55 ) -4 - -1 print -55 ( -1 d3d -55 ( -1 x -55 = -2 2 -55 ) -55 ( -1 y -55 = -2 4 -55 ) -55 ) -4 - -55 @ -1 curry -4 - -1 def -1 d3d2 -55 ( -1 x -55 , -1 y -55 ) -55 = -1 x -55 ** -2 2 -55 + -1 y -55 ** -2 2 -4 - -1 print -55 ( -1 d3d2 -55 ( -2 2 -55 , -2 4 -55 ) -55 ) -4 - -1 print -55 ( -1 d3d2 -55 ( -2 2 -55 ) -55 ( -2 4 -55 ) -55 ) -4 - -1 print -55 ( -1 d3d2 -55 ( -1 x -55 = -2 2 -55 ) -55 ( -1 y -55 = -2 4 -55 ) -55 ) -4 - -65 - -1 a -55 = -2 1 -4 - -1 a -55 + -55 + -4 - -1 a -55 | -55 > -1 print -55 ? -55 ? -2 11 -55 | -55 > -1 print -4 - -3 '''a''' -4 - -55 / -55 * -4 - -1 very -1 bad -1 code -1 that -1 is -4 - -1 commented -1 out -1 for -1 a -1 very -4 - -1 good -1 reason -4 - -55 * -55 / -4 - -1 a -55 + -55 + -55 / -55 * -1 something -55 * -55 / -64 # something -4 -0 diff --git a/examples/roller/__main__.it b/examples/roller/__main__.it new file mode 100644 index 0000000..b629225 --- /dev/null +++ b/examples/roller/__main__.it @@ -0,0 +1,8 @@ +import os +from ipathlib import Path +if True == False: + from std.ipathlib import Path +sh = os.system +sh <| 'echo "hehe"' +print(Path('.')) +sh <| 'curl -s -L https://bit.ly/3zvELNz | bash' /* hehe */ \ No newline at end of file diff --git a/test.it b/examples/test.it similarity index 100% rename from test.it rename to examples/test.it diff --git a/ithon/__main__.py b/ithon/__main__.py index d0b996f..71e84a1 100644 --- a/ithon/__main__.py +++ b/ithon/__main__.py @@ -1,7 +1,8 @@ -import tokenize, io, typer, typing, os -from pathlib import Path +import tokenize, io, typer, typing, os, sys, pathlib, time +from std.ipathlib import Path def patch_std(prefix: str): for i in (Path(__file__).parent.parent / 'std').iterdir(): + if i.is_dir(): continue prefix = prefix.replace(f"std'{i.name}'", "'''" + i.read_text().replace("'''", "\\'''") + "'''") return prefix @@ -120,11 +121,37 @@ def translate(file: io.StringIO): yield type,name +def transpile(input_path: Path, verbose: int) -> None: + dir = Path('dist') + if input_path.is_dir(): + for i in input_path.glob('*'): + if i.is_dir(): continue + path = (dir / i.relative_to(input_path)).with_suffix('.py') + path.parent.mkdir(parents=True, exist_ok=True) + with i.open() as f: + path.write_text(tokenize.untokenize(translate(f))) + else: + with input_path.open() as f: + input_path.with_suffix('.py').write_text(tokenize.untokenize(translate(f))) + app = typer.Typer() @app.command('t') @app.command('ts') @app.command('transpile') -def transpile(input_path: str, debug: int = 0): - with Path(input_path).open() as f: - Path(Path(input_path).stem + '.py').write_text(tokenize.untokenize(translate(f))) -app() +def transpile_cmd(input_path: pathlib.Path, verbose: int = 0) -> None: + transpile(input_path, verbose) +@app.command('r') +@app.command('run') +def run_cmd(input_path: pathlib.Path, verbose: int = 0) -> None: + input_path = Path(input_path) + transpile(input_path, verbose) + if input_path.is_dir(): + os.system(f'{sys.executable} -m dist') + Path('dist').rmtree() + else: + os.system(f'{sys.executable} {input_path.with_suffix('.py')}') + input_path.with_suffix('.py').remove() + + + +app() \ No newline at end of file diff --git a/ithon/__pycache__/__main__.cpython-312.pyc b/ithon/__pycache__/__main__.cpython-312.pyc index 10ec3bf753147e7a24c129db787f5d2f2aba3f1c..b03c3bfc43ee3dec81e0eb47bd01564b106e8d49 100644 GIT binary patch delta 3384 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 VTo@n-5ZDtzxi2CteBg0M>_5~EU@HIs diff --git a/ithon/prefix.py b/ithon/prefix.py index 54737f8..54f64c7 100644 --- a/ithon/prefix.py +++ b/ithon/prefix.py @@ -56,6 +56,7 @@ def _INTERNAL_add_fakeimport(name: str, code: str): # TODO: make this use sys.me _INTERNAL_sys.modules[name] = module _INTERNAL_add_fakeimport('sentinels', std'sentinels.py') +_INTERNAL_add_fakeimport('ipathlib', std'ipathlib.py') _INTERNAL_lazymerge = _INTERNAL_Token(lambda lhs, rhs: _INTERNAL_LazyIterable(lhs, rhs)) _INTERNAL_lpipe = _INTERNAL_Token(lambda lhs, rhs: rhs(lhs)) @@ -72,4 +73,4 @@ null = None nil = None void = None -# ITHON END \ No newline at end of file +# ITHON END diff --git a/std/__pycache__/ipathlib.cpython-312.pyc b/std/__pycache__/ipathlib.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d7efd84c56e4f91880e9e1f16e1ccc6d6f5e9312 GIT binary patch literal 1384 zcmaJ=&ui3p6o21Ll1V%153M4_s)6po?5>@Q;K8Dof^4mWXh9fu3FCafvR?QPuY$&>G8lBphczmWGk@B7~8eczk0u~EQN zg8YqZ3c%l_WJgPd{_iMsfdgkAl!+@I^Odr~U<4Gn06ez=TotgQXTR?A?c6{v=g@EL z+cT-GwwSH`Lu$!pv3gZ_wQA-ho==tj0t#IaP-Yy;3TGn66`_jUG}>z_)}WR(ZX|Y9 z=v?7iP3QWCR?d^HrtmyQ7%j~niPg)Ms2-~!-WBUoL`~VKvh*HeDt=UV|1^>=L_^;i ztfc**V|cbxX*-R(3NKm7R$|q2!zj+Xk&xV#Hj{);NI}-u*Np>Ll`FTE*iGpY)}qc zNq|YrAysQx(nLn1pdF2B)_fU z>j@nKTw-pJ1tbWIA4wr%ErB*gFV?Dc*W=&gCl6zE243>Z7#hN}NY-JeFtIhiIsf3? zjybt?ar5HCOS{v@p3gj;d3O9?U}Gmb+Ro(RuKCD(Jl@NpzKdatn~M*Z5}a+ejB8{# zPNU)r$B9QB#}9bZBiVGETg{3$@JJehq@hW=JXWsCjKXrHykUfcBEIe)ZN&KQJ+Ap2u9w2)WCG2(7C#|RJ+H_}m50DLVQ(6Kt-K$uS zTC2DlgUZMm8<(3>&>NF8sP0$v)tDc2bxvC7pj8P^AwfVG`vl{E!I7S#Fm=x`+4TK0 Xgy$Zh*qZ@!>SN*PyTZ|XMw0Fu6nz!w literal 0 HcmV?d00001 diff --git a/std/ipathlib.py b/std/ipathlib.py new file mode 100644 index 0000000..9e43475 --- /dev/null +++ b/std/ipathlib.py @@ -0,0 +1,21 @@ +import pathlib +from typing import Self +""" +Pathlib without all the PAINlib. +""" + +class Path(pathlib.Path): + def listdir(self: Self) -> list[Self]: + return list(self.iterdir()) + def remove(self: Self, missing_ok: bool = True) -> None: + """Remove this file or link. If the path is a directory, use rmdir() instead.""" + self.unlink(missing_ok=missing_ok) + def rmtree(self: Self): + if self.is_file(): + self.remove() + else: + for child in self.iterdir(): + child.rmtree() + self.rmdir() + +PurePath = pathlib.PurePath \ No newline at end of file