Releases: mishamsk/pyoak
Release list
v1.2.0
This mainly a backport of enhanced XPath & Pattern Matcher from 2.0.0, but also makes serialization dependencies options as well as removes the ability of TextFileSources to guess file encoding (and chardet dependency with it).
This release was entirely contributed by @dmmoeu. Thanks a lot!
🚀 Added
- ASTNode
findandfindallAPI's (backport from v2). See README for details.
✨ Changed
- pyyaml, orjson, msgpack are now optional dependencies. They can be installed via a new set of extras: msgpack, orjson, yaml or all. E.g.:
pip install pyoak[msgpack].DataClassSerializeMixinand henceASTNodewill haveto/from_yamlandto/from_msgpackmethods if the corresponding dependencies are installed.to/from_jsonmethods are always available and usejsoniforjsonis not installed.
⚠️ Breaking
- Pattern Grammar is now the same as v2 series. This is a breaking change, check out the README for details.
TextFileSourceno longer guesses file encoding. This is a breaking change, but it's a good thing. If you need to read a file with a specific encoding, read it yourself and pass the content as a string to theTextFileSourceconstructor's_rawattribute.
🐛 Fixed
- A couple of bugs in v2 pattern matcher were fixed in this release.
v2.1.0
A quick iteration on the 2.0.0 release to ensure consistency of the API's naming and future support for slotted classes.
⚠️ Breaking
- Unify Tree API's to start with
get_oris_
🐛 Fixed
- Workarounds for a couple stdlib slotted dataclasses bugs to support slotted ASTNodes (still contingent on Mashumaro update)
🛠️ Internal
- ⬇️ relaxed library dependency for Mashumaro
- ⬆️ dev deps
- Switch black pre-commit hook to new mirror repo
v2.0.0
This is a significant rework, that brings most of the features previously on the roadmap, but also introduces major breaking changes. To avoid disruption, the v1 code has been moved to legacy sub-package and the legacy ASTNode is now called AwareASTNode. Legacy package will emit deprecation warnings on import though.
✨ Highlights
- Ability to re-use nodes across multiple ASTs without creating duplicates
- Nodes are now hashable!
- 100x faster pattern matching with support for pattern variables & simplified grammar
- ~50% faster traversal
- XPath search APIs (not unlike those in ElementTree)
- Opt-in runtime type checking of AST nodes
- ... and more
🚀 Added
pyoak.tree.Treeclass that provides API for to retrieve node parents in a tree as well as traversing "up" the treepyoak.configmodule that provides global configuration options- Opt-in runtime type checking at node creation via
pyoak.config.RUNTIME_TYPE_CHECKflag - XPath
ASTXpath.findalland sisterASTNode.findall,ASTNode.findmethods. Work similarly to ElementTree'sfindallandfindmethods. The latter accept both a compiledASTXpathinstnace or string.
- Pattern Matching
- Ability to match against multiple types:
(Type1|Type2|... ...) - Pattern variables:
(* @field_val_from -> val @field_compare_to = $val)
- Ability to match against multiple types:
✨ Changed
- Traversal methods
dfs,bfsandgatherdo not return the node itself anymore ASTVisitorandASTTransformVisitorare now in a separate modulepyoak.visitor- Auto-generated ID hash size is now configurable via
config.ID_DIGEST_SIZE, and defaults to 8 bytes (16 hex chars) - Optional trace logging switch is now in
configmodule ASTNode._iter_child_fieldspropoted to a public APIASTNode.iter_child_fields
⚠️ Breaking
- Traversal methods
dfs,bfsandgatherreturn a tuple of(node, parent, field, index)instead of just the node - All methods of
ASTNodethat worked by going "up" the tree are now inTreeclass - Filters & pruners for traversal methods now must accept a tuple of
(node, parent, field, index)instead of just the node - Mixed fields (i.e. with types like
str | ASTNode) are not allowed anymore. Separate properties and children into separate fields instead. - Pattern Match grammar has been simplified:
- any field rule is denoted just by
@field_name=...instead of@[child_field=...] #[property=...]syntax. - there are no more
!and!!flags, since sequence matching is now always "strict" (i.e.@field_name=[]matches only if the field is a sequence and elements match the pattern exactly)
- any field rule is denoted just by
🐛 Fixed
- CI/CD pipeline now correctly runs tests on all platforms
- Local docformatter now uses the same parameters as the one in CI/CD pipeline
🔥 Removed
- Runtime checks during traversal/retrieving children. All the decisions whether a field is a child field and/or is a sequence are made based type annotations at class creation
- Removed the ability to provide custom
idtoASTNodeconstructor. If you need to track source/natural ID's, use a dedicated field for that. id_collision_withandoriginal_idauto-properties. Now if you need to track collisions, this must be done manually.parent,parent_fieldandparent_indexauto-properties. Nodes are not aware of the parent anymore. UseTreeAPI instead.ensure_unique_idandcreate_detachedremoved as they are no longer neededreplacemethod. Use the type-checked (as of mypy 1.5+)dataclasses.replaceinstead.replace_withmethod, since node's are not parent aware anymore. UseASTTransformVisitorinstead.xpathproperty andcalcualte_xpathmethod. UseTreeinstead.detached,is_attached_rootandis_attached_subtreeproperties. No longer relevant.
📖 Documentation
- Updated README
🛠️ Internal
- Prepare to support slotted classes (contingent on Mashumaro update)
v1.1.1
Quick hotfix release to restore backwards compatibility with 1.0.0
🐛 Fixed
- 1.1.0 wouldn't deserialize NoSource/NoPosition/NoOrigin serialized by an earlier version of the library. This is now fixed and the lib should be fully backwards compatible.
v1.1.0
🚀 Added
- Instantiated singleton constants NO_ORIGIN, NO_SOURCE, NO_POSITION in
pyoak.origin
✨ Changed
- Removes unnecessary need to pass deserialization option to distinguish whether Sources were serialized as normal or as registry id's
- Serializes NoXXX classes as empty dicts now
⚠️ Breaking
- NoSource singleton instance is not part of the Source registry anymore and reports source_registry_id as -1. However it is still returned via
Source.list_registered_sources()API for backwards compatibility.
🛠️ Internal
- ⬇️ relaxed library dependencies
v1.0.0
This is the first public release of pyoak, a library I've been working on for the last year. It was conceived for the benefit of the commercial static code analysis & transpiler tool at my startup, but should be useful for a wide range or cases.