196 IX: prepIX (196.html)

Keywords

ICH180RR "IX Macro Processor" IX Macro Processor python "unix timestamp" Geany Thonny sh shell "proper python dictionary" .pb _py.ix _html.ix _sh.ix _txt.ix _php.ix "source code" parameter version author run Terminal "Terminal Window" Raspberry Pi "Raspberry Pi" Pico MicroPython IX IXc marker "IX Family" "IX Modules" IXp "IX Family of Software" IX_menu_i.py .pyix yield return

/KeywordsEnd

(To enlarge .....Click it)
thumb: IXimage.jpg
IX or DC (IX by DC) or "|><"


This prepIX.py software is a part of the IX family of software.

Introduction

In previous articles, the author described a "buildIX" (or "buildMain") program that would insert the routines that were called by a main program. This program, named "prepIX.py" has now been written. Such a main program devoid of its routines is called a "proto-build-program" or a "main" calling program. The "prepIX.py" program is similar to a macro processor that provides the actual code cited by "macro" routine references. Such macro routines accept parameters that define what is to be done. These macro parameters are used to alter the final code produced by the macro proto-build-program code. This article explains how a proto-build-program can be constructed to "include" predefined routines in a program. In normal python software, a series of "import" statements cause code segments to be inserted (imported) in a program from a library that is usually external to the core (computer) being used. However, uploading routines to these external (usually remote) libraries is not a simple matter. Often, the generic routines that I wish to put in a library are for my personal use only, so the complexity of a formal library often outweighs the utility.

The prepIX.py program procedure is very similar to using an external library, but prepIX.py uses a "requires" statement instead of an "import" statement. In python, the "import" statement is never executed and is "ignored" during the running of the program, but an "import" statement does effectively import some "hidden" code as if it were actually in the main program. In prepIX.py, the "requires" statement is both used to trigger the prepIX preprocessor to insert a routine, and to also run the required routine in a "fettered" mode. In this (future) "fettered" mode, the "requires" statement will run the function only enough to validate that the version of the routine is high enough (recent enough) to satisfy the needs of the program using it. Any subsequent uses of the function (by the main program) are normal uses of the function (without rechecking the version). If the version of the routine is "too old" then a run-time error message (at the outset) will result. Note that all known "import"processes do NOT check to ensure that the version of the "included" routine is recent enough.

As with most laptops, the Raspberry Pi presumes that the user is "working" in the Desktop folder (ie the Desktop folder is the "current folder"). But while code is being developed, the IX user is expected to use the Desktop/IX_assets/ix folder. When prepIX.py is run, it presumes that it is running in the Desktop/IX_assets/ix folder. When prepIX.py learns that the program (that it is prepping) needs (or "requires") a routine, prepIX.py will first search the current folder, then it will search the "/home/pi/Desktop/ix/" folder (soon to be "/home/pi/Desktop/IX_assets/ix/") for each of the required routine(s). The prepIX program itself does NOT yet require any such routines, but it will. Both the program being built and the required routines can make use of normal python "import" statements. The normal python "import" statements are NOT presumed to contain any "requires" statements. At the moment, the prepIX.py program only processes a program named "main.pb". The "prepIX.py" program prepares the "main.pb" code to convert it into a program named "main.py" that is ready for python. The action of converting the "main.pb" program into the "main.py" program is called "prepping" (ie preparing) the program so that it can be compiled/run by python.

NOTE: Immediately above, the "macro" code mentioned must not have a ".py" extension, and an extension of ".pb" is suggested. As of 2024CMar30, the non-py extension will be ".pyix" not ".pb" . See articles 215 and 217 for examples of code using the ".pyix" extension.

Upcoming Changes

The following changes are in progress as of 2023KNov22:

The prepIX Lexicon

It is important to understand the different programs or types of "code modules" that are used by the prepIX system. For that reason, the following brief lexicon has been prepared:

Interactions between the IXc macro Processor and prepIX.py

This interaction is so simple that it is automatic. The IXc Macro Processor is invoked by a command in the RPi Terminal window. The IXc command can be quite long, but it results in the creation of a text module that can be processed by a program that accepts text as input. In the case when python code is created, another step (or process) is implemented prior to transferring the python code to python. The new step (or process) that is implemented is the prepIX.py step. After the IXc macro processor had done its "prepping' job, prepIX.py will do its prepping job, if necessary. While the IXc macro processor is "prepping" python-like stub code, it will watch for any "requires(...)" statements. If at least one such "requires(...)" exists in a python text file, the text file will be "prepped" by "prepIX.py" prior to it being processed by python. This will be done automatically without the programmer doing anything to cause this second "prep step". Early versions of the IX Software system used the word "requests". The word "requests" is being deprecated by the word "requires".

prepIX program status

The first version of the prepIX.py program has been programmed and is fully useable. The full code (Source 02) and a working example are included in this article. In Source 02 the reader will find "buildMain_WioT_v01o01_2023EMay15_i" which can be changed into "prepIX_I.py". Source 02 was developed on a microSD card. Note that Source 02 uses "requests()" instead of "requires()". The latter should be used in the final version of prepIX_I.py. Some simple future modifications (enhancements) have been planned, but are not yet implemented. These enhancements are described earlier in "Upcoming Changes" and later in "Other Related Thoughts". The next 2 phases of prepIX are described in more detail in Article 209 and Article 210.

A Simple prepIX_I Example

A Proto-Build-Module Example

The following Proto-Build-Module is a fully formed runnable python program. But it lacks two functions that it calls: requires() and show(). Two requires statements appear as valid statements in the code segment below. They cause the necessary code to be included immediately after each respective "requires" statement. An erroneous "requires" statement also appears. It demonstrates how the error event is handled when a non-existent requires statement exists in the example. (Note that the "showY" is not defined in either of the folders that prepIX_I searches. The fact that the "requires()" statement might require a copy of itself does not cause a problem (but it must be required as the first "requires" statement). Note that any comment lines (beginning with a "#") are not copied into the resulting program that is built. This is in order to save source code space when the resulting code is uploaded to a core (computer) with a small amount of memory (such as the Wio Terminal).

The parameters following the function name in the requires statement are place-holders that will be necessary in a future version of prepIX.

The sequence of the statements is not very important, the "requires" statements should be near the top of the proto-build-module and most-definitely before the required functions are called.

The "show" function is normally used during debugging. It simple shows (prints) the current value of a variable preceded by the name of the variable. To "turn off" this printing by the "show" function, simply set "isShow" to False.

	print("main.py program")
	#main.pb     #proto file for main.py
	#By: D@CC
	#Date: 2023EMay17

	requires("requires(s,'v==00')")
	requires("show(s,s,s,'v==00')")
	requires("showY(s,s,'v==00')")

	print("main.py proto-build-module")
	isShow=True
	strName="D@CC"
	show("strName",strName,isShow)
	print("end of main.py")
	
Notice how "readable" the above routine is, without being encumbered by the all the statements comprising the functions that it calls.

Resulting Module Built From the Above Proto-Build-Module Example

The resulting module is shown below. Two sections of code have been automatically inserted by prepIX. They are the def requires and the def show modules. Notice that all full comment lines have been eliminated. Some separation lines have been included. Two final comment lines have been added at the bottom to indicate the name of the final module and the date/time stamp when it was built. This prepIX.py program was run using Thonny on the RPi.

	print("main.pb program")
	
	def requires(fcall,strMsg=""):
	    if not strMsg=="": print("ErrRequest:",fcall,": ",strMsg)
	    return strMsg
	
	#def end requires
	requires("requires(s,v)")
	############################################
	def show(objName,obj,isShow):
	
	    if not isShow: return
	    if not isinstance(objName,str):
	        print("Error S01 in show Name is not a str:",objname)
	    if isinstance(obj, str) or isinstance(obj,list) or isinstance(obj,int)or isinstance(obj,bool):
	        print(objName,":",obj,":")
	    else:
	        typeObj=type(obj)
	        print("Error S02 in show obj is not a str, list, int nor bool:",objName,"type:",typeObj,"value:",obj)
	        return
	
	#def end show
	requires("show(s,s,B,v)")
	############################################
	requires("showY(s,s,B,v)","does NOT exist.")
	############################################
	print("main.py proto file")
	isShow=True
	strName="D@CC"
	show("strName",strName,isShow)
	print("end of main.py  proto-build-module")
	#main.py (created by prepIX.py)
	#        on 2023-05-16 T 01:22:57
	

Results When this Program is Run

This program can be run by python by entering these commands into the RPi Terminal.

	>>>$ cd Desktop
	>>>$ python main.py
	
This will produce the following output:

	main.pb program
	ErrRequest: showY(s,s,B,v) : does NOT exist
	main.py proto file
	strName : D@CC :
	end of main.py  proto-build-module
	

Folder Contents For prepIX.py

All that is needed is the following:

	/home/pi/Desktop/
		prepIX_WioT_v01o03_2023EMay17.py
		main.pb
	/home/pi/Desktop/ix/
		requires.py
		show.py
	
The source code for the "prepIX_WioT_v01o03_2023EMay17.py" (which is a time-stamped version of the prepIX.py) program can be found in Source 02. (Note that it has recently been renamed from "buildIX".) It will be downloaded from Source 02 as a ".txt" file. To use it, simply rename its extension to ".py" As the name implies, I will be using the prepIX.py program on the RPi to prepare the main.py programs for the Wio Terminal. I plan to use the IXc command (with the Bourne Shell shown below) to make it easy to run the prepIX.py program from the RPi Terminal command line.

The IXc Command and the Bourne Shell

Within the Terminal program in a Raspberry Pi computer that is running Linux, the shell program (called the Bourne shell) is run by a command such as "sh program.sh parameters". The resulting file (as produced by IXc) can be run by using an initial character string of "sh" followed by the remainder of the (eg IXc) command. For more information about IXc, see Source 03.

An example of an IXc command with an "sh" file is:
   > $ IXc
   > ! -sh Environ_ix.sh?date=2022FJun21 DCole
Some files (other than python e.g. shells such as "sh"), when run, are followed by a parameter or parameter string. In the above case, the parameter is "DCole". This parameter is allowed in IXc, so that IXc will function correctly for such non-python programs. In the case of python, the parameter "DCole" will be ignored by the python program.

In IXc, entity names must begin with "&" contain at least 1 lowercase letter and end with "|". It is recommended that entity names be a lower case alphanumeric character string, often only one word long beginning with a lower-case letter of the alphabet. If the user prefers to include second or third words in an entity name, the first letter of each of these two words should be capitalized. Of course, spaces are not allowed within entity names. Entity names beginning with "ix_" are reserved by IX and should not be used by the programmer in his macro source files.

The IX Family of Software

The ultra-simple prepIX.py system works very well for me. I can use it to create the main.py programs for the Wio Terminal. Until I get a uSD card to work on the Wio Terminal, I will keep all the python source modules on the RPi, only transferring the main.py files (and minor data files) to the Wio Terminal.

Because prepIX.py will be automatically invoked by the IXc Macro Processor, very little will be described about running prepIX.py as a stand-alone python program. But it will always be runnable as a stand-alone program as well. It is my intention to fully implement the device() function. This device() function will tell the program what type of core (computer) is being used. This describes whether the program will be running on a "WioTerminal" or a Raspberry Pi ("RPi") or a Pico or a Tiny2040. Usually, any python program to be run on a WioTerminal will also run on a RPi for "final" testing prior to running it on the WioTerminal. IXc will finish by running any python program on the RPi, but the final module, regardless of its name, will be saved, so that it can be run elsewhere, such as on the WioTerminal.

A notice will be appear here when IXc has been modified to include the "prepIX.py" step. It has not yet been done, as of 2023KNov22.

An upcoming article will be devoted to the improved IXc Macro Processor that includes "prepIX.py". The improved IXc will, hopefully, move the IX system closer to being able to produce the ixmRPC system. As described in Article 195, the ixmRPC system will permit Remote Procedure Calls of devices such as the Tiny2040, the WioTerminal, the Cytron Maker Pi RP2040, the Cytron Maker Pi Pico, the Raspberry Pi Zero W and my MAK Pi ADC as described in my Article 165 (Source 04 ). Note that the Cytron Maker Pi Pico ( Article 183 ) is still available. A list of the modules in the IX family of software can be found in Source 06.

Much more is said about the IX Family of Software in Source 08.

Other Related Thoughts

1. Because the Wio Terminal can only run a single program (main.py), I plan to improvise a small number of programs as "improvised" functions. Then main.py can "call" these other programs, making main.py become a Remote Procedure Call handler. When I do this, I rename each program into a function by adjusting the last part of it's name to become "_i.py". A first version of IX_menu_i.py has been written and tested. It can be run (using python) as a simple menu. It can be found in Source 08. An early version of the program used to create the full "IX_menu_i.py" from "IX_list_i.py" has been written (see Source 02). It will be part of the full prepIX.py program (also described in Source 08) or the future IX.py program. The future prepIX.py can do all the work of "packaging" the programs and functions together.

2. Most of my useful programs will be comprised of a tiny main "stub", some generic functions (used by multiple programs) and some routines only used by one program. The tiny main stub simply calls the improvised function (that is the real program). I place the generic functions into the /home/pi/Desktop/ix/" folder and the single-program-use functions in the same folder as the program that calls them. Here again, the future prepIX.py program (or IX.py) will do all the work of "packaging" the programs and functions together.

3. Video Source 01 introduces the Tiny2040 (a variant of the Raspberry Pico). The prepIX system will permit the easy "packaging" of programs into the Tiny2040. This will be done in a similar manner as for the Wio Terminal.

4. A much bigger project is the creation of the ixRPC system. Combined with the prepIX.py program, the ixRPC system should make the tiny microProcessors (such as the Tiny2040 and the WioTerminal) much easier to use.

5. A future version of prepIX.py will include the IXc macro pre-processor functionality, as initially defined in my Article 183 (Source 03).

6. Source 07 describes a future version of the PiR2 controller, with an on-screen control panel (as opposed to CLI controls). This control panel would make use of a queue of AandC actions. The future IX queue (formerly FFQueue) should figure prominently in the future PiR2 control panel. Multiple PiR2 devices can communicate with the MehInCharge.com (MIC) website (see more information at Article 128).

Pi Shop in Ottawa

The full contact info for the Pi Shop in Ottawa is:
	HiPi Industries Inc.
	DBA PiShop.ca
	9-190 Colonnade Rd. S.
	Ottawa ON, K2E 7J5
	GST & HST# 796009322
	Monday-Friday 9am-5pm EST
	844-850-1100
	Email: support@pishop.ca
	

Sources

Video Sources

Video Source V196:01: First Look at the Tiny2040 (3:14 min) by Learn Embedded Systems c2021DApr


Web Sources

Web Source S196:01: US ASCII Chart 8-bit at charset.org/charsets/us-ascii on 2022FJun15
Web Source S196:02: buildMain_WioT_v01o01_2023EMay15_py.txt (aka prepIX.py) by D@CC on 2023EMay16
Web Source S196:03: IT: IX/IXc - A General Purpose Macro Processor (183.html) by D@CC on 2022FJun12
Web Source S196:04: Pi: MAK Pi ADC by ICH180RR (165.html) by D@CC on 2021 H Aug 07
Web Source S196:05: DBA Pi Shop 9-190 Colonnade Rd.S., Ottawa, K2E 7J5 by 844-850-1100 on 2023 E May 17
Web Source S196:06: IX Family of Software by D@CC on 2023 J Oct 11
Web Source S196:07: PiR2 CONTROLLER FUNCTIONALITY V8 by D@CC on 2020 D Apr 25
Web Source S196:08: IT: IX_menu_i and improvised programs (208.html) by D@CC on 2023 J Oct 26

/SourcesEnd

WebMaster: Ye Old King Cole

There is a way to "google" any of the part-numbers, words and phrases in all my articles. This "google" search limits itself ONLY to my articles. Just go to the top of "ePC Articles by Old King Cole" and look for the "search" input box named "freefind".

Click here to return to Articles by Old King Cole

Date Written: 2023 E May 16
Last Updated: 2024 C Mar 30

All rights reserved 2023 by © ICH180RR

saved in E:\E\2022\DevE\MyPagesE\Globat\ePhotoCaption.com\a\196\196.html

backed up to ePhotoCaption.com\a\196\196_2023EMay16.html
Font: Courier New 10 (monospaced)
/196.html