Necessary Libraries
A major design goal for Pedal was to limit third-party libraries. Unfortunately, we are still dependent on some libraries in the Standard Library. Although that may not sound like a restriction, we are often interested in running Pedal in non-Cpython versions of Python, such as Skulpt and MicroPython. This page attempts to document the libraries we depend on, and why they are necessary. Where possible, we talk about workarounds.
Critical Standard Libraries
sysmodulesto do monkey patching madness.exc_infofor exception stuffsettraceandgettracefor tracingstdoutfor tracing rerouting
exc_infofor exception stuff
pedal.utilitiesstdoutfor exceptionsversion_infofor checking current system version
ospedal.sandboxandpedal.utilitiespathis used for a few things
dataclassespedal.assertions,pedal.types,pedal.utilitiesfieldsand_FIELDSare used to inspect dataclass objects (should be try/catched!)
functoolspedal.assertions.organizerswrapsis used out of convenience and for clarity, I think?
repedal.assertions,:py:mod:pedal.cait,pedal.sandbox,pedal.source,pedal.utilitiessearch,compile,split,MULTILINE,subare all necessary.
astpedal.assertions,pedal.cait,pedal.source,pedal.tifa,pedal.types,pedal.utilitiesparse, but also like almost every single other class descending fromAsttoo. Oh, andNodeVisitoranditer_fieldstoo.
typespedal.cait,pedal.sandbox,pedal.typesMethodTypefor dynamically creating methods (I wonder if this could be changed?)ModuleTypefor dynamically creating modules
ioStringIOis necessary for handling mocked files, and capturing stdout
unittestpatchis necessary for more sophisticated patching used in the Sandbox and the Tracer
tracebackpedal.utilities.exceptionTracebackExceptionandextract_tbare used to capture the full traceback info and reshape it.
timepedal.sandbox.timeouttimeis used to get the current time for calculating the timeout
mathpedal.sandbox.resulttruncateneeds to be imported and used in order to properly emulate it
itertoolszip_longestis used as a convenience
threadingThreadand_activeare used to handle threading student code (which is usually necessary for properly handling timeouts)
ctypespedal.sandbox.timeoutpythonapi,c_long, andpy_objectare used inside of threading the timeout stuff. I have no idea since that code is mostly stolen.
bdbpedal.sandbox.tracerBdbandBdbQuitare useful for tracing student code, but not critical.
hashlibdepends on the
md5function to translate users/questions into a replicable seed for consistent “random” question pools
stringpedal.utilities.comparisonspunctuationis used in the string comparison function (could be hardcoded)
numberspedal.utilities.comparisonsNumberis used somehow?
Non-Critical Standard Libraries
Most of the Environments require some various libraries (e.g., the Jupyter environment absolutely depends on
nbformat).
-
pedal.command_lineUses
version_info,stdoutpedal.environmentsUses
stderr,exc_info,argv sqlite3pickle
Optional Third Party Libraries
These allow us to do some convenient things, but we don’t need them.
coverage- does some fancier tracing I believe?tabulatetqdm
Compatiblity
Here is an attempt at figuring out compatibility with some popular CPython alternatives.
Skulpt
We support Skulpt via our own fork. Everything in Pedal works in our version of Skulpt because otherwise we couldn’t do BlockPy.
MicroPython
These libraries seem to be sufficiently supported:
re(although might need a specific MicroPython port?)iotimetruncate(although it might betrunc? Need to investigate)hashlib
These libraries might be a problem:
sys
sys.stdoutis available
sys.modulesis available, but might be missing “builting modules” (does that matter?)
sys.settraceis available, through a customized build! But what aboutsys.gettrace? Doesn’t seem to be implemented, but there might be workarounds…
sys.version_infois available, though might be slightly different?
sys.exc_infomay NOT be available? Need to investigate, since that’s a big deal breaker, I’m pretty sure.
os
pathmay NOT be available. Might be able to handle that other ways though?
threading
there is a
_threadlibrary with experimental support, so that might be sufficient?
ctypes
Since this is only used for timeout code, it might be related to what we need to do for
threading
These libraries are NOT available, and that’s a deal-breaker until they are added:
ast(entire thing seems to be missing)types(actually, I think its in the source code)unittest(key feature is missing)traceback(key features are missing)
These libraries are not available, but I suspect that we can work around:
dataclasses(really not necessary unless you want students using dataclasses, which they can’t!)functools(it’s in the source code…)itertoolsbdbstring(it’s in the source code…)numbers
The following features are CRITICAL to Pedal:
Overriding sys.stdin, sys.stdout and sys.stderr not possible (well that’s a deciding factor right there)
The following features would be DIFFICULT/PAINFUL to rewrite in Pedal:
f-strings don’t support the !r, !s, and !a conversions
Method Resolution Order (MRO) is not compliant with CPython
When inheriting from multiple classes super() only calls one class
User-defined attributes for functions are not supported (this one would be INCREDIBLY painful to rewrite)
The following features were convenient in Pedal, and could be avoided:
f-strings don’t support concatenation with adjacent literals if the adjacent literals contain braces or are f-strings
f-strings cannot support expressions that require parsing to resolve unbalanced nested braces and brackets
Raw f-strings are not supported
Failed to load modules are still registered as loaded
I am unclear if these will matter:
Calling super() getter property in subclass will return a property object, not the value
Error messages for methods may display unexpected argument counts
Context manager __exit__() not called in a generator which does not run to completion
User-defined attributes for builtin exceptions are not supported
Attributes/subscr not implemented for
strSubscript with step != 1 is not yet implemented¶