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

Add Python dependencies during ocpkg setup and then check for them during unit test invocation #337

Closed
cosmoharrigan opened this issue Oct 20, 2013 · 21 comments

Comments

@cosmoharrigan
Copy link
Member

  • What method should we use to add additional Python dependencies to ocpkg? (apt-get, pip, virtual environment...)
  • What is a good way to confirm that required Python dependencies are installed before CMake causes the associated Python unit tests to be ran?

Previous discussion, quoted from #336:
@cosmoharrigan:

In regards to new dependencies: I was thinking about Python dependencies recently while working on a separate task, and I was wondering: if we start using the tests/python directory again and re-enable AllPythonModuleTests in tests/python/CMakeLists.txt - what is a good way to confirm that required Python dependencies are installed before CMake causes the associated Python unit tests to be ran?

@keyvan-m-sadeghi:

I'm pretty sure that the code in tests/python is obsolete, but it certainly makes sense to have someone update them. I'm not sure how CMake comes into play, but I said in a thread earlier that it may make sense to have a C++ UTest call to Python tests, we could also introduce new flags like test-python or so.

Regarding the Python dependencies, there are two approaches:

-- Have OCPKG install python requirements with a flag like --python

-- create a virtual environment and have it install requirements.txt (included in this patch, but should be refactored to use >= instead of ==)

Lots to be done in the python-dev section, we're just starting...

@cosmoharrigan
Copy link
Member Author

The disabled portion of the tests/python/CMakeLists.txt file created AllPythonModuleTests, which invokes nosetests, which runs all the tests in the tests/python directory that meet the nosetests regex pattern. I'm going to try re-enabling it, and move the out-of-date tests to a separate directory until they are reviewed.

@linas
Copy link
Member

linas commented Oct 20, 2013

in CMakefiles, you can use expressions like

IF (HAVE_CYTHON)
do stuff..
ENDIF(HAVE_CYTHON)

which will do stuff only if cython is installed. If you also need nose, then

IF (NOSETESTS_EXECUTABLE)
do stuff ...
ENDIF (NOSETESTS_EXECUTABLE)

If you need to run python scripts indepedently of the cython interp inside of the cogserver, then you'd also need to check:

IF(PYTHONINTERP_FOUND)
ENDIF( ...)

This way, CMake won't break for those people who don't have these things installed.

@linas
Copy link
Member

linas commented Oct 20, 2013

Oh. from issue 336 there is a specific need to check for : python-numpy, python-scipy, python-matplotlib

Our current CMake scripts do not check for these. They don't need to, either, unless something (e.g. a unit test) will break if the dependencies are absent.

@cosmoharrigan
Copy link
Member Author

They don't need to, either, unless something (e.g. a unit test) will break if the dependencies are absent.

Yes, that is the scenario that I am referring to: checking for Python module dependencies that are required for a unit test to pass.

Nosetests allows you to skip the rest of the unit tests in a file if a certain condition is met by calling unittest.SkipTest:

try:
    import .....
except ImportError:
    import unittest
    raise unittest.SkipTest("ImportError exception: make sure the required dependencies are installed.")

Then, the ImportError is logged in LastTest.log, but the test is marked as passing, not failing.

But, is there a better way to approach it?

@cosmoharrigan
Copy link
Member Author

So, @ferrouswheel also suggested that we should use pip with requirements.txt. Would it be okay to add that to the ocpkg script?

@githart
Copy link
Member

githart commented Oct 22, 2013

yup, easy for ocpkg to find any requirements.txt in the source tree then 'pip install -r requirements.txt' them all. I'll test in a container before rolling out to the buildbot server.

@linas
Copy link
Member

linas commented Oct 22, 2013

Nosetests allows you to skip the rest of the unit tests in a file if a

certain condition is met by calling unittest.SkipTest:

OK, this is how the CMake unit tests work too: if some module is not
installed, then the code is not compiled, and th unit tests for it are not
run. All tests pass; there are just fewer of them.

Since CMake also prints out which subsystems it skipped, you at least get
some clue about what you need to do to get all of them.

Ideally, CMake should be modified so that skipped tests are marked
'skipped' instead of being ignored completely.

The pyhon framework should work the same way: mark each test as pass, fail,
or skipped; if skipped, something should hint why (i.e. some dependency not
installed)

Then, the ImportError is logged in LastTest.log, but the test is marked as
passing, not failing.

Aiee! Yet another log file! Ideally, all these test results need to get
prited to stdout, and not hidden in a log file.

@githart
Copy link
Member

githart commented Nov 14, 2013

python-flask-restful is available in ppa:gandelman-a/test-catalog.

I've sent @gandelman-a a note asking if he plans to rebuild this package in a longer-lived PPA or for trusty or precise-backports.

ocpkg in testing at https://github.com/githart/opencog-config-files/tree/master/docker/opencog/precise

@gandelman-a
Copy link

I'm on holiday atm but plan on getting uploadd to Debian + Ubuntu Trusty
when I return.

On Wed, Nov 13, 2013 at 9:58 PM, David Hart notifications@github.comwrote:

python-flask-restful is available in ppa:gandelman-a/test-catalog.

I've sent @gandelman-a https://github.com/gandelman-a a note asking if
he plans to rebuild this package in a longer-lived PPA or for trusty or
precise-backports.

ocpkg in testing at
https://github.com/githart/opencog-config-files/tree/master/docker/opencog/precise


Reply to this email directly or view it on GitHubhttps://github.com//issues/337#issuecomment-28461540
.

@githart
Copy link
Member

githart commented Nov 16, 2013

@gandelman-a thanks, that's good news!

Will cxxtest invoke python tests individually, per module, once for all of opencog/python? Has a python testing framework been chosen yet?

@cosmoharrigan
Copy link
Member Author

We're already using nosetests, and and they're invoked per module.

On Fri, Nov 15, 2013 at 5:16 PM, David Hart notifications@github.comwrote:

@gandelman-a https://github.com/gandelman-a thanks, that's good news!

Will cxxtest invoke python tests individually, per module, once for all of
opencog/python? Has a python testing framework been chosen yet?


Reply to this email directly or view it on GitHubhttps://github.com//issues/337#issuecomment-28616184
.

@githart
Copy link
Member

githart commented Mar 3, 2014

To date all python dependencies are fulfilled via system package repos & PPAs without the need for pips or python virtualenv. I can revisit the proliferation of PPAs when testing on trusty.

@cosmoharrigan
Copy link
Member Author

@githart A new dependency has been added for the REST API: pip install graphviz. I would like to add this to the ocpkg script so that the continuous integration server can run the unit test on the functionality, but first, I want to check in with you and ask if you think we could start using pip to manage Python dependencies?

@ferrouswheel
Copy link
Contributor

Not sure if it's helpful in this instance, but many python projects use a pip requirements file which can be generated with pip freeze > requirements.txt.

Then installing dependencies for pypi/github/whereever is as easy as pip install -r requirements.txt.

@cosmoharrigan
Copy link
Member Author

@ferrouswheel thanks Joel. In fact, we started to use that in
https://github.com/opencog/opencog/blob/master/opencog/python/requirements.txt
but whether that will be used as part of the ocpkg script used by the continuous integration server is the open question.

@githart
Copy link
Member

githart commented Jun 23, 2014

The next version of the CI server (likely Drone or similar instead of Buildbot) will use PyPI and requirements.txt.

@cosmoharrigan
Copy link
Member Author

Thanks @githart

@amebel
Copy link
Contributor

amebel commented May 4, 2015

@cosmoharrigan #1577 and #1579 replaced the installation of python packges using pip instead of apt.

@inflector are there means of checking for python packges in cmake?

@inflector
Copy link
Member

@amebel This way:

https://cmake.org/pipermail/cmake/2011-January/041666.html

can probably be adapted to your needs. What are you trying to check in cmake?

@amebel
Copy link
Contributor

amebel commented Jan 21, 2016

For checking whether a package exists before trying to run a test. Thanks for the pointer, will look at it.

@linas
Copy link
Member

linas commented Feb 22, 2016

closing opencog/ocpkg code has moved, I have opened opencog/ocpkg#55 to continue tracking this issue.

@linas linas closed this as completed Feb 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants