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

mock setup.py fails to detect incompatible setuptools fork 'distribute' and after install fails with "Versioning for this project requires..." #383

Closed
radekholy24 opened this issue Oct 20, 2016 · 7 comments

Comments

@radekholy24
Copy link

Reproducer:

  1. run a system with virtualenv 1.7.1.2 (in my case, a Vagrant box based on debian/wheezy64)
  2. create a Python 2.7 virtual environment (virtualenv venv)
  3. activate the environment (source venv/bin/activate)
  4. upgrade pip (pip install --upgrade pip)
  5. follow the mock's installation instructions (I did not find any, thus pip install mock)
  6. import mock (python -c "import mock")

Actual behavior:

An Exception with the following traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/mock/__init__.py", line 2, in <module>
    import mock.mock as _mock
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/mock/mock.py", line 71, in <module>
    _v = VersionInfo('mock').semantic_version()
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/pbr/version.py", line 460, in semantic_version
    self._semantic = self._get_version_from_pkg_resources()
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/pbr/version.py", line 447, in _get_version_from_pkg_resources
    result_string = packaging.get_version(self.package)
  File "/home/vagrant/venv/local/lib/python2.7/site-packages/pbr/packaging.py", line 725, in get_version
    raise Exception("Versioning for this project requires either an sdist"
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. Are you sure that git is installed

Expected behavior:

mock can be imported

Affected versions:

  • mock 2.0.0
  • pbr 1.10.0
  • pip 8.1.2
  • distribute 0.6.24
  • Python 2.7

Additional information

An upgrade of setuptools (pip install --upgrade pip) (to 28.6.1) after the installation of mock does not fix the issue. An upgrade before the installation helps.
Normally, I don't use these old libraries but I am forced to be compatible with Python 2.6 and Debian Wheezy seems to be the last Debian release that has Python 2.6 in its official repositories. Since I use that system only for testing and not for development, the provisioning of the system is automated (via Vagrant). Thus the steps above. Normally, I wouldn't even upgrade pip but I could not install mock without that.
What I want to say is that I understand that you expect users to use newer versions. But in such automated cases, it might not be the case. If you (or pbr - I don't know which package caused that) could enforce newer setuptools, it would really help. If not, at least a note in installation instructions would be nice.
Maybe this is a duplicate of #314. Maybe this is even a duplicate of https://bugs.launchpad.net/pbr/+bug/1505007. However, since the pbr bug is open for 1 year already without any response, it might be reasonable to implement a workaround in mock in the meantime.

@rbtcollins
Copy link
Member

Thanks, this is a great bug report. I suspect the heart of the problem lies in the use of distribution: mock detects too-old setuptools but distribute isn't triggering that errror during installation. You can see here - https://github.com/testing-cabal/mock/blob/master/setup.py#L5 that we require setuptools 17.1 or newer to install: and some bug in distribute is failing to recognise that it is an older version. (Note that this has broken and been fixed multiple times in setuptools from memory :(.).

So to confirm this, upgrading setuptools in the venv should fix it: which you note you have done and does fix it.

Therefore - I'm going to retitle the bug to indicate the failure is that we don't detect the incompatibility.

I have some sympathy for your situation but at the heart of the problem, running unsupported code and seeking community support is a difficult mix. http://www.curiousefficiency.org/posts/2015/04/stop-supporting-python26.html is a good blog post in this space.

One thing you could do to deal with Python 2.6 and such old tools is to install older versions of mock. I'm sure that <2.0.0 versions will work 'correctly' (I say 'correctly' because they suffer some fairly significant bugs that have lead to errors in dependent code due to tests just silently passing.

@rbtcollins rbtcollins changed the title mock installed with virtualenv 1.7.1.2 fails with "Versioning for this project requires..." mock installed with distribute fails with "Versioning for this project requires..." Oct 20, 2016
@rbtcollins
Copy link
Member

The underlying issue here is that distribute isn't installing the egg info in a way that pbr can actually read back - and pbr depends on the pkg_resources component of distribute, so the bug is down in that stack somewhere.

@rbtcollins
Copy link
Member

Also, I think this is in the category of, patches welcome: I have no interest in devoting time to supporting installs on 2.6 better: I won't deliberately break it, but thats the limit of my interest.

@radekholy24
Copy link
Author

radekholy24 commented Oct 20, 2016

Please note, that this bug is not specific to Python 2.6. I have deliberately provided a reproducer for Python 2.7.

Well, I cannot express how happy I would be if I could stop supporting Py2.6. But the system I want to support is my Nokia N9 phone. And since Microsoft shut down the repositories (I mean stopped supporting N9), I am stuck with Py2.6...

So, if you are not interested in supporting Python 2.6 anymore, may I ask you to improve the wording of the README accordingly? Until now I was under impression that you actually support Python 2.6... And if you mention there that e.g. setuptools >= 17.1 is required, I think that you can easily close this bug as resolved. But it's up to you of course. Just a suggestion... Actually, I can easily live with some workarounds in my Vagrantfile.

@tadeu
Copy link

tadeu commented Nov 17, 2016

There's a related error when using mock with frozen executables, because of this pbr/setuptools runtime dependency. Is it really important to have this dependency? Could the version information be written at setup time?

(It seems to have been introduced here: e795a4a)

@rbtcollins
Copy link
Member

@tadeu thats a totally separate discussion: to install properly mock needs a setuptools that handles conditional dependencies correctly, and we're not detecting that the setuptools in use here fails to do so - due to bugs in setup_requires handling in that (ancient) version. (and I do mean ancient). We'd still fail to install properly if pbr was not being used, and mock would still not work. I'll retitle it to be even more expliclt

@rbtcollins rbtcollins changed the title mock installed with distribute fails with "Versioning for this project requires..." mock setup.py fails to detect incompatible setuptools fork 'distribute' and after install fails with "Versioning for this project requires..." Dec 10, 2016
@cjw296
Copy link
Collaborator

cjw296 commented Nov 30, 2018

Thankfully, distribute and the need for it are now long gone :-)

@cjw296 cjw296 closed this as completed Nov 30, 2018
wchargin added a commit to tensorflow/tensorboard that referenced this issue Apr 19, 2019
Summary:
We’ve heretofore used the `mock` library without telling Bazel about it.
This isn’t generally a problem when `tensorflow` is installed in the
same virtualenv, because `tensorflow` pulls in `mock`. But tests that
don’t depend on TensorFlow have no build edge to `mock` when imported
into google3’s build system, causing build failures after syncing. This
commit makes the `mock` dependency explict.

We use `mock==1.0.0` rather than the current version (2.0.0) because the
current version depends on `pbr` at runtime in a way that does not play
well with Bazel: <testing-cabal/mock#383>
(It appears to be trying to find some globally registered `setup.cfg`
file from which to read a version identifier.) Rather than vendoring and
patching `mock`, declaring a fake `:expect_mock_installed` target, or
hacking `PBR_VERSION=2.0.0` into the action env, we simply depend on a
saner version of the library, which is also the version used in google3.

Existing `mock` users have been detected and fixed up:

```
$ bazel query "
>     kind(
>         py_.*rule,
>         rdeps(//..., set($(git grep -l 'import mock\($\| \)')), 1)
>     )
> " \
> | awk '{ print "add deps @org_pythonhosted_mock|" $0 }' \
> | buildozer -f - \
> ;
```

Test Plan:
All notf tests now pass in a virtualenv that does not include `mock`:

```
$ virtualenv -q -p python2 ./ve
$ . ./ve/bin/activate
(ve) $ pip install 'absl-py>=0.7.0' 'numpy<2.0,>=1.14.5' boto3==1.9.86 flake8==3.5.0 futures==3.1.1 grpcio==1.6.3 yamllint==1.5.0 >/dev/null 2>&1
(ve) $ python -c 'import mock'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/buildtools/current/sitecustomize/sitecustomize.py", line 152, in SetupPathsAndImport
    return real_import(name, globals, locals, fromlist, level)
ImportError: No module named mock
(ve) $ cd ~/git/tensorboard
(ve) $ bazel test //tensorboard/... --test_tag_filters=support_notf
...
INFO: Build completed successfully, 12 total actions
//tensorboard:lazy_test                                                  PASSED in 0.2s
//tensorboard:lib_test                                                   PASSED in 0.9s
//tensorboard:manager_test                                               PASSED in 0.3s
//tensorboard:plugin_util_test                                           PASSED in 0.5s
//tensorboard:program_test                                               PASSED in 0.8s
//tensorboard/backend:application_test                                   PASSED in 1.0s
//tensorboard/backend:http_util_test                                     PASSED in 0.8s
//tensorboard/backend:json_util_test                                     PASSED in 0.8s
//tensorboard/compat/tensorflow_stub:gfile_test                          PASSED in 0.8s
//tensorboard/summary:summary_test                                       PASSED in 0.8s
//tensorboard/util:platform_util_test                                    PASSED in 0.3s
```

Previously, `manager_test` and `application_test` failed in such an
environment.

wchargin-branch: mock-dep
wchargin added a commit to tensorflow/tensorboard that referenced this issue Apr 20, 2019
Summary:
We’ve heretofore used the `mock` library without telling Bazel about it.
This isn’t generally a problem when `tensorflow` is installed in the
same virtualenv, because `tensorflow` pulls in `mock`. But tests that
don’t depend on TensorFlow have no build edge to `mock` when imported
into google3’s build system, causing build failures after syncing. This
commit makes the `mock` dependency explict.

We use `mock==1.0.0` rather than the current version (2.0.0) because the
current version depends on `pbr` at runtime in a way that does not play
well with Bazel: <testing-cabal/mock#383>
(It appears to be trying to find some globally registered `setup.cfg`
file from which to read a version identifier.) Rather than vendoring and
patching `mock`, declaring a fake `:expect_mock_installed` target, or
hacking `PBR_VERSION=2.0.0` into the action env, we simply depend on a
saner version of the library, which is also the version used in google3.

Existing `mock` users have been detected and fixed up:

```
$ bazel query "
>     kind(
>         py_.*rule,
>         rdeps(//..., set($(git grep -l 'import mock\($\| \)')), 1)
>     )
> " \
> | awk '{ print "add deps @org_pythonhosted_mock|" $0 }' \
> | buildozer -f - \
> ;
```

Test Plan:
All notf tests now pass in a virtualenv that does not include `mock`:

```
$ virtualenv -q -p python2 ./ve
$ . ./ve/bin/activate
(ve) $ pip install 'absl-py>=0.7.0' 'numpy<2.0,>=1.14.5' boto3==1.9.86 flake8==3.5.0 futures==3.1.1 grpcio==1.6.3 yamllint==1.5.0 >/dev/null 2>&1
(ve) $ python -c 'import mock'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/buildtools/current/sitecustomize/sitecustomize.py", line 152, in SetupPathsAndImport
    return real_import(name, globals, locals, fromlist, level)
ImportError: No module named mock
(ve) $ cd ~/git/tensorboard
(ve) $ bazel test //tensorboard/... --test_tag_filters=support_notf
...
INFO: Build completed successfully, 12 total actions
//tensorboard:lazy_test                                                  PASSED in 0.2s
//tensorboard:lib_test                                                   PASSED in 0.9s
//tensorboard:manager_test                                               PASSED in 0.3s
//tensorboard:plugin_util_test                                           PASSED in 0.5s
//tensorboard:program_test                                               PASSED in 0.8s
//tensorboard/backend:application_test                                   PASSED in 1.0s
//tensorboard/backend:http_util_test                                     PASSED in 0.8s
//tensorboard/backend:json_util_test                                     PASSED in 0.8s
//tensorboard/compat/tensorflow_stub:gfile_test                          PASSED in 0.8s
//tensorboard/summary:summary_test                                       PASSED in 0.8s
//tensorboard/util:platform_util_test                                    PASSED in 0.3s
```

Previously, `manager_test` and `application_test` failed in such an
environment.

wchargin-branch: mock-dep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants