Skip to content

Adapt ipython tools for testing pull requests - #752

Merged
hagberg merged 11 commits into
networkx:masterfrom
jtorrents:tools
Jan 4, 2013
Merged

hagberg merged 11 commits into
networkx:masterfrom
jtorrents:tools

Conversation

@jtorrents

Copy link
Copy Markdown
Member

@ipython has a very nice set of tools for their github based development workflow. See:

https://github.com/ipython/ipython/tree/master/tools

As @fperez suggested at SciPy 2012, it is easy and useful to adapt some of them for NetworkX development. This pull request adapts the test_pr.py script and friends for NetworkX. It automatically tests pull requests (using virtualenv and downloading the code directly from github) and optionally posts the results as a comment in the pull request page (including a link to a gist with the log for failed tests). It is a very nice and useful tool. For the origunal ipython pr_test.py see:

https://github.com/ipython/ipython/blob/master/tools/test_pr.py

I did some changes on how the tests are run inside each virualenv. IPython uses a script for running tests which is installed at the 'bin' directory of each virtialenv. But I think it is easier for NetworkX tests to simply use check_output:

py = os.path.join(basedir, venv, 'bin', 'python')
cmd = [py, '-c', 'import networkx as nx; nx.test(verbosity=2,doctest=True)']
log = check_output(cmd, stderr=STDOUT).decode('utf-8')

I also added PyPy support (last commit). But I'm not sure if it will work in something different than a Debian based system. PyPy and virtualenv play nice together and no significative change in the code is required, but in Debian/Ubuntu systems the option --system-site-packages of virtialenv does not add the actual dist-packages path for pypy (/usr/local/lib/pypy2.7/dist-packages). As a quick and dirty solution, I've opted for adding the path explicitly in run_tests() to be able to import nose, but it is not a solid solution. So more work is needed. I'll be quite busy the next days and I'm not sure if I will be able to work on this, so I'm posting it hoping than someone can take a look, test it in other systems and also work on it.

This script assumes that there is a directory named .nx_pr_tests in your home directory and that the nose package and other libraries are installed system wide in each python environment. It does not import anything from the user defined $PYTHONPATH.

@jtorrents

Copy link
Copy Markdown
Member Author

Test results for commit 773c75b merged into master (3fc2ba9)
Platform: linux2

  • python2.6: OK (SKIP=57) Ran 1525 tests (libraries not available: pyyaml, pydot, numpy, matplotlib, ogr, yaml, scipy, pyparsing, pygraphviz)
  • python2.7: OK (SKIP=2) Ran 1707 tests (libraries not available: ogr)
  • python3.2: OK (SKIP=10) Ran 1678 tests (libraries not available: pyparsing, ogr, pygraphviz, matplotlib, pydot)
  • pypy: OK (SKIP=57) Ran 1525 tests (libraries not available: pyyaml, pydot, numpy, matplotlib, ogr, yaml, scipy, pyparsing, pygraphviz)

@fperez

fperez commented Aug 10, 2012

Copy link
Copy Markdown
Contributor

Very happy to see you guys using our tools! Let us know if anything needs clarification, and conversely, please send any upates/improvements our way :)

@Carreau

Carreau commented Aug 11, 2012

Copy link
Copy Markdown
Contributor

Note that we use gh_api.py which could maybe be merged with pygithub to navigate github programmatically through python.
There is also hub that adds a lot of github magics to git, but in Ruby.

@jtorrents

Copy link
Copy Markdown
Member Author

@fperez One of the things that I like of test_pr and friends is their simplicity, by reading the code you get a clear idea of what is going on. When our adaptation is merged and has settled down I will put together a pull request with all the changes that could also benefit ipython's test_pr.

@Carreau we used pygithub for the migration trac -> github. It is under active development and has a lot of functionality, but is still not well documented and is rather big and complex compared with gh_api.py. For now I think that it is better to keep gh_api.py instead of adding an external dependency.

In the future might make sense to create a project to abstract and generalize this kind of script and create a proper standalone program (if I recall correctly @Carreau suggested that at scipy2012). Other projects, such as @sympy have the sympy-bot for testing pull requests which creates very nice reviews. I still like test_pr.py better because it is small, simple and gets the job done.

Thanks for test_pr.py and friends @ipython guys!

@hagberg

hagberg commented Aug 12, 2012

Copy link
Copy Markdown
Member

The test_pr.py script isn't working for me - maybe I'm missing something?

[aric@ll tools (tools)]$ python test_pr.py 742
Traceback (most recent call last):
  File "test_pr.py", line 340, in <module>
    test_pr(args.number, post_results=args.publish)
  File "test_pr.py", line 312, in test_pr
    testrun = TestRun(num)
  File "test_pr.py", line 77, in __init__
    self.pr = gh_api.get_pull_request(gh_project, pr_num)
  File "/home/aric/Software/hagberg-networkx/tools/gh_api.py", line 95, in get_pull_request
    return json.loads(response.text, object_hook=Obj)
AttributeError: 'Response' object has no attribute 'text'

@takluyver

Copy link
Copy Markdown

@hagberg: I think you need a newer version of requests.

@hagberg

hagberg commented Aug 12, 2012

Copy link
Copy Markdown
Member

OK - I figured it out. My Ubuntu installation had an old/different version of the "requests" package.
I installed the latest one from here and it works: http://docs.python-requests.org/en/latest/index.html

But I don't have a PYTHONPATH set and it breaks looking for that:

Traceback (most recent call last):
  File "test_pr.py", line 340, in <module>
    test_pr(args.number, post_results=args.publish)
  File "test_pr.py", line 316, in test_pr
    testrun.run()
  File "test_pr.py", line 231, in run
    passed, log = run_tests(venv)
  File "test_pr.py", line 267, in run_tests
    orig_pythonpath = os.environ["PYTHONPATH"]
  File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'PYTHONPATH'

These are small things but we should update the script to work (or break gracefully) in these cases. I have a stock Ubuntu 12.04 install.

@jtorrents

Copy link
Copy Markdown
Member Author

Yes, I forgot to mention that. The python-requests package in Ubuntu 12.04 is outdated, you need to install a newer version. Not sure which one, I installed it from its github repo. I'll try to figure out the minimum request version needed for test_pr.py

@takluyver

Copy link
Copy Markdown

.text was added in 0.10.0, it seems, while precise has 0.8.2. I don't know
if we rely on anything else added recently.

@jtorrents

Copy link
Copy Markdown
Member Author

I added the PYTHONPATH bug when trying to support pypy in Ubuntu. The commit above fixes it. But it is still not clear to me who is to blame for not adding the correct dist-packages path when creating a pypy virtualenv. I'll look at that, but will not have a lot of time the next few days. Maybe an option is to remove pypy support for now, and add it when we have figured it out.

I also added a check for requests version and if our requirements are not met the script exits with an informative message.

@hagberg

hagberg commented Aug 12, 2012

Copy link
Copy Markdown
Member

On Sun, Aug 12, 2012 at 2:11 PM, Jordi Torrents [email protected]:

I added the PYTHONPATH bug when trying to support pypy in Ubuntu. The
commit above fixes it. But it is still not clear to me who is to blame for
not adding the correct dist-packages path when creating a pypy
virtualenv. I'll look at that, but will not have a lot of time the next few
days. Maybe an option is to remove pypy support for now, and add it when we
have figured it out.

Yes, maybe we should take the pypy part out if it adds that complexity of
relying on PYTHONPATH.

I also added a check for requests version and if our requirements are not
met the script exits with an informative message.

Great.

@jtorrents

Copy link
Copy Markdown
Member Author

Test results for commit 8088d2e merged into master (3fc2ba9)
Platform: linux2

  • python2.6: OK (SKIP=57) Ran 1525 tests (libraries not available: pyyaml, pydot, numpy, matplotlib, ogr, yaml, scipy, pyparsing, pygraphviz)
  • python2.7: OK (SKIP=2) Ran 1707 tests (libraries not available: ogr)
  • python3.2: OK (SKIP=10) Ran 1678 tests (libraries not available: pyparsing, ogr, pygraphviz, matplotlib, pydot)

@fperez

fperez commented Aug 13, 2012

Copy link
Copy Markdown
Contributor

On Sun, Aug 12, 2012 at 9:34 AM, Jordi Torrents [email protected]:

@fperez https://github.com/fperez One of the things that I like of
test_pr and friends is their simplicity, by reading the code you get a
clear idea of what is going on. When our adaptation is merged and has
settled down I will put together a pull request with all the changes that
could also benefit ipython's test_pr.

Great! That will make future integration (see below) easier.

In the future might make sense to create a project to abstract and
generalize this kind of script and create a proper standalone program (if I
recall correctly @Carreau https://github.com/Carreau suggested that at
scipy2012). Other projects, such as @sympy https://github.com/sympyhave the
sympy-bot https://github.com/sympy/sympy-bot for testing pull

I completely agree. I think it's OK to beat the tools up a little
ourselves in each project until the dust settles, and then we should make
it a standalone toolset that we can all pull in via git submodules. That
will let us all work as if it were builtin, while reusing each other's
improvements more easily, and making it simpler for others to adopt these
tools and practices.

Thanks for test_pr.py and friends @ipython https://github.com/ipythonguys!

Our pleasure! It makes me really happy to see this kind of
reuse/collaboration of tools and ideas...

@Carreau

Carreau commented Aug 29, 2012

Copy link
Copy Markdown
Contributor

Note that this might make some of this work easier,
https://gist.github.com/3342247

and moreover, instead of fetching refs/pull/*/head you can fetch refs/pull/*/merge wich is already the current state merge into master.

That's actually how github does test how This pull request can be automatically merged., by trying to merge, and see if it fails. Though, I don't know what /merge point to when merge don't work, but github api should tell you that's it's not mergeable.

@jtorrents

Copy link
Copy Markdown
Member Author

@Carreau, that is very nice. I didn't know you could do that. It is very useful for easily fetching pull requests. I still don't have a good understanding of git, so I don't have an informed opinion of the changes that you propose. But I will port any changes that you guys do on ipython's test_pr.py. However I think that the summary of the script should be more explicit if the pull request is not mergeable, maybe asking explicitly to rebase from master (as the sympy-bot does). If I'm not mistaken, this can be done with the current implementation, it is only a matter of changing the summary output. I'll try to do that.

@Carreau

Carreau commented Aug 31, 2012

Copy link
Copy Markdown
Contributor

I still don't have a good understanding of git, so I don't have an informed opinion of the changes that you propose.

I dont know git well neither, I discovered it by mistake by mistyping what was in the gist.

I think that you could
Ask github api : Is it mergeable
if so
clone /pull/#pr/merge and do it with a --depth of 1 as you'll need only the more recent commit.
then run the test.

It should decrease the required bandwidth a lot.

@jtorrents

Copy link
Copy Markdown
Member Author

NetworkX: Test results for pull request #752
Branch tools from @jtorrents at https://github.com/jtorrents/networkx.git
✳️ This pull request can be merged clearly (commit 804e903 into NetworkX master 50cb114)
Platform: linux2

  • python2.6: ✳️ OK (SKIP=57) Ran 1526 tests (libraries not available: pyyaml, pydot, numpy, matplotlib, ogr, yaml, scipy, pyparsing, pygraphviz)
  • python2.7: ✳️ OK (SKIP=2) Ran 1708 tests (libraries not available: ogr)
  • python3.2: ✳️ OK (SKIP=10) Ran 1679 tests (libraries not available: pyparsing, ogr, pygraphviz, matplotlib, pydot)

@jtorrents

Copy link
Copy Markdown
Member Author

Finally I've found some time to work on this. I've improved the reports from tests in order to be clearer, they caused some confusion (see #762). As Chris (@chebee7i) noted, posting tests results that pass as github comments (as I just did above) can give a false sense of security. We could adopt the convention of only posting the result of the script if there is some failure (test_pr.py will post a trace of the nose output in a gist). Thus we avoid the false sense of security by only posting its result to signal to the author of the pull request that there is a problem that needs fixing.

@takluyver

Copy link
Copy Markdown

I think it's quite important to post on success, so that everyone can see that the PR was tested before it was merged. Scanning through #762, it looks like the confusion just relates to the wording 'merged into master', so maybe that can be adjusted. Then again, I don't think we've had the same confusion in IPython, so maybe it was a one off.

@jtorrents

Copy link
Copy Markdown
Member Author

2012/9/23 Thomas Kluyver [email protected]

I think it's quite important to post on success, so that everyone can see that the PR was tested before it was merged. Scanning through #762, it looks like the confusion just relates to the wording 'merged into master', so maybe that can be adjusted. Then again, I don't think we've had the same confusion in IPython, so maybe it was a one off.

Yes, the confusion was mostly related to the report's wording. Maybe
you are right that with a clearer report is enough. What do you think
Chris?

By the way, what do you think of the changes in the report? If you
find them useful I can prepare a pull request against IPython's
test_pr.py when this is finally merged.

@takluyver

Copy link
Copy Markdown

In fact, I think your wording is already clearer in the report above: "This pull request can be merged clearly..." (although I think it should say 'cleanly', not clearly). I like the little icons - I assume there's a different icon for a failure? I'm not so sure about the branch description line, it seems to duplicate information already in the PR, although I know there's not a link to the repository. Maybe it should be integrated into the title: "...pull request #752 (jtorrents 'tools' branch)"

@jtorrents

Copy link
Copy Markdown
Member Author

2012/9/23 Thomas Kluyver [email protected]

In fact, I think your wording is already clearer in the report above: "This pull request can be merged clearly..." (although I think it should say 'cleanly', not clearly). I like the little icons - I assume there's a different icon for a failure? I'm not so sure about the branch description line, it seems to duplicate information already in the PR, although I know there's not a link to the repository. Maybe it should be integrated into the title: "...pull request #752 (jtorrents 'tools' branch)"

Ok, these changes sound good to me, I'll do them shortly (after lunch
;) ). Regarding the icons, when something fails 🔴 is used.
Those are the same icons used by sympy-bot

@jtorrents

Copy link
Copy Markdown
Member Author

NetworkX: Test results for pull request #752 (jtorrents 'tools' branch)
🔴 This pull request cannot be merged cleanly (commit 430d53f into NetworkX master 50cb114). Please rebase from upstream/master
Platform: linux2

  • python2.6: ✳️ OK (SKIP=57) Ran 1525 tests (libraries not available: pyyaml, pydot, numpy, matplotlib, ogr, yaml, scipy, pyparsing, pygraphviz)
  • python2.7: ✳️ OK (SKIP=2) Ran 1707 tests (libraries not available: ogr)
  • python3.2: ✳️ OK (SKIP=10) Ran 1678 tests (libraries not available: pyparsing, ogr, pygraphviz, matplotlib, pydot)

@jtorrents

Copy link
Copy Markdown
Member Author

NetworkX: Test results for pull request #752 (jtorrents 'tools' branch)
✳️ This pull request can be merged cleanly (commit 430d53f into NetworkX master 50cb114)
Platform: linux2

  • python2.6: ✳️ OK (SKIP=57) Ran 1526 tests (libraries not available: pyyaml, pydot, numpy, matplotlib, ogr, yaml, scipy, pyparsing, pygraphviz)
  • python2.7: ✳️ OK (SKIP=2) Ran 1708 tests (libraries not available: ogr)
  • python3.2: ✳️ OK (SKIP=10) Ran 1679 tests (libraries not available: pyparsing, ogr, pygraphviz, matplotlib, pydot)

@jtorrents

Copy link
Copy Markdown
Member Author

Implemented the changes suggested by Thomas. I also posted a message of a non mergeable pull request. It asks explicitly to rebase form upstream/master. Let me know if something should be changed/improved.

@takluyver

Copy link
Copy Markdown

Doesn't git default to calling the clone source 'origin', rather than 'upstream'? I guess that doesn't work if you cloned from your own Github fork, though. Can the rebase command use a remote repository URL?

@jtorrents

Copy link
Copy Markdown
Member Author

NetworkX: Test results for pull request #752 (jtorrents 'tools' branch)
✳️ This pull request can be merged cleanly (commit 854868c into NetworkX master 50cb114)
Platform: linux2

  • python2.6: ✳️ OK (SKIP=57) Ran 1526 tests (libraries not available: pyyaml, pydot, numpy, matplotlib, ogr, yaml, scipy, pyparsing, pygraphviz)
  • python2.7: ✳️ OK (SKIP=2) Ran 1708 tests (libraries not available: ogr)
  • python3.2: ✳️ OK (SKIP=10) Ran 1679 tests (libraries not available: pyparsing, ogr, pygraphviz, matplotlib, pydot)

@jtorrents

Copy link
Copy Markdown
Member Author

2012/9/23 Thomas Kluyver [email protected]

Doesn't git default to calling the clone source 'origin', rather than 'upstream'? I guess that doesn't work if you cloned from your own Github fork, though. Can the rebase command use a remote repository URL?

I think it is not possible to add a remote repository URL with the
rebase command. I was assuming that the user have already added the
upstream target (following ipython development workflow
documentation). Which is assuming too much. I removed the suggestion
to rebase when there is no clean merge. Also refactored a bit the code
for reports.

@fperez

fperez commented Sep 23, 2012

Copy link
Copy Markdown
Contributor

On Sun, Sep 23, 2012 at 8:34 AM, Jordi Torrents [email protected]:

I was assuming that the user have already added the
upstream target (following ipython development workflow
documentation).

If we're still using the 'upstream' language, we need to fix that. That
was the original setup we came up with at the very beginning, but we've
fine-tuned it a bit and now we follow more standard conventions (using
'origin' for the main repo) that make it easier to copy/paste all default
messages and instructions github generates. I'm not using the name
'upsteream' anywhere anymore.

Sorry if our outdated docs led you astray...

@jtorrents

Copy link
Copy Markdown
Member Author

2012/9/23 Fernando Perez [email protected]

On Sun, Sep 23, 2012 at 8:34 AM, Jordi Torrents [email protected]:

I was assuming that the user have already added the
upstream target (following ipython development workflow
documentation).

If we're still using the 'upstream' language, we need to fix that. That
was the original setup we came up with at the very beginning, but we've
fine-tuned it a bit and now we follow more standard conventions (using
'origin' for the main repo) that make it easier to copy/paste all default
messages and instructions github generates. I'm not using the name
'upsteream' anywhere anymore.

I wrote ipython documentation but I was actually referring to numpy
documentation:

http://docs.scipy.org/doc/numpy/dev/gitwash/development_setup.html#set-up-fork

However there are still references to upstream in ipython
development workflow docs. I'm still adjusting to git and github (but
I like it!), so maybe I'm missing something, but how do you refer to
your fork at github if you use origin for the main ipython repo?

@fperez

fperez commented Sep 23, 2012

Copy link
Copy Markdown
Contributor

On Sun, Sep 23, 2012 at 3:01 PM, Jordi Torrents [email protected]:

However there are still references to upstream in ipython
development workflow docs. I'm still adjusting to git and github (but
I like it!), so maybe I'm missing something, but how do you refer to
your fork at github if you use origin for the main ipython repo?

By name: I now refer to 'origin' for all projects' main repos, and use
'fperez' to refer to my own. That way it's fully consistent always: named
repos are people's (my own or from other developers) and 'origin' always
means official project.

That approach has the advantage that copy/pasting snippets that github
auto-generates on pull requests and similar almost always works, as they
tend to refer to origin for everything.

I think the numpy instructions were created back when we thought of the
'upstream' naming model, and they may not have been updated. It seemed
like a good idea at the time, but in practice we found it was better to
fine-tune it a little. I've been now using the origin/personal names
pattern for quite a while and find it 100% satisfactory.

hagberg added a commit that referenced this pull request Jan 4, 2013
Adapt ipython tools for testing pull requests
@hagberg
hagberg merged commit ef11bff into networkx:master Jan 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants