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

Load dynamically a composer dependency #146

Open
Taluu opened this issue Feb 2, 2015 · 18 comments
Open

Load dynamically a composer dependency #146

Taluu opened this issue Feb 2, 2015 · 18 comments

Comments

@Taluu
Copy link
Contributor

Taluu commented Feb 2, 2015

Hi,

I was wondering if psysh could load on demand (and only for the current session) a composer dependency. For example (my last and freshest use case), I need to play around with Symfony's PropertyAccess component to make some tests.

Rather than setting up a blank project with this requirement (and go back to good old php -r or a test script), it would be a killer feature to have a command like import package/name, and be able to play around with whatever was imported, limited to the current session : once the session is killed, the dependency would also be killed (maybe work on a /tmp directory ?)

I know this is huge though...

@bobthecow
Copy link
Owner

That sounds like an awesome idea for a command. I probably wouldn't make it import since that doesn't do a good job of conveying that "this will go on the internet, download and install a package, and include it in your current psysh session", but something like that would be rad :)

@Taluu
Copy link
Contributor Author

Taluu commented Feb 10, 2015

How about autoload then ? Or even composer (let's be crazy :D), as its name should imply the "go on the internet, download the package, include it in the current session"...

@bobthecow
Copy link
Owner

I like the idea of having composer in the name. Could also use packagist in the name since that's what it's using.

Maybe composer-require foo/bar @stable?

@Markcial
Copy link
Contributor

Cool!! i like that too, i made a little experiment and it succeeded!
screenshot from 2015-02-16 18 59 19

I will open a PR tomorrow and post the code, i will need to test how it works without composer installed and install if it is missing.

@bobthecow
Copy link
Owner

Awesome!

@Markcial
Copy link
Contributor

Current development of this issue here #152

@castarco
Copy link
Contributor

castarco commented Apr 9, 2015

Hello, what's the current state of this feature? ^^U

@Markcial
Copy link
Contributor

The PR related to this feature is ready, @bobthecow decides when to ship it, in the meanwhile feel free to review the PR here => #152

@castarco
Copy link
Contributor

As far as I can see, the code looks nice (I don't know how PsySH works internally).
I think it needs adding specific tests, since this is a relatively complex feature, and I couldn't find new tests in the PR.

I understand the commands purpose, but if I obtain more info about where will be created the sandbox directories I can try to add those tests.

I'm very interested in this feature because if it's combined with #121 , then it's possible to obtain something similar to the iPython Notebook , but with PHP (and probably more modular and flexible, but with less features).

@Markcial
Copy link
Contributor

The #121 is still in a very premature state and it depends on a separate thread with a psysh server that has a execute method that runs some code and evaluates in return preserving the context, I was trying to use as few libraries as possible so the vendor folder doesn't gets all bluffed, anyways i will post the code i have until the moment.

About the current issue, the libraries are created inside the temporary folder of each system, a call made by the sys_get_temp_dir function. If you write some tests would be very nice from you, I made the PR in a hurry without testing i am sorry about that.

Anyways there is a little pending point i have to fix yet, the composer command still needs to have the composer file path, that might be a optional parameter in the configuration that if it is missing, then it must download the composer and BTW it will also need docs that will help the psysh user to not avoid this point if he already has composer installed. For that last step let me find some time to fix that.

And finally one thing that i am not 100% sure about this PR, maybe this PR will ship as a separated plugin, there is a work in progress for that, all that information about this is here => #166

@bobthecow
Copy link
Owner

@Markcial if we ship this one as a separate plugin, it could actually add composer as a dependency for that plugin, right?

@Markcial
Copy link
Contributor

Yes, it can be added as a dependency, downloaded as a phar file, or added via config parameter set by the plugin, whatever causes less trouble.

@Taluu
Copy link
Contributor Author

Taluu commented Apr 14, 2015

Or even use Symfony's process component. :D

@Markcial
Copy link
Contributor

LOL, that is true too :D

@bobthecow
Copy link
Owner

True :)

@GrahamCampbell
Copy link
Contributor

I don't really like this idea tbh, sorry.

@Taluu
Copy link
Contributor Author

Taluu commented Jun 15, 2018

Refreshing a bit this issue, how about using https://github.com/sensiolabs/melody as an inspiration (not a direct dependency; we could even use that if it's installed) ?

@castarco
Copy link
Contributor

castarco commented Jun 16, 2018

@Taluu I was working on this problem on a related project ( https://github.com/Litipk/Jupyter-PHP ) , I didn't push my code to the remote repository because it was completely experimental (and because my laptop was stolen with a ton of work 😢 ), but I can tell that I experimented two major problems:

  1. Composer is not modular at all, it's very difficult to use its code (in a clean way) for non-CLI
    applications. It seems that they love super-tight coupling 💩 . I did it, but I'm not proud of the results...
  2. The auto-generated class used from Composer to handler the autoloading process works as a
    damn singleton, and this makes reusing Composer's autoloading code something in between
    of impossible and useless.

I know that the context should be provided before, but I'll provide the context now: I was interested on dealing with composer dependencies through Jupyter-PHP commands to make easier creating super-portable PHP "notebooks" (we have a single file per notebook, so we need alternative ways to declare dependencies).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants