mirror of
https://github.com/servo/servo.git
synced 2025-07-19 13:23:46 +01:00
script: Use Pythonic file names for code generation and use functools.cache
(#38047)
Renames the files to pythonic file names. Also replaces the bespoke caching function with the functools caching function which is functionally equivalent. --------- Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
This commit is contained in:
parent
8a19bc9145
commit
ac2cfdb801
3 changed files with 6 additions and 26 deletions
|
@ -36,7 +36,7 @@ from WebIDL import (
|
|||
IDLWrapperType,
|
||||
)
|
||||
|
||||
from Configuration import (
|
||||
from configuration import (
|
||||
Configuration,
|
||||
Descriptor,
|
||||
DescriptorProvider,
|
||||
|
@ -265,27 +265,7 @@ def indent(s, indentLevel=2):
|
|||
return s
|
||||
return re.sub(lineStartDetector, indentLevel * " ", s)
|
||||
|
||||
|
||||
# dedent() and fill() are often called on the same string multiple
|
||||
# times. We want to memoize their return values so we don't keep
|
||||
# recomputing them all the time.
|
||||
def memoize(fn):
|
||||
"""
|
||||
Decorator to memoize a function of one argument. The cache just
|
||||
grows without bound.
|
||||
"""
|
||||
cache = {}
|
||||
|
||||
@functools.wraps(fn)
|
||||
def wrapper(arg):
|
||||
retval = cache.get(arg)
|
||||
if retval is None:
|
||||
retval = cache[arg] = fn(arg)
|
||||
return retval
|
||||
return wrapper
|
||||
|
||||
|
||||
@memoize
|
||||
@functools.cache
|
||||
def dedent(s):
|
||||
"""
|
||||
Remove all leading whitespace from s, and remove a blank line
|
||||
|
@ -301,7 +281,7 @@ def dedent(s):
|
|||
fill_multiline_substitution_re = re.compile(r"( *)\$\*{(\w+)}(\n)?")
|
||||
|
||||
|
||||
@memoize
|
||||
@functools.cache
|
||||
def compile_fill_template(template):
|
||||
"""
|
||||
Helper function for fill(). Given the template string passed to fill(),
|
|
@ -27,8 +27,8 @@ def main():
|
|||
config_file = "Bindings.conf"
|
||||
|
||||
import WebIDL
|
||||
from Configuration import Configuration
|
||||
from CodegenRust import CGBindingRoot, CGConcreteBindingRoot
|
||||
from configuration import Configuration
|
||||
from codegen import CGBindingRoot, CGConcreteBindingRoot
|
||||
|
||||
parser = WebIDL.Parser(make_dir(os.path.join(out_dir, "cache")))
|
||||
webidls = [name for name in os.listdir(webidls_dir) if name.endswith(".webidl")]
|
||||
|
@ -91,7 +91,7 @@ def make_dir(path):
|
|||
|
||||
|
||||
def generate(config, name, filename):
|
||||
from CodegenRust import GlobalGenRoots
|
||||
from codegen import GlobalGenRoots
|
||||
root = getattr(GlobalGenRoots, name)(config)
|
||||
code = root.define()
|
||||
with open(filename, "wb") as f:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue