Skip to content

Flask import breaks on OSX #17

Closed
Closed
@mattmoor

Description

@mattmoor

You can see it in the Bazel CI job here

Activity

mattmoor

mattmoor commented on Sep 22, 2017

@mattmoor
ContributorAuthor

It looks like this starts working once pip is installed on the system.

mattmoor

mattmoor commented on Sep 22, 2017

@mattmoor
ContributorAuthor

Ok, I think I understand the error now, but not sure how to fix.

Normal installation of the wheel package installs a Python command for bdist_wheel. Wheel construction seems to rely on the capacity to shell out to:

/usr/bin/python -u -c "..." bdist_wheel -d ...

However, because we don't have pip or wheel installed on the system, this assumption is bad.

I'm not sure how this would work in a virtualenv for instance, but perhaps we could make the context of a {par,py}_binary look like a virtualenv to subprocesses and somehow communicate this kind of tool installation from the whl_library to the py_binary (through py_library hops)?

@duggelz I'd appreciate your thoughts on this (no rush).

mattmoor

mattmoor commented on Oct 11, 2017

@mattmoor
ContributorAuthor

@duggelz if you are around, I'd appreciate any thoughts you might have in this space.

mattmoor

mattmoor commented on Oct 12, 2017

@mattmoor
ContributorAuthor

Here's where this is configured in setup.py: https://github.com/pypa/wheel/blob/master/setup.py#L54

mattmoor

mattmoor commented on Oct 12, 2017

@mattmoor
ContributorAuthor

The wheel's .whl has the following in metadata.json:

    "extensions": {
        "python.commands": {
            "wrap_console": {
                "wheel": "wheel.tool:main"
            }
        },
        "python.details": {
            "contacts": [
                {
                    "email": "dholth@fastmail.fm",
                    "name": "Daniel Holth",
                    "role": "author"
                }
            ],
            "document_names": {
                "description": "DESCRIPTION.rst",
                "license": "LICENSE.txt"
            },
            "project_urls": {
                "Home": "https://bitbucket.org/pypa/wheel/"
            }
        },
        "python.exports": {
            "console_scripts": {
                "wheel": "wheel.tool:main"
            },
            "distutils.commands": {
                "bdist_wheel": "wheel.bdist_wheel:bdist_wheel"
            }
        }
    },
mattmoor

mattmoor commented on Oct 12, 2017

@mattmoor
ContributorAuthor

Watching this crazy video on how virtualenv works... :)

mattmoor

mattmoor commented on Oct 12, 2017

@mattmoor
ContributorAuthor

I think this comes down to:

from pkg_resources import iter_entry_points
for entry_point in iter_entry_points(group='distutils.commands', name=None):
    print(entry_point)

Which should show:

...
bdist_wheel = wheel.bdist_wheel:bdist_wheel
...
mattmoor

mattmoor commented on Oct 12, 2017

@mattmoor
ContributorAuthor

pkg_resources seems to load package information via a convoluted process around sys.path_hooks (docs).

Exploring this in a Bazel context (py_test) I see that sys.path_hooks basically has a single hook: zipimport.zipimporter.

Interestingly pkg_resources.resource_filename works fine in py_test, but I know @duggelz has indicated pkg_resources doesn't like some of the games Bazel / Python plays.

mattmoor

mattmoor commented on Oct 12, 2017

@mattmoor
ContributorAuthor

Hmm, within the context of the version_test.py, if I add wheel==0.30.0a0 to requirements.txt and if I add:

    ws = pkg_resources.WorkingSet()
    for dist in ws:
      print str(dist)

... to the test, I get the right Distributions of everything...

I'll try putting this into a PAR, and if all else fails having that PAR invoke a little python script.

mattmoor

mattmoor commented on Oct 12, 2017

@mattmoor
ContributorAuthor

Woof, so this is py_binary vs. par_binary.

If you clone the par-kour branch on my fork:

$ bazel run examples/par:list_resources
...
INFO: Running command line: bazel-bin/examples/par/list_resources
pip 9.0.1          <-- what I bundled
wheel 0.30.0a0     <--
...
$ bazel run examples/par:list_resources.par
...
INFO: Running command line: bazel-bin/examples/par/list_resources.par
...
pip 1.5.4          <-- system installed version
...

16 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @duggelz@brandjon@mattmoor@thundergolfer

        Issue actions

          Flask import breaks on OSX · Issue #17 · bazel-contrib/rules_python