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

Fix setupext [backport to 1.4.x] #3510

Merged
merged 1 commit into from Sep 18, 2014
Merged

Conversation

blink1073
Copy link
Member

Cleanup for build process on win32. Detects libpng and freetype and raises an error if they are not found. Also adds convenience method get_include_dirs to capture a pattern that was used several times in setupext.py.

This addresses #3509.

@tacaswell tacaswell modified the milestones: v1.4.x, v1.4.1 Sep 13, 2014
@tacaswell
Copy link
Member

Also see #3503 which is merged on 1.4.x.

cc @jbmohler

@tacaswell tacaswell changed the title Fix setupext Fix setupext [backport to 1.4.x] Sep 13, 2014
@blink1073
Copy link
Member Author

My version actually does check for png.h, but would fail on Windows with Python 3 < 3.3.4 due to a lack of getstatusoutput. We can include the actual function inline instead of importing it:

def getstatusoutput(cmd):
    """Return (status, output) of executing cmd in a shell."""
    import os
    pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r')
    text = pipe.read()
    sts = pipe.close()
    if sts is None: sts = 0
    if text[-1:] == '\n': text = text[:-1]
    return sts, text

@blink1073
Copy link
Member Author

Or, we could just use a dummy if it is not available:

try:
    if sys.version_info[0] < 3:
        from commands import getstatusoutput
    else:
        from subprocess import getstatusoutput
except ImportError:
    def getstatusoutput(text):
        return 1, ''

@tacaswell
Copy link
Member

I have merged 1.4.x into master (which may have generated a conflict on the link correction which I think this is the third time it has been fixed).

@blink1073 @jbmohler Can you two reach a consensus on how to deal with this?

@blink1073
Copy link
Member Author

The latest reflects what I vote to do. It respects the INCLUDE environmental variable on all platforms, and provides a dummy getstatusoutput. Here is the build text:

$ python matplotlib-winbuild/buildall.py -p
Obtaining file:///c:/Users/silvester/workspace/matplotlib
  Running setup.py (path:c:/Users/silvester/workspace/matplotlib\setup.py) egg_info for package from file:///c:/Users/silvester/workspace/matplotlib
    ============================================================================
    Edit setup.cfg to change the build options

    BUILDING MATPLOTLIB
                matplotlib: yes [1.5.x]
                    python: yes [2.7.8 |Continuum Analytics, Inc.| (default, Jul
                            2 2014, 15:13:35) [MSC v.1500 32 bit (Intel)]]
                  platform: yes [win32]

    REQUIRED DEPENDENCIES AND EXTENSIONS
                     numpy: yes [version 1.8.2]
                       six: yes [using six version 1.7.3]
                  dateutil: yes [using dateutil version 1.5]
                   tornado: yes [using tornado version 4.0.1]
                 pyparsing: yes [using pyparsing version 2.0.1]
                     pycxx: yes [Couldn't import.  Using local copy.]
                    libagg: yes [pkg-config information for 'libagg' could not
                            be found. Using local copy.]
                  freetype: yes [version Failed to identify version.]
                       png: yes [pkg-config information for 'libpng' could not
                            be found. Using unknown version found on system.]
                     qhull: yes [pkg-config information for 'qhull' could not be
                            found. Using local copy.]

    OPTIONAL SUBPACKAGES
               sample_data: yes [installing]
                  toolkits: yes [installing]
                     tests: yes [using nose version 1.3.3 / using mock 1.0.1]
            toolkits_tests: yes [using nose version 1.3.3 / using mock 1.0.1]

    OPTIONAL BACKEND EXTENSIONS
                    macosx: no  [Mac OS-X only]
                    qt5agg: no  [PyQt5 not found]
                    qt4agg: yes [installing, Qt: 4.8.6, PyQt: 4.8.6]
                    pyside: no  [PySide not found]
                   gtk3agg: no  [Requires pygobject to be installed.]
                 gtk3cairo: no  [Requires cairocffi or pycairo to be installed.]
                    gtkagg: no  [Requires pygtk]
                     tkagg: yes [installing, version 81008]
                     wxagg: no  [requires wxPython]
                       gtk: no  [Requires pygtk]
                       agg: yes [installing]
                     cairo: no  [cairocffi or pycairo not found]
                 windowing: yes [installing, installing]

    OPTIONAL LATEX DEPENDENCIES
                    dvipng: no
               ghostscript: yes [version 9.09]
                     latex: no
                   pdftops: no

raise CheckFailed(
"pkg-config information for '%s' could not be found." %
package)
msg = "pkg-config information for '%s' could not be found."
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this fits in the spirit of what this function does. It is checking for pkg-config data and not if the header exists. The function which calls this has the responsibility of doing any additional checks (like looking for a header file if that is the correct behavior for the particular dependency).

@jbmohler
Copy link
Contributor

There was an issue building on windows, but #3503 fixes some of the same things on this PR and now I'm a little unsure what else this PR is addressing.

I have a couple of comments in general after reading this in some more detail:

  1. I agree with @cimarronm about the _check_for_pkg_config changes
  2. The special case for win32 in check_include_file should probably be pulled in to has_include_file
  3. After item 2 is addressed, then Png.check method's has_include_file call will probably succeed on windows
  4. Making a null version of getstatusoutput for win32 seems a little sneaky to me. I'd probably prefer explicit win32 branches in the check functions, but I can appreciate the economy and it is similar to sneakiness in PkgConfig

(BTW, getstatusoutput actually exists on windows, but it is known not to work -- I'd vote to call that a bug in the standard library.)

@blink1073
Copy link
Member Author

@cimarronm, does that look better?

@blink1073
Copy link
Member Author

@jbmohler, #3503 does not check for the existence of libpng, so the user would not find out until the build failed later on.

@blink1073
Copy link
Member Author

@jbmohler, I added an implementation of getstatusoutput for win32, which I tested separately.

@blink1073
Copy link
Member Author

@jbmohler, I'm back with you on the separate code path way. What do you think now?

@@ -1003,6 +1011,10 @@ class Png(SetupPackage):
name = "png"

def check(self):
if sys.platform == 'win32':
check_include_file(get_include_dirs(), 'png.h', 'png')
Copy link
Member

Choose a reason for hiding this comment

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

I merged all of the other branches up into master. This seems to have introduced a conflict here. Can you rebase this PR?

@blink1073
Copy link
Member Author

Rebased.

@tacaswell
Copy link
Member

not quite what I meant, but it seems to have worked.

@blink1073
Copy link
Member Author

Do you not use rebase -i upstream/master in matplotlib?

@tacaswell
Copy link
Member

Never mind, it looks right now. Either I was confused or gh was showing me strangely cached results.

@jbmohler
Copy link
Contributor

I like this PR -- it errors early now as appropriate & tests just fine on my win7 box. The commit message should more succintly say what it currently is.

A very minor grumble is that in Png.check (and Freetype.check), it seems that the check_include_file check and has_include_file check could become the same code. However, I can't see an easy way to get the equivalent flow with the conditionals and exceptions that is really any clearer than what you have.

@tacaswell
Copy link
Member

Great, unless there are protests I will merge this tomorrow.

Allow for getstatusoutput on win32 and use INCLUDE and LIB env vars

Back off on the use of the environmental variables

Pinpointed necessary location for INCLUDE

Fix link to matplotlib-winbuild

Normalize handling of library location finding

Include more paths in the search

Restore _check for_pkg_config behavior

Implement getstatusoutput on win32

Remove win32 getstatusoutput in favor of explicit check_include_file
@blink1073
Copy link
Member Author

I updated the commit message and PR description.

@cimarronm
Copy link
Contributor

LGTM 👍 good work to improve the build for windows

tacaswell added a commit that referenced this pull request Sep 18, 2014
BLD : improve setupext.py on windows
@tacaswell tacaswell merged commit 2c11590 into matplotlib:master Sep 18, 2014
tacaswell added a commit that referenced this pull request Sep 18, 2014
BLD : improve setupext.py on windows
@tacaswell
Copy link
Member

cherry-picked as d10e26e

@pelson
Copy link
Member

pelson commented Sep 23, 2014

LGTM 👍 good work to improve the build for windows

Indeed. @blink1073 - incidentally do you have any experience of appveyor? (e.g. https://github.com/sunpy/sunpy/blob/master/appveyor.yml)

@blink1073
Copy link
Member Author

@pelson, not personally, but we are looking to add it to scikit-image.

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

Successfully merging this pull request may close these issues.

None yet

6 participants