-
Notifications
You must be signed in to change notification settings - Fork 70
PAR picks up system-installed version instead of bundled version #38
Comments
@duggelz Sorry I forgot to do this until just now, lmk if I can provide any more info. |
pip 1.5.4 from most likely from the |
pkg_resources doesn't recognize the packages inside the .par file, so it finds the old pip package. It's actually using the correct, newer version of pip, but I should fix this anyway. https://github.com/pypa/pip/blob/a9d56c7734fd465d01437d61f632749a293e7805/src/pip/_internal/utils/misc.py#L835 |
We'd have to do some surgery to tell pkg_resources about .par files, which are similar to, but different than .egg files. https://github.com/pypa/setuptools/blob/9f295a706590b1e3618978d6f2d83af0b893ec4d/pkg_resources/__init__.py#L1985 |
tl;dr I just linked an issue from Near as I can tell, this same problem is the root of why we cannot build This is because the metadata extracted from packages on the path is used to determine the "commands" that have been registered by a particular installed package. My conclusion is that we need our own The final gotcha (because nothing is easy) is that because wheel compilation happens in a separate process, we need whatever we do to work by just setting
Either way, I'm way outside of my depth. :) |
Hi there. I missed that the first time I peeked at |
Searching for examples of other finders, I happened across this, which seems close. |
Alright, hacking the hell out of that sample, I have something that seems to work for my tiny example... Basically, I added this to +class WheelMetadata(pkg_resources.EggMetadata):
+ """Metadata provider for zipped wheels."""
+
+ @classmethod
+ def _split_wheelname(cls, wheelname):
+ split_wheelname = wheelname.split('-')
+ return '-'.join(split_wheelname[:-3])
+
+ def _setup_prefix(self):
+ path = self.module_path
+ old = None
+ whl = os.path.dirname(path)
+ dir = os.path.dirname(whl)
+ if not dir.endswith('.par'):
+ return
+
+ whlname = os.path.basename(whl)
+ with zipfile.ZipFile(dir, 'r') as par:
+ for name in par.namelist():
+ parts = name.split('/', 2)
+ if parts[0] != whlname:
+ continue
+ if parts[1].endswith('.dist-info') and parts[2] == 'metadata.json':
+ self.egg_name = whlname
+ self.egg_info = os.path.join(dir, parts[0], parts[1])
+ self.egg_root = dir
+ break
+
+
+def wheel_from_metadata(location, metadata):
+ if not metadata.has_metadata(pkg_resources.DistInfoDistribution.PKG_INFO):
+ return None
+
+ from email.parser import Parser
+ pkg_info = Parser().parsestr(metadata.get_metadata(pkg_resources.DistInfoDistribution.PKG_INFO))
+ return pkg_resources.DistInfoDistribution(
+ location=location,
+ metadata=metadata,
+ project_name=pkg_info.get('Name'),
+ version=pkg_info.get('Version'),
+ platform=None)
+
+
+def find_whl_in_par(importer, path_item, only=False):
+ """Find .whl metadata in PAR files."""
+ metadata = WheelMetadata(importer)
+ dist = wheel_from_metadata(path_item, metadata)
+ if dist:
+ yield dist With this call in +
+ # Replace the built-in finder.
+ pkg_resources.register_finder(zipimport.zipimporter, find_whl_in_par) Who knows what breaks, but with this, $ bazel run examples/par:list_resources.par
...
pip 9.0.1
wheel 0.30.0a0
... I'm going to declare my day of Python spelunking a success and pray @duggelz finds this useful :) |
This is blocking the addition of several Python samples, including the http one and the TODO controller. The cause is tracked by [this](bazelbuild/rules_python#17) and [this](google/subpar#38) issue. Currently Bazel CI doesn't provide very meaningful coverage, most of it happens via Travis and example e2e tests.
After much head-scratching, it turns out pip has it's own private, independent, vendored version of |
The warning is: You are using pip version 1.5.4, however version 9.0.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. In reality, pip is at 9.0.1, but its bundled version of pkg_resources doesn't know that. See google/subpar#38
Ok, I don't think I can fix the 'bdist_wheel' issue without a ridiculous amount of hackery. The expedient solutions are:
Based on this and other considerations, I don't think I can avoid doing 2 any longer. |
More investigation: Simply doing https://github.com/pypa/pip/blob/master/src/pip/_vendor/__init__.py |
I don't think I appreciated that Github automatically closes issues if you have the right wording in your PR. |
In my PR to add PIP support to Bazel you can reproduce this as shown below.
On a system with:
(I must have gotten this through
apt-get
or some other super-slow release channel)If I
bazel run
thepy_binary
form, no warning:If I
bazel run
the.par
target, I get a warning:Happy to provide more info as needed.
The text was updated successfully, but these errors were encountered: