textual icon indicating copy to clipboard operation
textual copied to clipboard

Config file plan

Open willmcgugan opened this issue 3 years ago • 4 comments

We need a config file to be read by Textual that contains settings, key bindings etc.

YAML, or maybe TOML.

It should be flexible enough that third party packages should be able to read from it.

Discuss with @willmcgugan re requirements, and come up with a proposal before working on this.

willmcgugan avatar Jun 14 '22 09:06 willmcgugan

Is this for end users or developers of Textual apps, or both?

darrenburns avatar Jun 14 '22 10:06 darrenburns

Mainly developers, but potentially also exposed to users.

willmcgugan avatar Jun 14 '22 10:06 willmcgugan

My vote is for TOML as I personally find it significantly easier to read and write. Considering pyproject.toml is standard now, TOML support is being added to the Python stdlib in 3.11 (based on @hukkin great package https://github.com/hukkin/tomli), and TOML data structures look similar to Python, it's a format that Python developers are likely to be both familiar and comfortable with.

Every time I write YAML I don't feel certain it's correct, and past experience makes me suspect I'm not alone in this :)

darrenburns avatar Jun 14 '22 15:06 darrenburns

Since we're targetting people who are already writing Python code, I wonder if Starlark, the Python sandboxed dialect created by Google for their Bazel build tool, couldn't be a good choice?

Starlark is a language intended for use as a configuration language. It was designed for the Bazel build system, but may be useful for other projects as well. Starlark is a dialect of Python.

Design Principles

  • Deterministic evaluation. Executing the same code twice will give the same results.
  • Hermetic execution. Execution cannot access the file system, network, system clock. It is safe to execute untrusted code.
  • Parallel evaluation. Modules can be loaded in parallel. To guarantee a thread-safe execution, shared data becomes immutable.
  • Simplicity. We try to limit the number of concepts needed to understand the code. Users should be able to quickly read and write code, even if they are not expert. The language should avoid pitfalls as much as possible.
  • Focus on tooling. We recognize that the source code will be read, analyzed, modified, by both humans and tools.
  • Python-like. Python is a widely used language. Keeping the language similar to Python can reduce the learning curve and make the semantics more obvious to users.

I couldn't find an implementation of Starlark in pure Python (the 3 main implementations are in Go, Java and Rust), but there is a Python extension that wraps the Go version: https://python-starlark-go.readthedocs.io/en/latest/index.html

from starlark_go import Starlark

s = Starlark()
fibonacci = """
def fibonacci(n=10):
   res = list(range(n))
   for i in res[2:]:
       res[i] = res[i-2] + res[i-1]
   return res
"""
s.exec(fibonacci)
s.eval("fibonacci(5)")  # [0, 1, 1, 2, 3]

s.set(x=5)
s.eval("x") # 5
s.eval("fibonacci(x)")  # [0, 1, 1, 2, 3]

olivierphi avatar Jun 17 '22 09:06 olivierphi

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

github-actions[bot] avatar Dec 15 '22 11:12 github-actions[bot]