zestsoftware / zest.releaser

Python software releasing made easy and repeatable
https://zestreleaser.readthedocs.io
GNU General Public License v2.0
198 stars 62 forks source link

DistributionNotFound error using zest.releaser version config and nosetests #207

Closed blueskyjunkie closed 7 years ago

blueskyjunkie commented 7 years ago

I've used the zest.releaser recommended version configuration from here http://zestreleaser.readthedocs.io/en/latest/versions.html#using-the-version-number-in-setup-py-and-as-version

This seems to be interfering with unittests run on the source using nosetests in my build system.

/bin/sh -c "/venv/bin/nosetests --with-cov --logging-level=INFO --cov-report term-missing --cov registerMap" E

ERROR: Failure: DistributionNotFound (The 'registerMap' distribution was not found and is required by the application) ---------------------------------------------------------------------- Traceback (most recent call last): File "/venv/lib/python3.5/site-packages/nose/failure.py", line 39, in runTest raise self.exc_val.with_traceback(self.tb) File "/venv/lib/python3.5/site-packages/nose/loader.py", line 418, in loadTestsFromName addr.filename, addr.module) File "/venv/lib/python3.5/site-packages/nose/importer.py", line 47, in importFromPath return self.importFromDir(dir_path, fqname) File "/venv/lib/python3.5/site-packages/nose/importer.py", line 94, in importFromDir mod = load_module(part_fqname, fh, filename, desc) File "/venv/lib/python3.5/imp.py", line 244, in load_module return load_package(name, filename) File "/venv/lib/python3.5/imp.py", line 216, in load_package return _load(spec) File "", line 693, in _load File "", line 673, in _load_unlocked File "", line 665, in exec_module File "", line 222, in _call_with_frames_removed File "/builds/registerMap/registerMap/init.py", line 19, in version = pkg_resources.get_distribution("registerMap").version File "/venv/lib/python3.5/site-packages/pkg_resources/init.py", line 535, in get_distribution dist = get_provider(dist) File "/venv/lib/python3.5/site-packages/pkg_resources/init.py", line 415, in get_provider return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0] File "/venv/lib/python3.5/site-packages/pkg_resources/init.py", line 943, in require needed = self.resolve(parse_requirements(requirements)) File "/venv/lib/python3.5/site-packages/pkg_resources/init.py", line 829, in resolve raise DistributionNotFound(req, requirers) pkg_resources.DistributionNotFound: The 'registerMap' distribution was not found and is required by the application `

I assume the problem is that because my package hasn't been properly "installed" in a virtualenv or whatever, that the version configuration doesn't work properly.

I'm new to Python packaging and zest.releaser, so it's possible, even likely, that there is a known solution to this either in nosetests configuration, or in a methodology change.

I haven't discovered anything in searching. The one idea I had was to do a 'dev' installation of my project (which I don't yet know how to do, but setup.py seems to suggests it is possible) in the build and then run unittests from that. This seems like a complex solution to something that probably is a configuration problem.

If you can suggest a work around I would be most grateful.

mauritsvanrees commented 7 years ago

So if you remove the __version__ line, it works? That would be a workaround. If it still fails, then something else is wrong.

But it sounds like you haven't installed the package yet. When the current directory contains the setup.py of your registerMap package, this should to the trick:

/venv/bin/python setup.py develop
blueskyjunkie commented 7 years ago

If I remove the __version__ line, the unit tests work. Strangely, running the unittests at the top level of the project from PyCharm works just fine regardless, but I don't seem to be able to find exactly what magic PyCharm is doing when it runs nosetest.

It's true that in my CI build or just running from my source folder as I'm editing, I haven't installed the package yet, but why should I need to, except to fool the pkg_resources library into thinking it has what it needs for __version__?

In any case, for the CI build, running your suggested python setup does enable the unit tests to work.

Thanks for your help.

reinout commented 7 years ago

The code you were using for __version__ asks pkg_resources for information about a package. "So" pkg_resources needs to know about the packages. "So" it must be installed.

It probably works when running from the source folder because the top level directory can be found.

blueskyjunkie commented 7 years ago

It probably works when running from the source folder because the top level directory can be found.

That suggests that there is an incantation that PyCharm is using that doesn't require installation of the library, no?

Is it as simple as adding my source library to PYTHONPATH before invoking nosetests?

mauritsvanrees commented 7 years ago

That might help yes. I have PyCharm, but haven't used it much yet.