darikg / PgcliSublime

A Sublime Text 3 plugin supporting smart autocompletion for postgresql via pgcli
MIT License
8 stars 4 forks source link

Handling dependencies #12

Open klonuo opened 8 years ago

klonuo commented 8 years ago

pgcli running in Python 3.3. (This is the version of python shipped with Sublime Text 3). I recommend installing pgcli in a virtual environment.

Can you please elaborate how to use virtual environment in ST to meet requirements?

Assuming this would require installation of outdated Python 3.3, would you consider adding dependencies to your package, so that every single user doesn't have to?

Thanks

darikg commented 8 years ago

I fully admit it's a huge pain. The unfortunate reason it's necessary is that PgcliSublime depends on pgcli which in turn depends on psycopg2 to interact with postgresql. Sublime text ships with its own specific version of python (3.3), so in order to run pgcli inside of sublime text we need a specific version of psycopg2. Psycopg2 is a non-trivial binary dependency with a bunch of its own system dependencies and there's basically no way I could reliably package it. Ultimately the best way to go would be to split up pgcli into a server/client model so the pgcli server could run on a different version of python from the text editor client, but that's a huge amount of development work that isn't going to happen anytime soon.

So with all that said let me know what operating system you're using and I can try to help you set up a virtual environment

klonuo commented 8 years ago

@darikg ok, thanks for your reply.

In the meantime I temporary installed Python 3.3 and created venv then pip installed pgcli. I copied pgcli and dependency modules, namely:

click\
pgcli\
pgspecial\
prompt_toolkit\
psycopg2\
pygments\
sqlparse\
wcwidth\

to ../Sublime Text/Data/Packages/pgcli/st3_windows_x64 and pointed pgclisublime to the location. Works nice.

So I have dependencies for 64 bit Windows, and if you wish to make a new repo for these (to cover your package) I can make PR for st3_windows_x64. If you can make this for Linux and/or OSX and PR to package control channel, then that would cover large base or users that wont need to install these dependencies manually.

darikg commented 8 years ago

Wow so pip actually installed psycopg2 for you? That's never worked for me on windows. I'm actually not sure what to do here. I'm pretty skeptical that this will work reliably and I don't have a lot of different machine configurations to test it on, or the time to do so. On the other hand I totally agree it would be nice to make the installation a lot easier for most people.

klonuo commented 8 years ago

:) Ok, np

Yep, psycopg2 in pypi for Python 3.3 comes as a wheel (with precompiled library)

darikg commented 8 years ago

Yup you're right, I just tried it and it installed painlessly. I'm wondering if instead of trying to package dependencies we just had a basic shell script that created a venv and installed via pip/conda

klonuo commented 8 years ago

Hm, I don't know about shell script. That would probably assume that user already has Python 3.3 installed or...?

I was thinking more about using ST dependency feature. I don't know if you have experience with that, but I'll try again:

  1. You create a repo for dependencies. Here is example for lxml (https://github.com/eerohele/sublime-lxml)
  2. You make PR from dependencies repo to package control channel
  3. You add dependencies.json in this repo (PgcliSublime), i.e.:
{
    "*": {
        "*": [
            "pgcli"
        ]
    }
}

So I can push right now st3_windows_x64, and you or others can contribute for other platforms.

darikg commented 8 years ago

I'm coming around on this idea. I'm going to try to come back to it in the next couple weeks when I have some time to play around with it. Thanks for the links.

heme commented 8 years ago

I believe i'm trouble shooting similar config issues on OSX. Let me know if you'd like me to test anything. Python 2.7.10 install on my machine.

Console output:

...
plugins loaded
SublimeLinter: debug mode: off 
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 162, in on_api_ready
    m.plugin_loaded()
  File "pgcli_sublime in /Users/user/Library/Application Support/Sublime Text 3/Installed Packages/PgcliSublime.sublime-package", line 51, in plugin_loaded
ImportError: No module named 'pgcli'
GhostText is starting now…
Setting on request handler
HTTP Start
Package Control: Skipping automatic upgrade, last run at 2016-07-07 06:38:38, next run at 2016-07-07 07:38:38 or after
pgcli_sublime: ERROR: Error connecting to pgcli
pgcli_sublime: ERROR: traceback: Traceback (most recent call last):
  File "pgcli_sublime in /Users/user/Library/Application Support/Sublime Text 3/Installed Packages/PgcliSublime.sublime-package", line 384, in check_pgcli
  File "pgcli_sublime in /Users/user/Library/Application Support/Sublime Text 3/Installed Packages/PgcliSublime.sublime-package", line 450, in new_executor
NameError: global name 'PGExecute' is not defined

Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 574, in run_
    return self.run(edit)
  File "command_goto_file in /Users/user/Library/Application Support/Sublime Text 3/Installed Packages/FuzzyFilePath.sublime-package", line 17, in run
  File "./python3.3/posixpath.py", line 151, in dirname
AttributeError: 'NoneType' object has no attribute 'rfind'
rornor commented 7 years ago

Any news on this? Installing Python 3.3 just to make it work seems like overkill to me :(

shcherbak commented 6 years ago

I have similar issue on linux, sublime3 build 3143:

1) install PgcliSublime via Package Control 2) next go to console and set up virtualenv: cd ~/usr/ virtualenv-3.6 pgcli cd pgcli source ./bin/activate pip install pgcli 3) have virtualenv installed: pip freeze backports.csv==1.0.5 cli-helpers==0.2.3 click==6.7 configobj==5.0.6 humanize==0.5.1 pgcli==1.8.1 pgspecial==1.9.0 prompt-toolkit==1.0.15 psycopg2==2.7.3.2 Pygments==2.2.0 setproctitle==1.1.10 six==1.11.0 sqlparse==0.2.4 terminaltables==3.1.0 wcwidth==0.1.7

4) config settings: { "pgcli_autocomplete": true, "pgcli_dirs": ["\~/usr/pgcli/bin/"], "pgcli_site_dirs": ["\~/usr/pgcli/lib/python3.6/site-packages/"], "pgcli_url": "postgresql://postgres@localhost/test", "pgcli_urls": [], "pgcli_save_on_run_query_mode": "success", "pgcli_system_cmd": "\~/usr/pgcli/bin/pgcli {url}", "pgcli_sublime_log_level": "WARNING", "pgcli_log_level": "WARNING", "pgcli_console_log_level": "WARNING" }

5) try to conect: Traceback (most recent call last): File "/opt/sublime_text/sublime_plugin.py", line 210, in on_api_ready m.plugin_loaded() File "pgcli_sublime in /home/USER/.config/sublime-text-3/Installed Packages/PgcliSublime.sublime-package", line 51, in plugin_loaded ImportError: No module named 'pgcli' pgcli_sublime: ERROR: Error connecting to pgcli pgcli_sublime: ERROR: traceback: Traceback (most recent call last): File "pgcli_sublime in /home/USER/.config/sublime-text-3/Installed Packages/PgcliSublime.sublime-package", line 384, in check_pgcli File "pgcli_sublime in /home/USER/.config/sublime-text-3/Installed Packages/PgcliSublime.sublime-package", line 450, in new_executor NameError: global name 'PGExecute' is not defined