openlabs / magento

Python API for Magento
Other
136 stars 82 forks source link

Python 3 support #23

Open giampaolo opened 10 years ago

giampaolo commented 10 years ago

This is currently missing. Any plan to migrate magento to Python 3?

$ pip3.4 install magento --user
Downloading/unpacking magento
  Using download cache from /home/giampaolo/.pip/cache/https%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2Fm%2Fmagento%2Fmagento-0.4.tar.gz
  Running setup.py (path:/tmp/pip_build_giampaolo/magento/setup.py) egg_info for package magento
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip_build_giampaolo/magento/setup.py", line 14, in <module>
        execfile(os.path.join('magento', 'version.py'))
    NameError: name 'execfile' is not defined
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/tmp/pip_build_giampaolo/magento/setup.py", line 14, in <module>

    execfile(os.path.join('magento', 'version.py'))

NameError: name 'execfile' is not defined

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_giampaolo/magento
Storing debug log for failure in /home/giampaolo/.pip/pip.log

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/3739583-python-3-support?utm_campaign=plugin&utm_content=tracker%2F490249&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F490249&utm_medium=issues&utm_source=github).
sharoonthomas commented 10 years ago

Not planning on doing immediately though its in the roadmap. We mostly use it for the tryton magento integration and when tryton moves to python 3 this module should too. However, happy to accept a PR if you would like to implement it :)

sharoonthomas commented 10 years ago

running 2to3 should fix most issues I guess

giampaolo commented 9 years ago

With the following patch I'm able to install magento on Python 3.4. It uses "suds-jurko" instead of "suds" as apparently "suds" has not been ported yet and "suds-jurko" is the only viable alternative so far.

diff --git a/magento/api.py b/magento/api.py
index dc7c085..bda6977 100644
--- a/magento/api.py
+++ b/magento/api.py
@@ -9,9 +9,14 @@
     :license: AGPLv3, see LICENSE for more details
 '''

+import sys
+
 PROTOCOLS = []
 try:
-    from xmlrpclib import ServerProxy
+    if sys.version_info <= (2, ):
+        from xmlrpclib import ServerProxy
+    else:
+        from xmlrpc.client import ServerProxy
 except ImportError:
     pass
 else:
diff --git a/setup.py b/setup.py
index 16a1c32..ba9a7cb 100644
--- a/setup.py
+++ b/setup.py
@@ -8,10 +8,11 @@
     :license: AGPLv3, see LICENSE for more details

 '''
+
 import os
 from setuptools import setup

-execfile(os.path.join('magento', 'version.py'))
+exec(open(os.path.join('magento', 'version.py')).read())

 setup(
     name = 'magento',
@@ -26,15 +27,17 @@ setup(
     zip_safe=False,
     platforms='any',
     install_requires=[
-        'suds>=0.3.9',
+        'suds-jurko',
     ],
     classifiers=[
         'Development Status :: 6 - Mature',
         'Environment :: Web Environment',
         'Intended Audience :: Developers',
-        'License :: OSI Approved :: GNU Affero General Public License v3', 
+        'License :: OSI Approved :: GNU Affero General Public License v3',
         'Operating System :: OS Independent',
         'Programming Language :: Python',
+        'Programming Language :: Python :: 2',
+        'Programming Language :: Python :: 3',
         'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
         'Topic :: Software Development :: Libraries :: Python Modules'
     ],
tomaszsmolarek commented 8 years ago

This patch seems to work perfectly. Any chance we could get this added to the repo? I'd like to be able to create a submodule out of your repo.

sharoonthomas commented 8 years ago

Can you send a patch to https://github.com/fulfilio/python-magento ? not maintained here anymore.