fabianvf / python-rake

MIT License
130 stars 35 forks source link

Update imports to work in both versions of python #19

Closed fabianvf closed 7 years ago

fabianvf commented 7 years ago

Also make functions snake_case to match rest of project, and to avoid name collision with the python files.

Closes #17

@justinkterry Before I go willy-nilly merging again, does this help you?

jkterry1 commented 7 years ago

@fabianvf forgive my ignorance, but how do I download the equivalent of the merged PR to fix it? I don't find it on google.

jkterry1 commented 7 years ago

(in the github web UI I mean)

fabianvf commented 7 years ago

Ah sorry, thought I'd responded to this. You should be able to do

pip install https://github.com/fabianvf/python-rake/archive/fix_imports.zip
jkterry1 commented 7 years ago

Thanks. Still broken:

station@Station:~/Documents$ sudo pip3 install https://github.com/fabianvf/python-rake/archive/fix_imports.zip
[sudo] password for station: 
The directory '/home/station/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/station/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting https://github.com/fabianvf/python-rake/archive/fix_imports.zip
  Downloading https://github.com/fabianvf/python-rake/archive/fix_imports.zip
     \ 20kB 24.9MB/s
Installing collected packages: python-rake
  Running setup.py install for python-rake ... done
Successfully installed python-rake-1.1.1
Cstation@Station:~/Documents$ ipython
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import RAKE

In [2]: RAKE.SmartStopList()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-82f4c6d727de> in <module>()
----> 1 RAKE.SmartStopList()

AttributeError: module 'RAKE' has no attribute 'SmartStopList'

In [3]: quit()
fabianvf commented 7 years ago

Yeah, I changed the functions to be snake_case instead, to match the rest of the file (and prevent conflict with the actual files as well, since they had the same name as the function, importing them into init.py was confusing to me). So you'll need to do

import RAKE
RAKE.smart_stop_list()

I can revert that if you'd like, it may make more sense to move the stoplists into a stoplists directory so they can be imported as stoplists.XStopList, which would fix the collision as well.

jkterry1 commented 7 years ago

Tried that on different computer (just because I'm at work):

justin@Justin:~$ sudo pip3 install https://github.com/fabianvf/python-rake/archive/fix_imports.zip
[sudo] password for justin: 
The directory '/home/justin/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/justin/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting https://github.com/fabianvf/python-rake/archive/fix_imports.zip
  Downloading https://github.com/fabianvf/python-rake/archive/fix_imports.zip
     \ 20kB 57.0MB/s
  Requirement already satisfied (use --upgrade to upgrade): python-rake==1.1.1 from https://github.com/fabianvf/python-rake/archive/fix_imports.zip in /usr/local/lib/python3.5/dist-packages
justin@Justin:~$ ipython
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import RAKE

In [2]: RAKE.smart_stop_list()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-7195b3b7f0a5> in <module>()
----> 1 RAKE.smart_stop_list()

AttributeError: module 'RAKE' has no attribute 'smart_stop_list'

Regarding snake case, if you could revert it to SmartStopList() and refactor it to prevent collisions with that I'd appreciate it. It differs from whats used inside but for something outward facing its cleaner and more pythonic.

fabianvf commented 7 years ago

Ah,

Requirement already satisfied (use --upgrade to upgrade): python-rake==1.1.1 from https://github.com/fabianvf/python-rake/archive/fix_imports.zip in /usr/local/lib/python3.5/dist-packages

Looks like you need to run it with upgrade for it to overwrite the old installation.

jkterry1 commented 7 years ago
justin@Justin:~/Documents$ sudo pip3 install https://github.com/fabianvf/python-rake/archive/fix_imports.zip -U
The directory '/home/justin/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/justin/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting https://github.com/fabianvf/python-rake/archive/fix_imports.zip
  Downloading https://github.com/fabianvf/python-rake/archive/fix_imports.zip
Installing collected packages: python-rake
  Found existing installation: python-rake 1.1.1
    Uninstalling python-rake-1.1.1:
      Successfully uninstalled python-rake-1.1.1
  Running setup.py install for python-rake ... done
Successfully installed python-rake-1.1.1
justin@Justin:~/Documents$ ipython
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import RAKE

In [2]: RAKE.smart_stop_list()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-7195b3b7f0a5> in <module>()
----> 1 RAKE.smart_stop_list()

AttributeError: module 'RAKE' has no attribute 'smart_stop_list'

Why not just refactor it like I talked about, push it to the main so it's in pip like normal and we'll go from there?