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

Enable some Python 3 testing. #768

Merged
merged 8 commits into from Feb 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -7,6 +7,7 @@ env:
- TOX_ENV=py27-lint-readme
- TOX_ENV=py27-lint-docs
- TOX_ENV=py27-quick
- TOX_ENV=py34-quick
- TOX_ENV=py27
- TOX_ENV=py34
- TOX_ENV=py27-lint-docstrings
Expand Down
10 changes: 5 additions & 5 deletions planemo/bioconda_scripts/bioconductor_skeleton.py
Expand Up @@ -3,6 +3,7 @@
https://github.com/bioconda/bioconda-recipes/blob/master/scripts/bioconductor/bioconductor_skeleton.py
(written by Ryan Dale github: daler)
"""
from __future__ import print_function

import configparser
import hashlib
Expand All @@ -12,14 +13,13 @@
import shutil
import tarfile
import tempfile
import urlparse
from collections import OrderedDict
from textwrap import dedent

import bs4
import pyaml
import requests

from six.moves.urllib.parse import urljoin

logging.basicConfig(level=logging.INFO, format='[bioconductor_skeleton.py %(asctime)s]: %(message)s')
logger = logging.getLogger()
Expand Down Expand Up @@ -135,7 +135,7 @@ def f(href):
# build the actual URL based on the identified package name and the
# relative URL from the source. Here we're just hard-coding
# '../src/contrib' based on the structure of the bioconductor site.
return os.path.join(urlparse.urljoin(self.url, '../src/contrib'), s[0])
return os.path.join(urljoin(self.url, '../src/contrib'), s[0])

@property
def tarball_url(self):
Expand Down Expand Up @@ -197,8 +197,8 @@ def description(self):
e = c['top']

# Glue together newlines
for k in e.keys():
e[k] = e[k].replace('\n', ' ')
for k, v in e.items():
e[k] = v.replace('\n', ' ')

return dict(e)

Expand Down
4 changes: 3 additions & 1 deletion planemo/database/postgres.py
Expand Up @@ -2,6 +2,8 @@

import subprocess

from galaxy.util import unicodify

from planemo.io import communicate
from .interface import DatabaseSource

Expand All @@ -20,7 +22,7 @@ def __init__(self, **kwds):
def list_databases(self):
"""Use `psql --list` to generate a list of identifiers."""
command_builder = self._psql_command_builder("--list")
stdout = self._communicate(command_builder)
stdout = unicodify(self._communicate(command_builder))
output_lines = stdout.splitlines()
identifiers = []
for line in output_lines:
Expand Down
12 changes: 7 additions & 5 deletions planemo/git.py
@@ -1,8 +1,10 @@
"""Utilities for interacting with git using planemo abstractions."""
from __future__ import absolute_import

import os
import subprocess

from six import text_type
from galaxy.util import unicodify

from planemo import io

Expand Down Expand Up @@ -81,7 +83,7 @@ def diff(ctx, directory, range):
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True
)
return [l.strip() for l in text_type(stdout).splitlines() if l]
return [l.strip() for l in unicodify(stdout).splitlines() if l]


def clone(*args, **kwds):
Expand All @@ -103,7 +105,7 @@ def rev(ctx, directory):
stdout, _ = io.communicate(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
return text_type(stdout).strip()
return unicodify(stdout).strip()


def is_rev_dirty(ctx, directory):
Expand All @@ -117,8 +119,8 @@ def rev_if_git(ctx, directory):
"""Determine git revision (or ``None``)."""
try:
the_rev = rev(ctx, directory)
is_dirtry = is_rev_dirty(ctx, directory)
if is_dirtry:
is_dirty = is_rev_dirty(ctx, directory)
if is_dirty:
the_rev += "-dirty"
return the_rev
except RuntimeError:
Expand Down
18 changes: 5 additions & 13 deletions planemo/io.py
Expand Up @@ -51,7 +51,7 @@ def shell(cmds, **kwds):
def info(message, *args):
if args:
message = message % args
_echo(click.style(message, bold=True, fg='green'))
click.echo(click.style(message, bold=True, fg='green'))


def can_write_to_path(path, **kwds):
Expand All @@ -64,20 +64,13 @@ def can_write_to_path(path, **kwds):
def error(message, *args):
if args:
message = message % args
_echo(click.style(message, bold=True, fg='red'), err=True)
click.echo(click.style(message, bold=True, fg='red'), err=True)


def warn(message, *args):
if args:
message = message % args
_echo(click.style(message, fg='red'), err=True)


def _echo(message, err=False):
if sys.version_info[0] == 2:
click.echo(message, err=err)
else:
print(message)
click.echo(click.style(message, fg='red'), err=True)


def shell_join(*args):
Expand Down Expand Up @@ -133,7 +126,7 @@ def find_matching_directories(path, pattern, recursive):

@contextlib.contextmanager
def real_io():
"""Ensure stdout and stderr have ``fileno`` attributes.
"""Ensure stdout and stderr have supported ``fileno()`` method.

nosetests replaces these streams with :class:`StringIO` objects
that may not work the same in every situtation - :func:`subprocess.Popen`
Expand All @@ -142,9 +135,8 @@ def real_io():
original_stdout = sys.stdout
original_stderr = sys.stderr
try:
if not hasattr(sys.stdout, "fileno"):
if commands.redirecting_io(sys=sys):
sys.stdout = sys.__stdout__
if not hasattr(sys.stderr, "fileno"):
sys.stderr = sys.__stderr__
yield
finally:
Expand Down
3 changes: 1 addition & 2 deletions planemo/reports/xunit_handler.py
Expand Up @@ -5,5 +5,4 @@ def handle_report_xunit_kwd(kwds, collected_data):
if kwds.get('report_xunit', False):
with open(kwds['report_xunit'], 'w') as handle:
handle.write(template_data(
collected_data, template_name='xunit.tpl')
.encode('ascii', 'xmlcharrefreplace'))
collected_data, template_name='xunit.tpl'))
2 changes: 1 addition & 1 deletion planemo/tool_builder.py
Expand Up @@ -300,7 +300,7 @@ def _build_galaxy(**kwds):
# process raw cite urls
cite_urls = kwds.get("cite_url", [])
del kwds["cite_url"]
citations = map(UrlCitation, cite_urls)
citations = list(map(UrlCitation, cite_urls))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using a list comprehension here?

citations = [UrlCitation(url) for url in cite_urls]

Or, using the _ variable:

citations = [UrlCitation(_) for _ in cite_urls]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funnily we discussed this yesterday in a galaxy-lib PR: galaxyproject/galaxy-lib#88 (comment)

kwds["bibtex_citations"] = citations

# handle requirements and containers
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Expand Up @@ -11,8 +11,8 @@ jinja2
glob2
virtualenv
lxml
gxformat2>=0.1.1
gxformat2>=0.2.0
ephemeris>=0.2.0
galaxy-lib>=17.9.8
galaxy-lib>=17.9.12
html5lib>=0.9999999,!=0.99999999,!=0.999999999,!=1.0b10,!=1.0b09
cwltool==1.0.20170828135420
8 changes: 3 additions & 5 deletions tests/test_io.py
@@ -1,10 +1,8 @@
"""Test utilities from :module:`planemo.io`."""
import tempfile

from .test_utils import (
assert_equal,
io,
)
from planemo import io
from .test_utils import assert_equal


def test_io_capture():
Expand Down Expand Up @@ -40,7 +38,7 @@ def assert_filtered_is(paths, expected, **kwds):
assert_filtered_is(["/a/c"], [], exclude=["/a"])
assert_filtered_is(["/b"], ["/b"], exclude=["/a"])
assert_filtered_is(["/a/b/c"], [], exclude=["c"])
with tempfile.NamedTemporaryFile() as tmp:
with tempfile.NamedTemporaryFile(mode='w+') as tmp:
tmp.write("#exclude c\n\nc\n")
tmp.flush()
assert_filtered_is(["/a/b/c", "/a/b/d"], ["/a/b/d"], exclude_from=[tmp.name])
2 changes: 1 addition & 1 deletion tests/test_shed_upload.py
Expand Up @@ -138,7 +138,7 @@ def test_upload_from_git(self):
"git add .",
"git commit -m 'initial commit'"
]))
rev = git.rev(None, "single_tool").decode("UTF-8")
rev = git.rev(None, "single_tool")
upload_command = [
"shed_update", "--force_repository_creation",
"git+single_tool/.git"
Expand Down