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

move extension into the package #578

Closed
wants to merge 1 commit into from

Conversation

mindw
Copy link
Contributor

@mindw mindw commented Feb 6, 2015

No description provided.

@mindw mindw force-pushed the move_extension_2_pkg branch 2 times, most recently from fed0781 to d3e7b18 Compare February 6, 2015 12:33
except ImportError:
from distutils.core import setup, Extension

from setuptools import setup, Extension
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this? AFAIK setuptools is a third-party dep which is not installed by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pip requires setuptools if installing from source. Wheels do not use the setup.py script. Both 'bootstrapped' in 2.7 & 3.4.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still support python 2.6.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm eager to do this only if a brand new Python installation (2.6 included) has setuptools installed.

@giampaolo
Copy link
Owner

Thanks for writing this. The changes you did against the import system broke some imports on Python 3 though:
https://travis-ci.org/giampaolo/psutil/jobs/49733189
Perhaps because you changed paths in setup.py?

@@ -134,6 +130,7 @@ def get_winver():

def main():
setup_args = dict(
zip_safe=False,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to this:
https://pythonhosted.org/setuptools/setuptools.html#setting-the-zip-safe-flag
...zip_safe=False seems to be unnecessary because if the package contains C extension files (as psutil) zip_safe is already implicitly set to False. Given that zip_safe is an option which exists only if setuptools is installed I think it makes sense to remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

@giampaolo
Copy link
Owner

Also, once you manage to fix the imports don't forget to update README.rst and CREDITS.rst (add your name).

@mindw
Copy link
Contributor Author

mindw commented Feb 6, 2015

I'm looking into the import failure on py 3.x.

@giampaolo
Copy link
Owner

Yes, the import failure is because of the different names in setup.py. For example, in __init__.py you'll have to do this:

-        import _psutil_linux
+        import psutil._psutil_linux

@mindw mindw force-pushed the move_extension_2_pkg branch 4 times, most recently from 9d52300 to b33ad4c Compare February 6, 2015 17:23
@mindw
Copy link
Contributor Author

mindw commented Feb 6, 2015

finally fixed the tests.

@mindw mindw force-pushed the move_extension_2_pkg branch from b33ad4c to 4307c28 Compare February 6, 2015 17:42
@mindw
Copy link
Contributor Author

mindw commented Feb 6, 2015

I dropped the setuptools stuff.

CONN_LISTEN,
CONN_CLOSING,
CONN_NONE
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't do this for now. I'll think about whether I'm OK with this later.

@giampaolo
Copy link
Owner

I made different commits today and this PR cannot be merged cleanly anymore.
I created a branch in here in which I merged my changes with yours:
https://github.com/giampaolo/psutil/tree/mindw-move_extension_2_pkg
Everything is fine if I run tests via "make test" but if I try to run them via "tox" I get import related errors (if you want to try yourself just "pip install tox" then run "tox" from the main psutil directory).
Now I remember why I didn't do this before: because I tried but I always got stuck with these kind of issues.
I've been struggling with this for hours now and I really don't know how to fix this problem. Do you have any idea?

~/svn/psutil {mindw-move_extension_2_pkg|MERGING}$ tox
GLOB sdist-make: /home/giampaolo/svn/psutil/setup.py
py26 inst-nodeps: /home/giampaolo/svn/psutil/.tox/dist/psutil-3.0.0.zip
py26 runtests: PYTHONHASHSEED='2581425950'
py26 runtests: commands[0] | py.test
============================================================================================= test session starts =============================================================================================
platform linux2 -- Python 2.6.9 -- py-1.4.26 -- pytest-2.6.4
collected 0 items / 2 errors 

=================================================================================================== ERRORS ====================================================================================================
_________________________________________________________________________________ ERROR collecting test/test_memory_leaks.py __________________________________________________________________________________
test/test_memory_leaks.py:20: in <module>
    import psutil
psutil/__init__.py:68: in <module>
    from . import _pslinux as _psplatform
psutil/_pslinux.py:26: in <module>
    from . import _psutil_linux as cext
E   ImportError: cannot import name _psutil_linux
____________________________________________________________________________________ ERROR collecting test/test_psutil.py _____________________________________________________________________________________
test/test_psutil.py:54: in <module>
    import psutil
psutil/__init__.py:68: in <module>
    from . import _pslinux as _psplatform
psutil/_pslinux.py:22: in <module>
    from . import _common
E   ImportError: cannot import name _common
=========================================================================================== 2 error in 0.33 seconds ===========================================================================================

For some reason the py modules can be imported, as in:

from . import _common

...but the C extension modules are not found:

from . import _psutil_linux

@giampaolo
Copy link
Owner

Note: travis tests pass so it seems to be a problem related with tox:
https://travis-ci.org/giampaolo/psutil/builds/49831656

@giampaolo
Copy link
Owner

OK, I solved the issue by adding "usedevelop = True" in the tox config file. I merged your PR as of
e5d0946
Thanks a lot.

@giampaolo giampaolo closed this Feb 7, 2015
@giampaolo
Copy link
Owner

Unfortunately I had to revert this change in 454b1ac because relative imports no longer works if I run the interactive interpreter from within psutil installation directory.

giampaolo added a commit that referenced this pull request Feb 9, 2015
giampaolo added a commit that referenced this pull request Feb 9, 2015
giampaolo added a commit that referenced this pull request Feb 9, 2015
@mindw
Copy link
Contributor Author

mindw commented Feb 9, 2015

Why on earth would you do that? Open an interactive interpreter a package and access the package?!

And even if you must have this why revert the module move? You could have reverted only the relative imports.

@giampaolo
Copy link
Owner

Well, when I work on psutil I have a shell open in psutil root directory so it's not rare I open up a python interpreter in order to try some stuff. I also sometimes executes scripts (import psutil) from within the root directory and the same issue occurs. I also reverted the changes in setup.py because the same problem applies.

landryb added a commit to landryb/psutil that referenced this pull request Apr 5, 2015
landryb added a commit to landryb/psutil that referenced this pull request Apr 5, 2015
@landryb landryb mentioned this pull request Apr 5, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants