Skip to content

Conversation

nikhaldi
Copy link
Contributor

@nikhaldi nikhaldi commented Dec 5, 2017

Previously any wheel dependencies that had an environment marker
(such as 'python_version>3.3') were simply ignored, leading to
missing packages in the Python environment constructed by bazel.

Fixes #49

@bazel-io
Copy link

bazel-io commented Dec 5, 2017

Can one of the admins verify this patch?

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
  • In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

@nikhaldi
Copy link
Contributor Author

nikhaldi commented Dec 5, 2017

Two concerns that I still have with this change:

  1. This definitely has the potential to break existing builds. Not sure what the rules are around breaking changes.
  2. This relies on pkg_resources.evaluate_marker() which comes from setuptools. I assume it's only available from some setuptools version onwards. I wonder if it's a good idea to put a lower boundary setuptools version in python/requirements.txt. Update: evaluate_marker() has been part of the API since setuptools version 1.0, so not a real concern.

@nikhaldi nikhaldi force-pushed the feat/python-version-markers branch from 25d1649 to 3c2e6ad Compare December 6, 2017 16:57
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes and removed cla: no labels Dec 6, 2017
Copy link
Contributor

@mattmoor mattmoor left a comment

Choose a reason for hiding this comment

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

This generally looks good to me. Can you rebase?

if VERSION_TUPLE < (3, 3):
expected_deps = ['funcsigs', 'pbr', 'six']
else:
expected_deps = ['pbr', 'six']
Copy link
Contributor

Choose a reason for hiding this comment

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

@duggelz Do you have any tricks to get coverage of both paths?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I think it can be done by mocking platform.python_version(). I could add this to this PR or send a separate change after.

Previously any wheel dependencies that had an environment marker
(such as 'python_version>3.3') were simply ignored, leading to
missing packages in the Python environment constructed by bazel.

Fixes bazel-contrib#49
Required after making changes to whl.py
@nikhaldi nikhaldi force-pushed the feat/python-version-markers branch from d60c037 to 7398169 Compare December 13, 2017 18:37
@nikhaldi
Copy link
Contributor Author

@mattmoor rebased

@mattmoor
Copy link
Contributor

Test this please

(For Bazel CI)

@nikhaldi
Copy link
Contributor Author

About the CI failure (https://ci.bazel.io/blue/organizations/jenkins/PR%2Frules_python/detail/rules_python/67/pipeline): It seems the linux-x86_64 environment on Jenkins has a somewhat old setuptools version which does not yet support some common syntax in version markers. It's failing on '<='. This appears to be supported from setuptools 17.1 onwards.

I added another commit which pins the version of setuptools in piptool to the latest (38.2.4). I think this is a good idea in any case as it should make builds more predictable in general. It does mean that the piptool.par executable is now 1.8M instead of 1.3M as setuptools is embedded in it.

@mattmoor
Copy link
Contributor

Test this please

@nikhaldi
Copy link
Contributor Author

Ugh, this is painful. piptool does use the provided setuptools now, but the whl_library rules generated by piptools do not. Unclear to me if it's possible to pull in the correct setuptools in the whl_library rules. I'll need more time to investigate, any ideas appreciated in the meantime.

@mattmoor
Copy link
Contributor

@nikhaldi This is because we are actually using two different scripts to do this, piptool.par is one, which we bundle as a PAR to avoid needing the host to have pip installed, and whl.py, which we invoke directly.

So why are these (checked in .par or .py) our only options?

During BUILD steps, you can use py_binary targets as "tools", but you cannot do this during WORKSPACE. So whatever you invoke must be a standalone executable.

So how do we get past this?

Given a dependency on a particular setuptools, I think the option that makes the most sense would be to do with whl.py what we do for piptool.par and have update_tools.sh check a PAR file into the repo (yuck, but oh well).

LMK if that [doesn't] make sense, and I'm happy to elaborate.

@nikhaldi
Copy link
Contributor Author

@mattmoor thanks for the explanation. It makes somewhat sense, though it feels like there is a lot of duct tape holding this thing together.

I can see how to do a separate whl.par. An alternative might be to vendor (copy) the packaging module. That's where the environment marker parsing is actually implemented. I only realized recently that setuptools is doing the same thing, it's just vendoring packaging. The existing uses in piptool of pkg_resources.Requirement could probably be replaced with packaging as well which would remove setuptools from piptool.par. Thoughts?

I won't have time to look at this further until late December/early January but I can spend some more time on it then. I'm not unhappy either if somebody else takes over in the meantime.

@mattmoor
Copy link
Contributor

@nikhaldi You cannot vendor the packaging module because whl.py has to be a self-contained script to work properly. This is what I meant when I said it couldn't be a py_binary.

FWIW, I agree with your characterization (re: duct tape), but I think it's largely working around some limitations of Bazel that aren't easily fixed (though I've been trying!). For things that aren't, I'm certainly open to discussing the trade-offs and making improvements.

The existing uses in piptool of pkg_resources.Requirement could probably be replaced with packaging as well which would remove setuptools from piptool.par. Thoughts?

Defer to @duggelz wisdom, but superficially this SGTM.

I won't have time to look at this further until late December/early January but I can spend some more time on it then. I'm not unhappy either if somebody else takes over in the meantime.

No worries, everything slows down this time of year :)

I really appreciate you taking the time to send us this PR.

@nikhaldi nikhaldi force-pushed the feat/python-version-markers branch from 6a67037 to cf58abc Compare December 27, 2017 18:17
@nikhaldi
Copy link
Contributor Author

Test this please

1 similar comment
@mattmoor
Copy link
Contributor

Test this please

Some common operators in version markers (e.g., <=) are only supported
in setuptools>=17.1. Rather than risk failing because the environment
has an old setuptools version it's better to include it. Pinning to
an exact version (currently the latest) to make things as predictable
as possible.

In addition, whl.py used during workspace setup also now depends on
setuptools. We package this in a separate whltool.par to make this
predictable as well.
@nikhaldi nikhaldi force-pushed the feat/python-version-markers branch from cf58abc to 6a8e4ef Compare December 27, 2017 18:24
@nikhaldi
Copy link
Contributor Author

This appears to be working now with a separate whltool.par. Also refactored the tests to not use ugly branching based on Python versions.

I opted to leave the setuptools package in over packaging because piptool uses some pkg_resources features which I'm not sure can easily be rewritten with packaging. This could be a separate refactoring if the size of the par files is a real concern.

@mattmoor
Copy link
Contributor

Test this please

alexeagle pushed a commit to alexeagle/rules_python that referenced this pull request Aug 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants