From befc6da3d8a1dd5842bd1145223f980a037bd9a5 Mon Sep 17 00:00:00 2001 From: hantianfeng Date: Fri, 6 Sep 2024 17:39:49 +0800 Subject: [PATCH] Enhanced code generation tools to support Python classes --- examples/lib/thread.php | 26 + lib/python/matplotlib/pyplot.php | 831 ------------------- lib/python/os.php | 52 +- lib/python/os/DirEntry.php | 15 + lib/python/os/GenericAlias.php | 15 + lib/python/os/_wrap_close.php | 20 + lib/python/os/error.php | 15 + lib/python/os/sched_param.php | 15 + lib/python/os/stat_result.php | 15 + lib/python/os/statvfs_result.php | 15 + lib/python/os/terminal_size.php | 15 + lib/python/os/times_result.php | 15 + lib/python/os/uname_result.php | 15 + lib/python/os/waitid_result.php | 15 + lib/python/subprocess.php | 29 +- lib/python/subprocess/CalledProcessError.php | 16 + lib/python/subprocess/CompletedProcess.php | 20 + lib/python/subprocess/Popen.php | 46 + lib/python/subprocess/SubprocessError.php | 15 + lib/python/subprocess/TimeoutExpired.php | 16 + lib/python/threading/Thread.php | 59 ++ tools/gen-lib.php | 118 --- tools/gen-php-lib.php | 38 + tools/{gen-pymod.php => gen-py-mod.php} | 0 tools/src/Tool.php | 165 +++- tools/templates/php-class.tpl | 24 + 26 files changed, 630 insertions(+), 995 deletions(-) create mode 100644 examples/lib/thread.php delete mode 100644 lib/python/matplotlib/pyplot.php create mode 100644 lib/python/os/DirEntry.php create mode 100644 lib/python/os/GenericAlias.php create mode 100644 lib/python/os/_wrap_close.php create mode 100644 lib/python/os/error.php create mode 100644 lib/python/os/sched_param.php create mode 100644 lib/python/os/stat_result.php create mode 100644 lib/python/os/statvfs_result.php create mode 100644 lib/python/os/terminal_size.php create mode 100644 lib/python/os/times_result.php create mode 100644 lib/python/os/uname_result.php create mode 100644 lib/python/os/waitid_result.php create mode 100644 lib/python/subprocess/CalledProcessError.php create mode 100644 lib/python/subprocess/CompletedProcess.php create mode 100644 lib/python/subprocess/Popen.php create mode 100644 lib/python/subprocess/SubprocessError.php create mode 100644 lib/python/subprocess/TimeoutExpired.php create mode 100644 lib/python/threading/Thread.php delete mode 100644 tools/gen-lib.php create mode 100644 tools/gen-php-lib.php rename tools/{gen-pymod.php => gen-py-mod.php} (100%) create mode 100644 tools/templates/php-class.tpl diff --git a/examples/lib/thread.php b/examples/lib/thread.php new file mode 100644 index 0000000..0d511f3 --- /dev/null +++ b/examples/lib/thread.php @@ -0,0 +1,26 @@ +sleep(1); + echo "[Thread#{$i}]\thello world\n"; + } + }); + $thread->start(); + $threads[] = $thread; + echo "Thread#{$i} is started\n"; +} + diff --git a/lib/python/matplotlib/pyplot.php b/lib/python/matplotlib/pyplot.php deleted file mode 100644 index 2a18cb4..0000000 --- a/lib/python/matplotlib/pyplot.php +++ /dev/null @@ -1,831 +0,0 @@ -` for the plotting methods on an Axes:: - - import numpy as np - import matplotlib.pyplot as plt - - x = np.arange(0, 5, 0.1) - y = np.sin(x) - fig, ax = plt.subplots() - ax.plot(x, y) - - -See :ref:`api_interfaces` for an explanation of the tradeoffs between the -implicit and explicit interfaces. -*/ -class pyplot{ - /** - * @return pyplot - */ - public static function import() - { - return \PyCore::import('matplotlib.pyplot'); - } - - public $__name__ = "matplotlib.pyplot"; - public $__package__ = "matplotlib"; - public $_backend_mod = null; - - public $Annotation = null; - public $Arrow = null; - public $Artist = null; - public $AutoLocator = null; - public $Axes = null; - public $Button = null; - public $Circle = null; - public $Enum = null; - public $ExitStack = null; - public $Figure = null; - public $FigureBase = null; - public $FigureCanvasBase = null; - public $FigureManagerBase = null; - public $FixedFormatter = null; - public $FixedLocator = null; - public $FormatStrFormatter = null; - public $Formatter = null; - public $FuncFormatter = null; - public $GridSpec = null; - public $IndexLocator = null; - public $Line2D = null; - public $LinearLocator = null; - public $Locator = null; - public $LogFormatter = null; - public $LogFormatterExponent = null; - public $LogFormatterMathtext = null; - public $LogLocator = null; - public $MaxNLocator = null; - public $MouseButton = null; - public $MultipleLocator = null; - public $Normalize = null; - public $NullFormatter = null; - public $NullLocator = null; - public $Number = null; - public $PolarAxes = null; - public $Polygon = null; - public $Rectangle = null; - public $ScalarFormatter = null; - public $Slider = null; - public $Subplot = null; - public $SubplotSpec = null; - public $Text = null; - public $TickHelper = null; - public $Widget = null; - public $_REPL_DISPLAYHOOK = null; - public $_ReplDisplayHook = null; - public $_api = null; - public $_docstring = null; - public $_interactive_bk = null; - public $_log = null; - public $_pylab_helpers = null; - public $cbook = null; - public $cm = null; - public $color_sequences = null; - public $colormaps = null; - public $draw_all = null; - public $functools = null; - public $importlib = null; - public $inspect = null; - public $logging = null; - public $matplotlib = null; - public $mlab = null; - public $np = null; - public $rcParams = null; - public $rcParamsDefault = null; - public $rcParamsOrig = null; - public $rcsetup = null; - public $re = null; - public $style = null; - public $sys = null; - public $threading = null; - public $time = null; - - public function _auto_draw_if_interactive($fig, $val) - { - } - - public function _copy_docstring_and_deprecators($method, $func = null) - { - } - - public function _draw_all_if_interactive() - { - } - - public function _get_backend_mod() - { - } - - public function _get_pyplot_commands() - { - } - - public function _get_required_interactive_framework($backend_mod) - { - } - - public function _warn_if_gui_out_of_main_thread() - { - } - - public function acorr($x) - { - } - - public function angle_spectrum($x, $Fs = null, $Fc = null, $window = null, $pad_to = null, $sides = null) - { - } - - public function annotate($text, $xy, $xytext = null, $xycoords = "data", $textcoords = null, $arrowprops = null, $annotation_clip = null) - { - } - - public function arrow($x, $y, $dx, $dy) - { - } - - public function autoscale($enable = true, $axis = "both", $tight = null) - { - } - - public function autumn() - { - } - - public function axes($arg = null) - { - } - - public function axhline($y = 0, $xmin = 0, $xmax = 1) - { - } - - public function axhspan($ymin, $ymax, $xmin = 0, $xmax = 1) - { - } - - public function axis($arg = null) - { - } - - public function axline($xy1, $xy2 = null) - { - } - - public function axvline($x = 0, $ymin = 0, $ymax = 1) - { - } - - public function axvspan($xmin, $xmax, $ymin = 0, $ymax = 1) - { - } - - public function bar($x, $height, $width = 0.8, $bottom = null) - { - } - - public function bar_label($container, $labels = null) - { - } - - public function barbs() - { - } - - public function barh($y, $width, $height = 0.8, $left = null) - { - } - - public function bone() - { - } - - public function box($on = null) - { - } - - public function boxplot($x, $notch = null, $sym = null, $vert = null, $whis = null, $positions = null, $widths = null, $patch_artist = null, $bootstrap = null, $usermedians = null, $conf_intervals = null, $meanline = null, $showmeans = null, $showcaps = null, $showbox = null, $showfliers = null, $boxprops = null, $labels = null, $flierprops = null, $medianprops = null, $meanprops = null, $capprops = null, $whiskerprops = null, $manage_ticks = true, $autorange = false, $zorder = null, $capwidths = null) - { - } - - public function broken_barh($xranges, $yrange) - { - } - - public function cla() - { - } - - public function clabel($CS, $levels = null) - { - } - - public function clf() - { - } - - public function clim($vmin = null, $vmax = null) - { - } - - public function close($fig = null) - { - } - - public function cohere($x, $y, $NFFT = 256, $Fs = 2, $Fc = 0, $detrend = null, $window = null, $noverlap = 0, $pad_to = null, $sides = "default", $scale_by_freq = null) - { - } - - public function colorbar($mappable = null, $cax = null, $ax = null) - { - } - - public function connect($s, $func) - { - } - - public function contour() - { - } - - public function contourf() - { - } - - public function cool() - { - } - - public function copper() - { - } - - public function csd($x, $y, $NFFT = null, $Fs = null, $Fc = null, $detrend = null, $window = null, $noverlap = null, $pad_to = null, $sides = null, $scale_by_freq = null, $return_line = null) - { - } - - public function cycler() - { - } - - public function delaxes($ax = null) - { - } - - public function disconnect($cid) - { - } - - public function draw() - { - } - - public function draw_if_interactive() - { - } - - public function errorbar($x, $y, $yerr = null, $xerr = null, $fmt = "", $ecolor = null, $elinewidth = null, $capsize = null, $barsabove = false, $lolims = false, $uplims = false, $xlolims = false, $xuplims = false, $errorevery = 1, $capthick = null) - { - } - - public function eventplot($positions, $orientation = "horizontal", $lineoffsets = 1, $linelengths = 1, $linewidths = null, $colors = null, $alpha = null, $linestyles = "solid") - { - } - - public function figaspect($arg) - { - } - - public function figimage($X, $xo = 0, $yo = 0, $alpha = null, $norm = null, $cmap = null, $vmin = null, $vmax = null, $origin = null, $resize = false) - { - } - - public function figlegend() - { - } - - public function fignum_exists($num) - { - } - - public function figtext($x, $y, $s, $fontdict = null) - { - } - - public function figure($num = null, $figsize = null, $dpi = null) - { - } - - public function fill() - { - } - - public function fill_between($x, $y1, $y2 = 0, $where = null, $interpolate = false, $step = null) - { - } - - public function fill_betweenx($y, $x1, $x2 = 0, $where = null, $step = null, $interpolate = false) - { - } - - public function findobj($o = null, $match = null, $include_self = true) - { - } - - public function flag() - { - } - - public function gca() - { - } - - public function gcf() - { - } - - public function gci() - { - } - - public function get($obj) - { - } - - public function get_backend() - { - } - - public function get_cmap($name = null, $lut = null) - { - } - - public function get_current_fig_manager() - { - } - - public function get_figlabels() - { - } - - public function get_fignums() - { - } - - public function get_plot_commands() - { - } - - public function get_scale_names() - { - } - - public function getp($obj) - { - } - - public function ginput($n = 1, $timeout = 30, $show_clicks = true, $mouse_add = 1, $mouse_pop = 3, $mouse_stop = 2) - { - } - - public function gray() - { - } - - public function grid($visible = null, $which = "major", $axis = "both") - { - } - - public function hexbin($x, $y, $C = null, $gridsize = 100, $bins = null, $xscale = "linear", $yscale = "linear", $extent = null, $cmap = null, $norm = null, $vmin = null, $vmax = null, $alpha = null, $linewidths = null, $edgecolors = "face", $reduce_C_function = null, $mincnt = null, $marginals = false) - { - } - - public function hist($x, $bins = null, $range = null, $density = false, $weights = null, $cumulative = false, $bottom = null, $histtype = "bar", $align = "mid", $orientation = "vertical", $rwidth = null, $log = false, $color = null, $label = null, $stacked = false) - { - } - - public function hist2d($x, $y, $bins = 10, $range = null, $density = false, $weights = null, $cmin = null, $cmax = null) - { - } - - public function hlines($y, $xmin, $xmax, $colors = null, $linestyles = "solid", $label = "") - { - } - - public function hot() - { - } - - public function hsv() - { - } - - public function imread($fname, $format = null) - { - } - - public function imsave($fname, $arr) - { - } - - public function imshow($X, $cmap = null, $norm = null) - { - } - - public function inferno() - { - } - - public function install_repl_displayhook() - { - } - - public function interactive($b) - { - } - - public function ioff() - { - } - - public function ion() - { - } - - public function isinteractive() - { - } - - public function jet() - { - } - - public function legend() - { - } - - public function locator_params($axis = "both", $tight = null) - { - } - - public function loglog() - { - } - - public function magma() - { - } - - public function magnitude_spectrum($x, $Fs = null, $Fc = null, $window = null, $pad_to = null, $sides = null, $scale = null) - { - } - - public function margins() - { - } - - public function matshow($A, $fignum = null) - { - } - - public function minorticks_off() - { - } - - public function minorticks_on() - { - } - - public function new_figure_manager() - { - } - - public function nipy_spectral() - { - } - - public function pause($interval) - { - } - - public function pcolor() - { - } - - public function pcolormesh() - { - } - - public function phase_spectrum($x, $Fs = null, $Fc = null, $window = null, $pad_to = null, $sides = null) - { - } - - public function pie($x, $explode = null, $labels = null, $colors = null, $autopct = null, $pctdistance = 0.6, $shadow = false, $labeldistance = 1.1, $startangle = 0, $radius = 1, $counterclock = true, $wedgeprops = null, $textprops = null, $center = array ( - 0 => 0, - 1 => 0, -), $frame = false, $rotatelabels = false) - { - } - - public function pink() - { - } - - public function plasma() - { - } - - public function plot() - { - } - - public function plot_date($x, $y, $fmt = "o", $tz = null, $xdate = true, $ydate = false) - { - } - - public function polar() - { - } - - public function prism() - { - } - - public function psd($x, $NFFT = null, $Fs = null, $Fc = null, $detrend = null, $window = null, $noverlap = null, $pad_to = null, $sides = null, $scale_by_freq = null, $return_line = null) - { - } - - public function quiver() - { - } - - public function quiverkey($Q, $X, $Y, $U, $label) - { - } - - public function rc($group) - { - } - - public function rc_context($rc = null, $fname = null) - { - } - - public function rcdefaults() - { - } - - public function register_cmap() - { - } - - public function rgrids($radii = null, $labels = null, $angle = null, $fmt = null) - { - } - - public function savefig() - { - } - - public function sca($ax) - { - } - - public function scatter($x, $y, $s = null, $c = null, $marker = null, $cmap = null, $norm = null, $vmin = null, $vmax = null, $alpha = null, $linewidths = null) - { - } - - public function sci($im) - { - } - - public function semilogx() - { - } - - public function semilogy() - { - } - - public function set_cmap($cmap) - { - } - - public function set_loglevel() - { - } - - public function setp($obj) - { - } - - public function show() - { - } - - public function specgram($x, $NFFT = null, $Fs = null, $Fc = null, $detrend = null, $window = null, $noverlap = null, $cmap = null, $xextent = null, $pad_to = null, $sides = null, $scale_by_freq = null, $mode = null, $scale = null, $vmin = null, $vmax = null) - { - } - - public function spring() - { - } - - public function spy($Z, $precision = 0, $marker = null, $markersize = null, $aspect = "equal", $origin = "upper") - { - } - - public function stackplot($x) - { - } - - public function stairs($values, $edges = null) - { - } - - public function stem() - { - } - - public function step($x, $y) - { - } - - public function streamplot($x, $y, $u, $v, $density = 1, $linewidth = null, $color = null, $cmap = null, $norm = null, $arrowsize = 1, $arrowstyle = "-|>", $minlength = 0.1, $transform = null, $zorder = null, $start_points = null, $maxlength = 4, $integration_direction = "both", $broken_streamlines = true) - { - } - - public function subplot() - { - } - - public function subplot2grid($shape, $loc, $rowspan = 1, $colspan = 1, $fig = null) - { - } - - public function subplot_mosaic($mosaic) - { - } - - public function subplot_tool($targetfig = null) - { - } - - public function subplots($nrows = 1, $ncols = 1) - { - } - - public function subplots_adjust($left = null, $bottom = null, $right = null, $top = null, $wspace = null, $hspace = null) - { - } - - public function summer() - { - } - - public function suptitle($t) - { - } - - public function switch_backend($newbackend) - { - } - - public function table($cellText = null, $cellColours = null, $cellLoc = "right", $colWidths = null, $rowLabels = null, $rowColours = null, $rowLoc = "left", $colLabels = null, $colColours = null, $colLoc = "center", $loc = "bottom", $bbox = null, $edges = "closed") - { - } - - public function text($x, $y, $s, $fontdict = null) - { - } - - public function thetagrids($angles = null, $labels = null, $fmt = null) - { - } - - public function tick_params($axis = "both") - { - } - - public function ticklabel_format() - { - } - - public function tight_layout() - { - } - - public function title($label, $fontdict = null, $loc = null, $pad = null) - { - } - - public function tricontour() - { - } - - public function tricontourf() - { - } - - public function tripcolor() - { - } - - public function triplot() - { - } - - public function twinx($ax = null) - { - } - - public function twiny($ax = null) - { - } - - public function uninstall_repl_displayhook() - { - } - - public function violinplot($dataset, $positions = null, $vert = true, $widths = 0.5, $showmeans = false, $showextrema = true, $showmedians = false, $quantiles = null, $points = 100, $bw_method = null) - { - } - - public function viridis() - { - } - - public function vlines($x, $ymin, $ymax, $colors = null, $linestyles = "solid", $label = "") - { - } - - public function waitforbuttonpress($timeout = -1) - { - } - - public function winter() - { - } - - public function xcorr($x, $y, $normed = true, $detrend = null, $usevlines = true, $maxlags = 10) - { - } - - public function xkcd($scale = 1, $length = 100, $randomness = 2) - { - } - - public function xlabel($xlabel, $fontdict = null, $labelpad = null) - { - } - - public function xlim() - { - } - - public function xscale($value) - { - } - - public function xticks($ticks = null, $labels = null) - { - } - - public function ylabel($ylabel, $fontdict = null, $labelpad = null) - { - } - - public function ylim() - { - } - - public function yscale($value) - { - } - - public function yticks($ticks = null, $labels = null) - { - } - -} diff --git a/lib/python/os.php b/lib/python/os.php index 2b7a629..b1cea68 100644 --- a/lib/python/os.php +++ b/lib/python/os.php @@ -64,6 +64,23 @@ public static function import() public $F_ULOCK = 0; public $GRND_NONBLOCK = 1; public $GRND_RANDOM = 2; + public $MFD_ALLOW_SEALING = 2; + public $MFD_CLOEXEC = 1; + public $MFD_HUGETLB = 4; + public $MFD_HUGE_16GB = -2013265920; + public $MFD_HUGE_16MB = 1610612736; + public $MFD_HUGE_1GB = 2013265920; + public $MFD_HUGE_1MB = 1342177280; + public $MFD_HUGE_256MB = 1879048192; + public $MFD_HUGE_2GB = 2080374784; + public $MFD_HUGE_2MB = 1409286144; + public $MFD_HUGE_32MB = 1677721600; + public $MFD_HUGE_512KB = 1275068416; + public $MFD_HUGE_512MB = 1946157056; + public $MFD_HUGE_64KB = 1073741824; + public $MFD_HUGE_8MB = 1543503872; + public $MFD_HUGE_MASK = 63; + public $MFD_HUGE_SHIFT = 26; public $NGROUPS_MAX = 65536; public $O_ACCMODE = 3; public $O_APPEND = 1024; @@ -106,6 +123,7 @@ public static function import() public $P_NOWAITO = 1; public $P_PGID = 2; public $P_PID = 1; + public $P_PIDFD = 3; public $P_WAIT = 0; public $RTLD_DEEPBIND = 8; public $RTLD_GLOBAL = 256; @@ -114,6 +132,11 @@ public static function import() public $RTLD_NODELETE = 4096; public $RTLD_NOLOAD = 4; public $RTLD_NOW = 2; + public $RWF_APPEND = 16; + public $RWF_DSYNC = 2; + public $RWF_HIPRI = 1; + public $RWF_NOWAIT = 8; + public $RWF_SYNC = 4; public $R_OK = 4; public $SCHED_BATCH = 3; public $SCHED_FIFO = 1; @@ -167,34 +190,23 @@ public static function import() public $sep = "/"; public $supports_bytes_environ = true; - public $DirEntry = null; - public $GenericAlias = null; public $Mapping = null; public $MutableMapping = null; public $PathLike = null; public $_Environ = null; - public $_wrap_close = null; public $abc = null; public $confstr_names = null; public $environ = null; public $environb = null; - public $error = null; public $path = null; public $pathconf_names = null; - public $sched_param = null; public $st = null; - public $stat_result = null; - public $statvfs_result = null; public $supports_dir_fd = null; public $supports_effective_ids = null; public $supports_fd = null; public $supports_follow_symlinks = null; public $sys = null; public $sysconf_names = null; - public $terminal_size = null; - public $times_result = null; - public $uname_result = null; - public $waitid_result = null; public function WCOREDUMP($status) { @@ -300,6 +312,10 @@ public function confstr($name) { } + public function copy_file_range($src, $dst, $count, $offset_src = null, $offset_dst = null) + { + } + public function cpu_count() { } @@ -564,11 +580,7 @@ public function lockf($fd, $command, $length) { } - public function login_tty($fd) - { - } - - public function lseek($fd, $position, $whence) + public function lseek($fd, $position, $how) { } @@ -588,6 +600,10 @@ public function makedirs($name, $mode = 511, $exist_ok = false) { } + public function memfd_create($name, $flags = 1) + { + } + public function minor($device) { } @@ -620,6 +636,10 @@ public function pathconf($path, $name) { } + public function pidfd_open($pid, $flags = 0) + { + } + public function pipe() { } diff --git a/lib/python/os/DirEntry.php b/lib/python/os/DirEntry.php new file mode 100644 index 0000000..4646a26 --- /dev/null +++ b/lib/python/os/DirEntry.php @@ -0,0 +1,15 @@ +_self = \PyCore::import('os')->DirEntry(); + } + +} diff --git a/lib/python/os/GenericAlias.php b/lib/python/os/GenericAlias.php new file mode 100644 index 0000000..ed04c98 --- /dev/null +++ b/lib/python/os/GenericAlias.php @@ -0,0 +1,15 @@ +_self = \PyCore::import('os')->GenericAlias(); + } + +} diff --git a/lib/python/os/_wrap_close.php b/lib/python/os/_wrap_close.php new file mode 100644 index 0000000..57eeec0 --- /dev/null +++ b/lib/python/os/_wrap_close.php @@ -0,0 +1,20 @@ +_self = \PyCore::import('os')->_wrap_close($stream, $proc); + } + + public function close() + { + return $this->_self->close(); + } + +} diff --git a/lib/python/os/error.php b/lib/python/os/error.php new file mode 100644 index 0000000..dba072f --- /dev/null +++ b/lib/python/os/error.php @@ -0,0 +1,15 @@ +_self = \PyCore::import('os')->error(); + } + +} diff --git a/lib/python/os/sched_param.php b/lib/python/os/sched_param.php new file mode 100644 index 0000000..e6dbc27 --- /dev/null +++ b/lib/python/os/sched_param.php @@ -0,0 +1,15 @@ +_self = \PyCore::import('os')->sched_param(); + } + +} diff --git a/lib/python/os/stat_result.php b/lib/python/os/stat_result.php new file mode 100644 index 0000000..49b1a75 --- /dev/null +++ b/lib/python/os/stat_result.php @@ -0,0 +1,15 @@ +_self = \PyCore::import('os')->stat_result(); + } + +} diff --git a/lib/python/os/statvfs_result.php b/lib/python/os/statvfs_result.php new file mode 100644 index 0000000..78d70f0 --- /dev/null +++ b/lib/python/os/statvfs_result.php @@ -0,0 +1,15 @@ +_self = \PyCore::import('os')->statvfs_result(); + } + +} diff --git a/lib/python/os/terminal_size.php b/lib/python/os/terminal_size.php new file mode 100644 index 0000000..c7e2a2c --- /dev/null +++ b/lib/python/os/terminal_size.php @@ -0,0 +1,15 @@ +_self = \PyCore::import('os')->terminal_size(); + } + +} diff --git a/lib/python/os/times_result.php b/lib/python/os/times_result.php new file mode 100644 index 0000000..c607c5b --- /dev/null +++ b/lib/python/os/times_result.php @@ -0,0 +1,15 @@ +_self = \PyCore::import('os')->times_result(); + } + +} diff --git a/lib/python/os/uname_result.php b/lib/python/os/uname_result.php new file mode 100644 index 0000000..7b834d9 --- /dev/null +++ b/lib/python/os/uname_result.php @@ -0,0 +1,15 @@ +_self = \PyCore::import('os')->uname_result(); + } + +} diff --git a/lib/python/os/waitid_result.php b/lib/python/os/waitid_result.php new file mode 100644 index 0000000..43db325 --- /dev/null +++ b/lib/python/os/waitid_result.php @@ -0,0 +1,15 @@ +_self = \PyCore::import('os')->waitid_result(); + } + +} diff --git a/lib/python/subprocess.php b/lib/python/subprocess.php index 03e72f6..b7aa3bf 100644 --- a/lib/python/subprocess.php +++ b/lib/python/subprocess.php @@ -47,28 +47,21 @@ public static function import() public $PIPE = -1; public $STDOUT = -2; public $_PIPE_BUF = 4096; - public $_WNOHANG = 1; public $_USE_POSIX_SPAWN = true; public $_USE_VFORK = true; public $__name__ = "subprocess"; public $__package__ = ""; - public $_can_fork_exec = true; public $_mswindows = false; - public $CalledProcessError = null; - public $CompletedProcess = null; - public $Popen = null; - public $SubprocessError = null; - public $TimeoutExpired = null; public $_PopenSelector = null; public $_active = null; + public $_posixsubprocess = null; public $builtins = null; public $contextlib = null; public $errno = null; public $fcntl = null; public $io = null; - public $locale = null; public $os = null; public $select = null; public $selectors = null; @@ -79,14 +72,6 @@ public static function import() public $types = null; public $warnings = null; - public function _WIFSTOPPED($status) - { - } - - public function _WSTOPSIG($status) - { - } - public function _args_from_interpreter_flags() { } @@ -99,22 +84,10 @@ public function _optim_args_from_interpreter_flags() { } - public function _text_encoding() - { - } - public function _use_posix_spawn() { } - public function _waitpid($pid, $options) - { - } - - public function _waitstatus_to_exitcode($status) - { - } - public function call() { } diff --git a/lib/python/subprocess/CalledProcessError.php b/lib/python/subprocess/CalledProcessError.php new file mode 100644 index 0000000..3138492 --- /dev/null +++ b/lib/python/subprocess/CalledProcessError.php @@ -0,0 +1,16 @@ +_self = \PyCore::import('subprocess')->CalledProcessError($returncode, $cmd, $output, $stderr); + } + +} diff --git a/lib/python/subprocess/CompletedProcess.php b/lib/python/subprocess/CompletedProcess.php new file mode 100644 index 0000000..78f626c --- /dev/null +++ b/lib/python/subprocess/CompletedProcess.php @@ -0,0 +1,20 @@ +_self = \PyCore::import('subprocess')->CompletedProcess($args, $returncode, $stdout, $stderr); + } + + public function check_returncode() + { + return $this->_self->check_returncode(); + } + +} diff --git a/lib/python/subprocess/Popen.php b/lib/python/subprocess/Popen.php new file mode 100644 index 0000000..f12a2ab --- /dev/null +++ b/lib/python/subprocess/Popen.php @@ -0,0 +1,46 @@ +_self = \PyCore::import('subprocess')->Popen($args, $bufsize, $executable, $stdin, $stdout, $stderr, $preexec_fn, $close_fds, $shell, $cwd, $env, $universal_newlines, $startupinfo, $creationflags, $restore_signals, $start_new_session, $pass_fds); + } + + public function communicate($input = null, $timeout = null) + { + return $this->_self->communicate($input, $timeout); + } + + public function kill() + { + return $this->_self->kill(); + } + + public function poll() + { + return $this->_self->poll(); + } + + public function send_signal($sig) + { + return $this->_self->send_signal($sig); + } + + public function terminate() + { + return $this->_self->terminate(); + } + + public function wait($timeout = null) + { + return $this->_self->wait($timeout); + } + +} diff --git a/lib/python/subprocess/SubprocessError.php b/lib/python/subprocess/SubprocessError.php new file mode 100644 index 0000000..5efc05c --- /dev/null +++ b/lib/python/subprocess/SubprocessError.php @@ -0,0 +1,15 @@ +_self = \PyCore::import('subprocess')->SubprocessError(); + } + +} diff --git a/lib/python/subprocess/TimeoutExpired.php b/lib/python/subprocess/TimeoutExpired.php new file mode 100644 index 0000000..20c8a85 --- /dev/null +++ b/lib/python/subprocess/TimeoutExpired.php @@ -0,0 +1,16 @@ +_self = \PyCore::import('subprocess')->TimeoutExpired($cmd, $timeout, $output, $stderr); + } + +} diff --git a/lib/python/threading/Thread.php b/lib/python/threading/Thread.php new file mode 100644 index 0000000..6f5304f --- /dev/null +++ b/lib/python/threading/Thread.php @@ -0,0 +1,59 @@ +_self = \PyCore::import('threading')->Thread($group, $target, $name, $args, $kwargs); + } + + public function getName() + { + return $this->_self->getName(); + } + + public function isDaemon() + { + return $this->_self->isDaemon(); + } + + public function is_alive() + { + return $this->_self->is_alive(); + } + + public function join($timeout = null) + { + return $this->_self->join($timeout); + } + + public function run() + { + return $this->_self->run(); + } + + public function setDaemon($daemonic) + { + return $this->_self->setDaemon($daemonic); + } + + public function setName($name) + { + return $this->_self->setName($name); + } + + public function start() + { + return $this->_self->start(); + } + +} diff --git a/tools/gen-lib.php b/tools/gen-lib.php deleted file mode 100644 index 6cd962c..0000000 --- a/tools/gen-lib.php +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env php -{$name}; - - if (is_numeric($attr)) { - $constants[$name] = $attr; - } elseif (is_bool($attr) or is_string($attr)) { - $staticProperties[$name] = Tool::valueToRepr($attr); - } elseif ($attr === null) { - $staticProperties[$name] = Tool::valueToRepr(null); - } elseif ($name === '__doc__') { - $comment = strval($attr); - } elseif (in_array($name, $ignoreAttrs)) { - continue; - } elseif ($attr instanceof PyStr) { - $staticProperties[$name] = Tool::valueToRepr(PyCore::scalar($attr)); - } else { - $type = (strval(PyCore::type($attr))); - if ($type === "" or $type === "") { - try { - $info = $inspect->getfullargspec($attr); - } catch (\Throwable $e) { - continue; - } - $args = $info[0]; - $defaultValue = $info[3]; - $functions[$name] = [ - 'args' => gen_args($args, $defaultValue), - 'call' => gen_args($args), - ]; - } else { - $dynamicProperties[$name] = $type; - } - } -} - -$module_name_ext = 'python.' . $module_name; -$namespace = gen_namespace($module_name_ext); -$sub_dir = str_replace('.', '/', $module_name_ext); -$class = basename($sub_dir); - -Tool::render( - __DIR__ . '/templates/php-lib.tpl', - OUT_DIR . '/' . $sub_dir . '.php', - compact('module_name', 'module', 'class', 'comment', 'namespace', 'constants', 'staticProperties', 'dynamicProperties', 'functions'), - ' '', 'args' => '']; + $attrs = PyCore::dir($class); + foreach ($attrs as $name) { + $name = $name->__toString(); + if (in_array($name, self::$ignoreAttrs) or ($name[0] === '_' and $name !== '__init__')) { + continue; + } + $attr = $class->{$name}; + $type = PyCore::type($attr)->__toString(); + if ($type === "") { + $info = self::parseMethod($name, $attr); + if ($name === '__init__') { + $constructor = $info; + } else { + $methods[$name] = $info; + } + } elseif ($type === "") { + $properties[] = $name; + } else { + echo "[$module_name.$class_name.$name] attr unknown type: $type\n"; + } + } + + $module_name_ext = 'python.' . $module_name . '.' . $class_name; + $namespace = self::genNameSpace($module_name_ext); + $sub_dir = str_replace('.', '/', $module_name_ext); + self::render( + __DIR__ . '/../templates/php-class.tpl', + OUT_DIR . '/' . $sub_dir . '.php', + compact('class_name', 'module_name', 'namespace', 'properties', 'methods', 'constructor'), + 'getfullargspec($func); + $args = $info[0]; + $args = $args->__getitem__(PyCore::slice(1, null)); + $defaultValue = $info[3]; + return [ + 'args' => self::genArgs($args, $defaultValue), + 'call' => self::genArgs($args), + ]; + } + + public static function parseFunction($name, $func): array + { + $inspect = PyCore::import('inspect'); + $info = $inspect->getfullargspec($func); + $args = $info[0]; + $defaultValue = $info[3]; + return [ + 'args' => self::genArgs($args, $defaultValue), + 'call' => self::genArgs($args), + ]; + } + + public static function parseModule($module_name, $module): array + { + $staticProperties = []; + $dynamicProperties = []; + $constants = []; + $functions = []; + $classes = []; + $comment = ''; + $attrs = PyCore::dir($module); + + foreach ($attrs as $name) { + $name = strval($name); + $attr = $module->{$name}; + + if (is_numeric($attr)) { + $constants[$name] = $attr; + } elseif (is_bool($attr) or is_string($attr)) { + $staticProperties[$name] = self::valueToRepr($attr); + } elseif ($attr === null) { + $staticProperties[$name] = self::valueToRepr(null); + } elseif ($name === '__doc__') { + $comment = strval($attr); + } elseif (in_array($name, self::$ignoreAttrs)) { + continue; + } elseif ($attr instanceof PyStr) { + $staticProperties[$name] = self::valueToRepr(PyCore::scalar($attr)); + } else { + $type = (strval(PyCore::type($attr))); + if ($type === "" or $type === "") { + try { + $functions[$name] = self::parseFunction($name, $attr); + } catch (\Exception $e) { + continue; + } + } elseif ($type === "") { + self::parseClass($module_name, $name, $attr); + } else { + $dynamicProperties[$name] = $type; + } + } + } + + return compact( + 'staticProperties', + 'dynamicProperties', + 'constants', + 'functions', + 'classes', + 'comment', + ); + } + + static function genArgs($args, $default = null) + { + $n = count($args); + if ($n == 0) { + return ''; + } + $list = []; + foreach ($args as $arg) { + $list[] = '$' . $arg; + } + if ($default) { + $values = PyCore::scalar($default); + $pos = $n - count($values); + for ($i = $pos; $i < $n; $i++) { + $v = $values[$i - $pos]; + $list[$i] = $list[$i] . ' = ' . self::valueToRepr($v); + } + } + return implode(', ', $list); + } + + + static function genNameSpace($module_name_ext): string + { + $list = explode('.', $module_name_ext); + if (count($list) == 2) { + return $list[0]; + } + + return implode('\\', array_slice($list, 0, count($list) - 1)); + } } diff --git a/tools/templates/php-class.tpl b/tools/templates/php-class.tpl new file mode 100644 index 0000000..c5d8ab1 --- /dev/null +++ b/tools/templates/php-class.tpl @@ -0,0 +1,24 @@ +namespace ; + +/** + +* @property $ + +*/ +class +{ + private $_self; + + public function __construct() + { + $this->_self = \PyCore::import('')->(); + } + + $info): ?> + public function () + { + return $this->_self->(); + } + + +}