Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Changes for macosx + remove code for python2
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Jan 12, 2019
1 parent 1395546 commit 077b621
Show file tree
Hide file tree
Showing 31 changed files with 112 additions and 103 deletions.
5 changes: 5 additions & 0 deletions _unittests/ut_helpgen/test_module_c.py
Expand Up @@ -7,6 +7,7 @@
import os
import unittest
import shutil
import warnings
from textwrap import dedent


Expand Down Expand Up @@ -215,6 +216,10 @@ def test_compile_module(self):
indexes = {}
add_file_rst(temp2, store_obj, actions, fLOG=fLOG,
rootrep=("stdchelper_demo.", ""), indexes=indexes)
if sys.platform == "darwin":
warnings.warn(
"add_file_rst does not work yet on MacOSX for C++ modules.")
return
self.assertNotEmpty(store_obj)
self.assertEqual(len(store_obj), 1)
if len(actions) not in (3, 4):
Expand Down
30 changes: 22 additions & 8 deletions _unittests/ut_loghelper/test_log.py
Expand Up @@ -10,8 +10,8 @@

if "temp_" in os.path.abspath(__file__):
raise ImportError(
"this file should not be imported in that location: " +
os.path.abspath(__file__))
"This file should not be imported in that location: {0}".format(
os.path.abspath(__file__)))

try:
import src
Expand Down Expand Up @@ -67,25 +67,37 @@ def test_cmd(self):
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
out, err = run_cmd("dir", shell=True, wait=True)
if sys.platform.startswith("win"):
cmd = "dir"
else:
cmd = "ls"
out, err = run_cmd(cmd, shell=True, wait=True)
assert len(out) > 0
out, err = run_cmd("dir *.pyc", shell=True, wait=True)
out, err = run_cmd(cmd + " *.pyc", shell=True, wait=True)
assert len(out) > 0

def test_cmd_noshell(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
out, err = run_cmd("dir", wait=True)
if sys.platform.startswith("win"):
cmd = "dir"
else:
cmd = "ls"
out, err = run_cmd(cmd, wait=True)
assert len(out) > 0

def test_cmd_communicate(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
out, err = run_cmd("dir", wait=True, communicate=True)
if sys.platform.startswith("win"):
cmd = "dir"
else:
cmd = "ls"
out, err = run_cmd(cmd, wait=True, communicate=True)
assert len(out) > 0

def test_cmd_communicate2(self):
Expand All @@ -94,9 +106,11 @@ def test_cmd_communicate2(self):
self._testMethodName,
OutputPrint=__name__ == "__main__")
if sys.platform.startswith("win"):
out, err = run_cmd("dir *.py", shell=True, wait=True, communicate=True)
out, err = run_cmd("dir *.py", shell=True,
wait=True, communicate=True)
else:
out, err = run_cmd("ls *.py", shell=True, wait=True, communicate=True)
out, err = run_cmd("ls *.py", shell=True,
wait=True, communicate=True)
self.assertNotEmpty(out)

def test_python(self):
Expand Down
11 changes: 9 additions & 2 deletions _unittests/ut_sphinxext/test_cmdref_extension.py
Expand Up @@ -22,7 +22,7 @@
import src

from src.pyquickhelper.loghelper.flog import fLOG
from src.pyquickhelper.pycode import get_temp_folder, ExtTestCase, is_travis_or_appveyor
from src.pyquickhelper.pycode import get_temp_folder, ExtTestCase, is_travis_or_appveyor, skipif_azure_macosx
from src.pyquickhelper.helpgen import rst2html
from src.pyquickhelper.sphinxext import CmdRef, CmdRefList
from src.pyquickhelper.sphinxext.sphinx_cmdref_extension import cmdref_node, visit_cmdref_node, depart_cmdref_node
Expand Down Expand Up @@ -251,7 +251,14 @@ def test_cmdref_quote(self):
if t1 in html:
raise Exception(html)

@skipif_azure_macosx("The Mac OS X backend will not be able to function correctly if Python is not installed as a framework.")
def test_cmdref_module(self):
"""
The test fails on MACOSX if it runs from a virtual envrionment.
See https://github.com/pypa/virtualenv/issues/609,
https://github.com/pypa/virtualenv/issues/54.
Or use https://docs.python.org/3/library/venv.html.
"""
fLOG(
__file__,
self._testMethodName,
Expand All @@ -264,7 +271,7 @@ def test_cmdref_module(self):
self.assertExists(path)
from docutils import nodes as skip_

if is_travis_or_appveyor() == "azurepipe":
if is_travis_or_appveyor() == "azurepipe" and sys.platform == "darwin":
import matplotlib as mpl
mpl.use('TkAgg')

Expand Down
6 changes: 2 additions & 4 deletions src/pyquickhelper/filehelper/anyfhelper.py
Expand Up @@ -143,8 +143,7 @@ def read_content_ufs(file_url_stream, encoding="utf8", asbytes=False, add_source
The function can return bytes.
"""
if isinstance(file_url_stream, str # unicode#
):
if isinstance(file_url_stream, str):
if is_file_string(file_url_stream) and os.path.exists(file_url_stream):
if asbytes:
with open(file_url_stream, "rb") as f:
Expand All @@ -169,8 +168,7 @@ def read_content_ufs(file_url_stream, encoding="utf8", asbytes=False, add_source
return (content, "u") if add_source else content
else:
# the string should the content itself
if isinstance(file_url_stream, str # unicode#
):
if isinstance(file_url_stream, str):
if asbytes:
raise TypeError(
"file_url_stream is str when expected bytes")
Expand Down
3 changes: 1 addition & 2 deletions src/pyquickhelper/filehelper/encrypted_backup.py
Expand Up @@ -116,8 +116,7 @@ def __init__(self, key, file_tree_node, transfer_api,
self._root_local = root_local if root_local is not None else (
file_tree_node.root if file_tree_node else None)
self._root_remote = root_remote if root_remote is not None else ""
if filter_out is not None and not isinstance(filter_out, str # unicode#
):
if filter_out is not None and not isinstance(filter_out, str):
self._filter_out = filter_out
else:
self._filter_out_reg = None if filter_out is None else re.compile(
Expand Down
3 changes: 1 addition & 2 deletions src/pyquickhelper/filehelper/file_tree_node.py
Expand Up @@ -118,8 +118,7 @@ def __init__(self, root, file=None, filter=None, level=0, parent=None,

self._fillstat()
if self.isdir():
if isinstance(filter, str # unicode#
):
if isinstance(filter, str):
# it assumes it is a regular expression instead of a function
exp = re.compile(filter)

Expand Down
4 changes: 2 additions & 2 deletions src/pyquickhelper/filehelper/files_status.py
Expand Up @@ -78,7 +78,7 @@ def save_dates(self, checkfile=None):
@param checkfile check the status for file checkfile
"""
typstr = str # unicode#
typstr = str
if checkfile is None:
checkfile = []
rows = []
Expand Down Expand Up @@ -118,7 +118,7 @@ def has_been_modified_and_reason(self, file):
"""
res = True
reason = None
typstr = str # unicode#
typstr = str

if file not in self.copyFiles:
reason = "new"
Expand Down
6 changes: 2 additions & 4 deletions src/pyquickhelper/filehelper/ftp_transfer.py
Expand Up @@ -281,8 +281,7 @@ def transfer(self, file, to, name, debug=False, blocksize=None, callback=None):
bs = blocksize if blocksize else TransferFTP.blockSize
if exc is None:
try:
if isinstance(file, str # unicode#
):
if isinstance(file, str):
if not os.path.exists(file):
raise FileNotFoundError(file)
with open(file, "rb") as f:
Expand Down Expand Up @@ -357,8 +356,7 @@ def retrieve(self, fold, name, file, debug=False):

raise_exc = None

if isinstance(file, str # unicode#
):
if isinstance(file, str):
with open(file, "wb") as f:
def callback(block):
f.write(block)
Expand Down
3 changes: 1 addition & 2 deletions src/pyquickhelper/filehelper/ftp_transfer_files.py
Expand Up @@ -152,8 +152,7 @@ def filter_out(full_file_name, filename):
self._is_binary = is_binary
self._exc = exc
self._force_allow = force_allow
if filter_out is not None and not isinstance(filter_out, str # unicode#
):
if filter_out is not None and not isinstance(filter_out, str):
self._filter_out = filter_out
else:
self._filter_out_reg = None if filter_out is None else re.compile(
Expand Down
5 changes: 2 additions & 3 deletions src/pyquickhelper/filehelper/synchelper.py
Expand Up @@ -283,7 +283,7 @@ def filter_copy(file):
def mytrue(v):
return True

typstr = str # unicode#
typstr = str
if filter is None:
tfilter = mytrue
elif isinstance(filter, typstr):
Expand All @@ -305,8 +305,7 @@ def pr_filter(root, path, f, d):
be = os.path.join(path, f)
return tfilter(be)

if isinstance(filter_copy, str # unicode#
):
if isinstance(filter_copy, str):
rg = re.compile(filter_copy)

def regtrue2(f):
Expand Down
4 changes: 2 additions & 2 deletions src/pyquickhelper/helpgen/conf_path_tools.py
Expand Up @@ -50,7 +50,7 @@ def find_graphviz_dot(exc=True):
p = find_in_PATH("dot.exe")
if p is None:
if exc:
typstr = str # unicode#
typstr = str
raise FileNotFoundError(
"unable to find graphviz, look into paths such as: " + typstr(graphviz_dot))
else:
Expand All @@ -77,7 +77,7 @@ def find_latex_path(exc=True):
latex = find_in_PATH("latex.exe")
if latex is None or not os.path.exists(latex):
if exc:
typstr = str # unicode#
typstr = str
raise FileNotFoundError(
"unable to find latex (miktex), look into paths such as: " + typstr(latex0))
else:
Expand Down
3 changes: 1 addition & 2 deletions src/pyquickhelper/helpgen/sphinx_main.py
Expand Up @@ -285,8 +285,7 @@ def generate_help_sphinx(project_var_name, clean=False, root=".",
extra_ext = []

def lay_build_override_newconf(t3):
if isinstance(t3, str # unicode#
):
if isinstance(t3, str):
lay, build, override, newconf = t3, "build", {}, None
elif len(t3) == 1:
lay, build, override, newconf = t3[0], "build", {}, None
Expand Down
4 changes: 2 additions & 2 deletions src/pyquickhelper/helpgen/sphinx_main_helper.py
Expand Up @@ -135,7 +135,7 @@ def to_str(x):
x = list(range(len(xl)))
y = list(gr["commits"])

typstr = str # unicode#
typstr = str

code = """
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -221,7 +221,7 @@ def generate_changes_repo(chan, source, exception_if_empty=True,
rows.append(
"""\n.. _l-changes:\n\n\nChanges\n=======\n\n__CODEGRAPH__\n\nList of recent changes:\n""")

typstr = str # unicode#
typstr = str

values = []
for i, row in enumerate(logs):
Expand Down
3 changes: 1 addition & 2 deletions src/pyquickhelper/helpgen/sphinx_main_missing_html_files.py
Expand Up @@ -98,8 +98,7 @@ def add_missing_files(root, conf, blog_list):
"""<a href="{{ pathto('',1) }}/py-modindex.html">Module</a>\n""")
f.write(
"""<h3><a href="{{ pathto('',1) }}/blog/main_0000.html">Blog</a></h3>\n""")
if isinstance(blog_list, str # unicode#
):
if isinstance(blog_list, str):
f.write(blog_list)
elif isinstance(blog_list, list):
f.write("\n<br />".join(blog_list))
Expand Down
17 changes: 9 additions & 8 deletions src/pyquickhelper/helpgen/utils_sphinx_doc.py
Expand Up @@ -397,6 +397,10 @@ def apply_modification_template(rootm, store_obj, template, fullname, rootrep,
threader_module_clear,
NULL
};
.. warning::
This function still needs some improvments
for C++ modules on MacOSX.
"""
from pandas import DataFrame

Expand Down Expand Up @@ -428,8 +432,7 @@ def apply_modification_template(rootm, store_obj, template, fullname, rootrep,
tspecials = {}

if mo is not None:
if isinstance(mo, str # unicode#
):
if isinstance(mo, str):
# it is an error
spl = mo.split("\n")
mo = "\n".join([" " + _ for _ in spl])
Expand Down Expand Up @@ -464,7 +467,7 @@ def apply_modification_template(rootm, store_obj, template, fullname, rootrep,
doc = ""
shortdoc = "empty"

# we produce the table for the function, classes, and
# it produces the table for the function, classes, and
objs = get_module_objects(mo)

prefix = ".".join(fullnamenoext.split(".")[:-1])
Expand Down Expand Up @@ -624,8 +627,7 @@ def add_file_rst(rootm, store_obj, actions, template=add_file_rst_template,
app = []
for action in actions:
_, file, dest = action[:3]
if not isinstance(file, str # unicode#
):
if not isinstance(file, str):
file = file.name

to = os.path.join(dest, file)
Expand Down Expand Up @@ -1039,8 +1041,7 @@ def prepare_file_for_sphinx_help_generation(store_obj, input, output,
indexes = {}

for sub in subfolders:
if isinstance(sub, str # unicode#
):
if isinstance(sub, str):
src = (input + "/" + sub).replace("//", "/")
dst = (output + "/" + sub).replace("//", "/")
else:
Expand Down Expand Up @@ -1524,7 +1525,7 @@ def _private_migrating_doxygen_doc(rows, index_first_line, filename,
openi = False
beginends = {}

typstr = str # unicode#
typstr = str

whole = "\n".join(rows)
if "@var" in whole:
Expand Down
8 changes: 4 additions & 4 deletions src/pyquickhelper/helpgen/utils_sphinx_doc_helpers.py
Expand Up @@ -194,7 +194,7 @@ def __init__(self, obj, ty=None, cl=None, name=None, module=None):
self.name = name
self.populate()

typstr = str # unicode#
typstr = str

if self.cl is None and self.type in [
"method", "staticmethod", "property"]:
Expand Down Expand Up @@ -224,7 +224,7 @@ def populate(self):
"""
obj = self.obj
ty = self.type if "type" in self.__dict__ else None
typstr = str # unicode#
typstr = str
if ty is None:
if inspect.isclass(obj):
self.type = "class"
Expand Down Expand Up @@ -908,12 +908,12 @@ def accept(c):
try:
r = "".join(map(accept, title))
if len(r) == 0:
typstr = str # unicode#
typstr = str
raise HelpGenException("unable to interpret this title (empty?): {0} (type: {2})\nCOMMENT:\n{1}".format(
typstr(title), comment, typstr(type(title))))
return r
except TypeError as e:
typstr = str # unicode#
typstr = str
raise HelpGenException("unable to interpret this title: {0} (type: {2})\nCOMMENT:\n{1}".format(
typstr(title), comment, typstr(type(title)))) from e

Expand Down
4 changes: 2 additions & 2 deletions src/pyquickhelper/ipythonhelper/magic_parser.py
Expand Up @@ -34,7 +34,7 @@ def _private_get_name(*args):
"""
if args == ('-h', '--help'):
return "help"
typstr = str # unicode#
typstr = str
for a in args:
if isinstance(a, typstr):
if a[0] != "-":
Expand Down Expand Up @@ -177,7 +177,7 @@ def eval(self, value, context, fLOG=noLOG):
The method interprets variable inside list, tuple or dictionaries (for *value*).
"""
typstr = str # unicode#
typstr = str
if isinstance(value, typstr):
if value in context:
return context[value]
Expand Down

0 comments on commit 077b621

Please sign in to comment.