Skip to content

Commit

Permalink
Few changes to be python 2.7 compatible
Browse files Browse the repository at this point in the history
- Fixed a typo in MANIFEST.in as well
- Moved coverage config out of tox.ini and into .coveragerc
  • Loading branch information
fchorney committed Nov 8, 2018
1 parent 4ffaa34 commit 724af63
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
10 changes: 10 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[report]
show_missing = True
skip_covered = True
precision = 2
exclude_lines =
# Ignore unreachable code
if __name__ == .__main__.:

# Specifically ignore a line with this text
pragma: no cover
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
sudo: false
language: python
python:
- "2.7"
- "3.6"
install:
- pip install tox-travis
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include README.rst
include README.md
include LICENSE
include CHANGES.rst
12 changes: 6 additions & 6 deletions sphinxcontrib/runcmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
RE_SPLIT = re.compile(r"(?P<pattern>.*)(?<!\\)/(?P<replacement>.*)")


class CMDCache(object, metaclass=Singleton): # noqa: E999
__metaclass__ = Singleton
class CMDCache(Singleton): # noqa: E999
cache = {}

def get(self, cmd):
Expand All @@ -32,16 +31,17 @@ def get(self, cmd):
def run_command(command):
true_cmd = shlex.split(command)
try:
result = subprocess.run(
subp = subprocess.Popen(
true_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
except Exception as e:
out = ""
err = e
else:
out, err = subp.communicate()
encoding = sys.getfilesystemencoding()
out = result.stdout.decode(encoding, "replace").rstrip()
err = result.stderr.decode(encoding, "replace").rstrip()
out = out.decode(encoding, "replace").rstrip()
err = err.decode(encoding, "replace").rstrip()

if err and err != "":
print("Error in runcmd: {}".format(err))
Expand Down Expand Up @@ -109,7 +109,7 @@ def run(self):
# Set up our arguments to run the CodeBlock parent run function
self.arguments[0] = syntax
self.content = [output]
node = super().run()
node = super(RunCmdDirective, self).run()

return node

Expand Down
8 changes: 6 additions & 2 deletions sphinxcontrib/runcmd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
"""


class Singleton(type):
class _Singleton(type):
_instances = {}

def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]


class Singleton(_Singleton("SingletonMeta", (object,), {})):
pass
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from sphinxcontrib.runcmd.utils import Singleton


class TheSingleton(object, metaclass=Singleton): # noqa: E999
class TheSingleton(Singleton):
pass


Expand Down
19 changes: 6 additions & 13 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
[tox]
envlist = formatting, py36
envlist = formatting, py27, py36, coverage

[testenv]
usedevelop = True
deps = .[test]
setenv =
PYTHONPATH = {toxinidir}
commands = py.test --cov-config=tox.ini --cov=sphinxcontrib --verbose --tb=long
py{27,36}: COVERAGE_FILE={envdir}/.coverage
commands =
py{27,36}: py.test --cov=sphinxcontrib --verbose --tb=long
coverage: /usr/bin/env bash -c "{envpython} -m coverage combine {toxworkdir}/py*/.coverage"
coverage: coverage report

[testenv:formatting]
basepython = python3.6
Expand Down Expand Up @@ -35,14 +39,3 @@ not_skip=__init__.py
max-line-length = 88
ignore = E203
inline-quotes = double

[report]
show_missing = True
skip_covered = True
precision = 2
exclude_lines =
# Ignore unreachable code
if __name__ == .__main__.:

# Specifically ignore a line with this text
pragma: no cover

0 comments on commit 724af63

Please sign in to comment.