Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alias ctx.obj into ctx #18

Open
1 task done
ethanknox-palmetto opened this issue Nov 16, 2021 · 2 comments
Open
1 task done

alias ctx.obj into ctx #18

ethanknox-palmetto opened this issue Nov 16, 2021 · 2 comments
Labels
enhancement New feature or request (RFC) Request For Comment Input from others appreciated!

Comments

@ethanknox-palmetto
Copy link
Contributor

Context
While the interface is still young we could consider simplifying it for readability.
since this API is a core user interface for palm we probably want it as reads-like-english as possible.

Describe the solution you'd like
We could potentially capture the context at top level, then monkeypatch __getattribute__ to make obj the final lookup path.
so it would look something like this:

class PalmContext(Context):
    def __getattribute__(self, attr):
        try: 
            return Context.__getattribute__(self, attr)
        except Exception as parent_exception: 
            try:
                 return self.obj.__getattribute__(self.obj, attr)
            except:
                raise parent_exception

then the interface would be

def some_command(context):
    context.run_in_docker("thing")

Describe alternatives you've considered
it would be trivial to just alias ctx.obj in the template, and that might actually be better for reasons stated below.

Additional context
Naming collisions would suck here. this is the kind of magic that makes OOP great. It's also the kind of magic that makes functional programmers hate OOP if something goes wrong here.

Is there an existing feature request for this?

  • I have searched the existing issues
@ethanknox-palmetto ethanknox-palmetto added enhancement New feature or request (RFC) Request For Comment Input from others appreciated! labels Nov 16, 2021
@jakeberesford-palmetto
Copy link
Collaborator

I think we can achieve this with click.make_pass_decorator(Environment) - this documentation has an example: https://click.palletsprojects.com/en/8.0.x/complex/

@ethanknox-palmetto
Copy link
Contributor Author

This is going to get scooped into whatever we do for #40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request (RFC) Request For Comment Input from others appreciated!
Projects
None yet
Development

No branches or pull requests

2 participants