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

whl: Parse requirements from METADATA files #90

Open
wants to merge 1 commit into
base: master
from

Conversation

@evanj
Copy link

@evanj evanj commented Apr 9, 2018

Some wheels only include METADATA files (examples: wheel 0.31.0,
tenacity 4.10.0). Previously whl did not parse the requirement
sections. Add code to parse these sections.

The most complicated part is parsing out the extra == 'something'
clauses from the boolean expression. Use the same expression parser
used by pkg_resources.evaluate_marker which is already used by this
code to find those clauses and produce a version with them removed.

@evanj
Copy link
Author

@evanj evanj commented Apr 9, 2018

I ran into this with our rules_pyz rules, but since we basically use a version of this tool ourselves, I decided I might as well submit this improvement upstream: https://github.com/TriggerMail/rules_pyz

@ensonic
Copy link

@ensonic ensonic commented Jun 11, 2018

Got the same problem. Could you please rebase the change, so that I can verify it?

Some wheels only include METADATA files (examples: wheel 0.31.1,
tenacity 4.10.0). Previously whl did not parse the requirement
sections. Add code to parse these sections.

The most complicated part is parsing out the extra == 'something'
clauses from the boolean expression. Use the same expression parser
used by pkg_resources.evaluate_marker which is already used by this
code to find those clauses and produce a version with them removed.
@evanj evanj force-pushed the evanj:parse-metadata-requires branch from 0de64e6 to 1a1ebcd Jun 12, 2018
@evanj
Copy link
Author

@evanj evanj commented Jun 12, 2018

I just rebased this change. I also updated the version of wheel that is used by the test to the latest version.

@ensonic
Copy link

@ensonic ensonic commented Jun 12, 2018

I found one issue that does not work. Look at the last line of the generated BUILD file:

# ... /external/pypi__gapic_google_cloud_logging_v2_0_91_3/BUILD

package(default_visibility = ["//visibility:public"])

load("@ros_log_deps//:requirements.bzl", "requirement")

py_library(
  name = "pkg",
  srcs = glob(["**/*.py"]),
  data = glob(["**/*"], exclude=["**/*.py", "**/* *", "BUILD", "WORKSPACE"]),
  # This makes this directory a top-level in the python import
  # search path for anything that depends on this.
  imports = ["."],
  deps = [requirement("google-gax"),requirement("googleapis-common-protos[grpc]"),requirement("oauth2client"),requirement("proto-google-cloud-logging-v2[grpc]"
)],
     )

this results into:

key "googleapis_common_protos[grpc]" not found in dictionary
@rogerhub
Copy link

@rogerhub rogerhub commented Jul 16, 2018

Also, do tools/piptool.par and tools/whltool.par need to be updated to include these changes?

@bbarnes52
Copy link

@bbarnes52 bbarnes52 commented Aug 2, 2018

any ETA when this will be resolved?

@lberki lberki requested a review from brandjon Aug 3, 2018
@lberki
Copy link
Collaborator

@lberki lberki commented Aug 3, 2018

Soon! Jon will start working on this around middle August. Sorry for the continuing delays.

@c4urself
Copy link

@c4urself c4urself commented Aug 14, 2018

whl.py should not have any Python2-only syntax (such as basestring) -- the problem is that when you parse requirements with pkg_resources.evaluate_marker it will use the current script's Python version. A lot of libraries have extra requires if it's not Python3, so, when running whltool.par under Python2 you end up adding unresolvable requirements to the BUILD file. For example requirement('futures') which is a builtin Python3 lib that's been backported.

Note if whltool.par is Python2 then we will always only get Python2 dependencies.

@c4urself
Copy link

@c4urself c4urself commented Aug 14, 2018

I think the right way to do is is to merge #82 first and then use six to make whl.py Python2/3 compatible.

@gfl-chris
Copy link

@gfl-chris gfl-chris commented Sep 11, 2018

Hello! Are there any updates on this?

The workaround to declare transitive dependencies manually is only so much maintainable...

@davidstanke
Copy link
Contributor

@davidstanke davidstanke commented Sep 11, 2018

@brandjon for thoughts?

gfl-chris added a commit to zenreach/rules_python that referenced this pull request Sep 11, 2018
@gfl-chris
Copy link

@gfl-chris gfl-chris commented Sep 11, 2018

I merged this PR into my fork and I do see the BUILD files in the ./bazel-<proj>/external/* directories now contain the transitive dependencies, but they don't seem to be automatically picked up. Any idea what I need to add to my BUILD files?

gfl-chris added a commit to zenreach/rules_python that referenced this pull request Sep 11, 2018
gfl-chris added a commit to zenreach/rules_python that referenced this pull request Sep 11, 2018
gfl-chris added a commit to zenreach/rules_python that referenced this pull request Sep 11, 2018
@gfl-chris
Copy link

@gfl-chris gfl-chris commented Sep 12, 2018

I take that back. This does generate dependencies for some packages, but not for others. For example, the BUILD file for Flask-1.0.2 looks like this:


package(default_visibility = ["//visibility:public"])

load("@my_deps//:requirements.bzl", "requirement")

py_library(
    name = "pkg",
    srcs = glob(["**/*.py"]),
    data = glob(["**/*"], exclude=["**/*.py", "**/* *", "BUILD", "WORKSPACE"]),
    # This makes this directory a top-level in the python import
    # search path for anything that depends on this.
    imports = ["."],
    deps = [],
)

but deps should really be [requirement("Werkzeug"),requirement("Jinja2"),requirement("itsdangerous"),requirement("click")]. For Flask-RESTful-0.3.6, the BUILD looks like this:


package(default_visibility = ["//visibility:public"])

load("@my_deps//:requirements.bzl", "requirement")

py_library(
    name = "pkg",
    srcs = glob(["**/*.py"]),
    data = glob(["**/*"], exclude=["**/*.py", "**/* *", "BUILD", "WORKSPACE"]),
    # This makes this directory a top-level in the python import
    # search path for anything that depends on this.
    imports = ["."],
    deps = [requirement("Flask"),requirement("aniso8601"),requirement("pytz"),requirement("six")],
)

which is correct.

@nayak16
Copy link

@nayak16 nayak16 commented Sep 13, 2018

What is the status of this? @buchgr

@buchgr
Copy link
Contributor

@buchgr buchgr commented Sep 13, 2018

@nayak16 I am not familiar with this change. Wrong ping?

@asford
Copy link

@asford asford commented Feb 25, 2019

@brandjon Any chance you can review this in connection to your triage of #70?

@greggdonovan
Copy link
Member

@greggdonovan greggdonovan commented May 28, 2019

@evanj @brandjon What's the latest on this PR? We're interested in this, as we have had to pause any Python dependency updates for effected dependencies. E.g. kubernetes-client.

@evanj
Copy link
Author

@evanj evanj commented May 29, 2019

I couldn't convince my organization to use Bazel, so I no longer have the time to figure out how to get Python to work with it, sorry.

@pcn
Copy link

@pcn pcn commented Jun 13, 2019

#121 works as-is with python2, but doesn't work on its latest commits with python3.

@greggdonovan
Copy link
Member

@greggdonovan greggdonovan commented Jun 18, 2019

@brandjon Do you have any advice for how to move forward? If this PR is rebased is it mergeable?

@hrfuller
Copy link
Collaborator

@hrfuller hrfuller commented Sep 3, 2020

Wondering the same. What is needed to get this merged?

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

Successfully merging this pull request may close these issues.

None yet

You can’t perform that action at this time.