umlet / pwk

Python With Kurly braces
94 stars 4 forks source link

Request: Setting up a Config file #5

Open JoaquimEsteves opened 3 years ago

JoaquimEsteves commented 3 years ago

Hello, I've been playing around with your package and I've loved I'm loving it so far!

I would, however, like to have an option in the cli to include a config file that would be expand the code's namespace.

Example:

# Config file ensures my path file exists and I can easily do something with it
# My aliases are also conveniently saved
pathlib import Path
P = print
if not (some_file := Path('./some_file')).exists():
    raise Exception("some_file doesn't exist!")
$ pwk '[P(line) for line in some_file.open().readlines())]' --config ./path/to/pwk_cfg.py

I'm currently working on this feature on my own fork; and would like to know if you'd be interested in a PR.

Why not edit pwk directly

This would allow me to have multiple config files for different projects, making it more convenient than hopping over to /usr/bin/pwk and editing the file directly or copy-pasting it everywhere.

What about name conflicts, won't this make it trickier to develop pwk itself?

We can pass the environment over to exec directly like so:

exec(python_cmd, {**globals, **vars_from_config})
umlet commented 3 years ago

thx for your feedack! yes, i'd like to extend to config file handling (also some defaults in home dir) and hope to get to it the coming months; no need for a PR, as i will be wteaking quite a bit.. and prob be slow to test/respond.. thx! m

On Thu, 10 Dec 2020 at 10:26, JoaquimEsteves notifications@github.com wrote:

Hello, I've been playing around with your package and I've loved I'm loving it so far!

I would, however, like to have an option in the cli to include a config file that would be expand the code's namespace.

Example:

Config file ensures my path file exists and I can easily do something with it# My aliases are also conveniently savedpathlib import PathP = printif not (some_file := Path('./some_file')).exists():

raise Exception('some_file doesn't exist!')

$ pwk '[P(line) for line in some_file.open().readlines())]' --config ./path/to/pwk_cfg.py

I'm currently working on this feature on my own fork; and would like to know if you'd be interested in a PR.

Why not edit pwk directly

This would allow me to have multiple config files for different projects, making it more convenient than hopping over to /usr/bin/pwk and editing the file directly or copy-pasting it everywhere.

What about name conflicts, won't this make it trickier to develop pwk itself?

We can pass the environment over to exec directly like so:

exec(python_cmd, {globals, vars_from_config})

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/umlet/pwk/issues/5, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACX4QLQ6LXAJVTSX77AW2JDSUCH37ANCNFSM4UUXMQLQ .