From f4c0ed66f34593d8caa5cfb92e0d2aee765a3395 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Thu, 25 Jun 2020 19:34:21 -0400 Subject: [PATCH 01/24] some changes to file reading --- bpython/importcompletion.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/bpython/importcompletion.py b/bpython/importcompletion.py index 0fbc46d58..189ebe404 100644 --- a/bpython/importcompletion.py +++ b/bpython/importcompletion.py @@ -35,6 +35,7 @@ import os import sys import warnings +import re from six.moves import filter if py3: @@ -134,6 +135,10 @@ def complete(cursor_offset, line): def find_modules(path): """Find all modules (and packages) for a given directory.""" + + global nameSubname + nameSubname = [] + if not os.path.isdir(path): # Perhaps a zip file return @@ -192,8 +197,21 @@ def find_modules(path): if is_package: for subname in find_modules(pathname): if subname != "__init__": - yield "%s.%s" % (name, subname) + doNotAppend = False + for obj in nameSubname: + nam = obj[0] + subnam = obj[1] + if (name == nam and subname == subnam) or \ + any(nam in sub for sub in re.split("[.]", subname)) or \ + any(subname in na for na in re.split("[.]", name)): + doNotAppend = True + break + if not doNotAppend: + nameSubname.append((name, subname)) + yield "%s.%s" % (name, subname) yield name + for obj in nameSubname: + print(obj[0] + " " + obj[1]) def find_all_modules(path=None): From 347707dde58c33055356c743494181ee9b8cb7b8 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Fri, 26 Jun 2020 15:16:35 -0400 Subject: [PATCH 02/24] Some work on symbolic link files --- bpython/importcompletion.py | 69 +++++++++++++----- importtest.py | 72 +++++++++++++++++++ importtestfolder/Level0/Level1/Level2/Level3 | 1 + .../Level0/Level1/Level2/__init__.py | 0 importtestfolder/Level0/Level1/__init__.py | 0 importtestfolder/Level0/__init__.py | 0 importtestfolder/__init__.py | 0 7 files changed, 126 insertions(+), 16 deletions(-) create mode 100644 importtest.py create mode 120000 importtestfolder/Level0/Level1/Level2/Level3 create mode 100644 importtestfolder/Level0/Level1/Level2/__init__.py create mode 100644 importtestfolder/Level0/Level1/__init__.py create mode 100644 importtestfolder/Level0/__init__.py create mode 100644 importtestfolder/__init__.py diff --git a/bpython/importcompletion.py b/bpython/importcompletion.py index 189ebe404..88a95fd31 100644 --- a/bpython/importcompletion.py +++ b/bpython/importcompletion.py @@ -139,6 +139,9 @@ def find_modules(path): global nameSubname nameSubname = [] + #global pathNameList + #pathNameList = [] + if not os.path.isdir(path): # Perhaps a zip file return @@ -195,23 +198,57 @@ def find_modules(path): continue else: if is_package: - for subname in find_modules(pathname): - if subname != "__init__": - doNotAppend = False - for obj in nameSubname: - nam = obj[0] - subnam = obj[1] - if (name == nam and subname == subnam) or \ - any(nam in sub for sub in re.split("[.]", subname)) or \ - any(subname in na for na in re.split("[.]", name)): - doNotAppend = True - break - if not doNotAppend: - nameSubname.append((name, subname)) - yield "%s.%s" % (name, subname) + pathGood = True + #print("pathname:", pathname) + #for paths in pathNameList: + #print(paths) + #print("Hi") + + #if pathname == paths: + #pathGood = False + #break + + pathList = re.split("[/]", pathname) + #print("pathL length:", len(pathList)) + #for pathL in pathList: + #print("pathL:", pathL) + + for folder in range(len(pathList)): + for folderT in range(len(pathList)): + #print("folder:", folder, "folderT:", folderT) + #print("Pathlist Folder:", pathList[folder], "Pathlist FolderT:", pathList[folderT]) + if folder == folderT: + continue + elif pathList[folder] == pathList[folderT]: + pathGood = False + #print(pathGood) + #print() + if pathGood: + #pathNameList.append(pathname) + #print("PathGood len", len(pathNameList), pathname) + for subname in find_modules(pathname): + if subname != "__init__": + #doNotAppend = False + #print("name: ", name, " subname: ", subname) + #for obj in nameSubname: + #nam = obj[0] + #subnam = obj[1] + #print("name: ", name, " nam: ", nam, " subname: ", subname, " subnam: ", subnam) + #if (name == nam and subname == subnam) or \ + #any(name in sub for sub in re.split("[.]", subnam)): + #print("Excluded: ", name, subname, "because ", nam, subnam) + #doNotAppend = True + #break + #print() + #if not doNotAppend: + #nameSubname.append((name, subname)) + #print(name, subname) + yield "%s.%s" % (name, subname) yield name for obj in nameSubname: - print(obj[0] + " " + obj[1]) + #print(obj[0] + " " + obj[1]) + pass + #print("PathNameList len:", len(pathNameList)) def find_all_modules(path=None): @@ -220,7 +257,7 @@ def find_all_modules(path=None): if path is None: modules.update(try_decode(m, "ascii") for m in sys.builtin_module_names) path = sys.path - + path = ['/Users/eerichart/bpython'] for p in path: if not p: p = os.curdir diff --git a/importtest.py b/importtest.py new file mode 100644 index 000000000..6b3380db0 --- /dev/null +++ b/importtest.py @@ -0,0 +1,72 @@ +from bpython.importcompletion import find_modules +import os + +foo = find_modules(os.path.abspath("./importtestfolder")) + +for thing in foo: + print(thing) + +#for obj in foo.nameSubname: + #print(obj[0] + " " + obj[1]) + +#bpython import_completion yield name | #bpython import yield name subname and yield name +#bpdb | #bpdb +#__pycache__ | #__pycache__ +# | #bpython __pycache__ +#__pycache__ | #__pycache__ +# | #curtsiesfrontend __pycache__ +# | #bpython curtsiesfrontend.__pycache__ +#curtsiesfrontend | #curtsiesfrontend +# | #bpython curtsiesfrontend +#fodder | #fodder +# | #test fodder +# | #bpython test.fodder +#test | #test +# | #bpython test +#__pycache__ | #__pycache__ +# | #translations __pycache__ +# | #bpython translations.__pycache__ +#LC_MESSAGES | #LC_MESSAGES +# | #de LC_MESSAGES +# | #translations de.LC_MESSAGES +# | #bpython translations.de.LC_MESSAGES +#de | #de +#LC_MESSAGES | #LC_MESSAGES +# | #es_ES LC_MESSAGES +# | #translations es_ES.LC_MESSAGES +# | #bpython translations.es_ES.LC_MESSAGES +#es_ES | #es_ES +#LC_MESSAGES | #LC_MESSAGES +# | #fr_FR LC_MESSAGES +# | #translations fr_FR.LC_MESSAGES +# | #bpython translations.fr_FR.LC_MESSAGES +#fr_FR | #fr_FR +#LC_MESSAGES | #LC_MESSAGES +# | #it_IT LC_MESSAGES +# | #translations it_IT.LC_MESSAGES +# | #bpython translations.it_IT.LC_MESSAGES +#it_IT | #it_IT +#LC_MESSAGES | #LC_MESSAGES +# | #nl_NL LC_MESSAGES +# | #translations nl_NL.LC_MESSAGES +# | #bpython translations.nl_NL.LC_MESSAGES +#nl_NL | #nl_NL +#translations | #translations +# | #bpython translations +#bpython | #bpython +#data | #data +#source | #source +# | #sphinx source +# | #doc sphinx.source +#sphinx | #sphinx +# | #doc sphinx +#doc | #doc +#Level2 | #Level2 +# | #Level1 Level2 +# | #Level0 Level1.Level2 +# | #importtestfolder Level0.Level1.Level2 +#Level1 | #Level1 +#Level0 | #Level0 +# | #importtestfolder Level0 +#importtestfolder | #importtestfolder +#pip-wheel-metadata | #pip-wheel-metadata \ No newline at end of file diff --git a/importtestfolder/Level0/Level1/Level2/Level3 b/importtestfolder/Level0/Level1/Level2/Level3 new file mode 120000 index 000000000..0eb0122bd --- /dev/null +++ b/importtestfolder/Level0/Level1/Level2/Level3 @@ -0,0 +1 @@ +/Users/eerichart/bpython/importtestfolder/Level0/Level1 \ No newline at end of file diff --git a/importtestfolder/Level0/Level1/Level2/__init__.py b/importtestfolder/Level0/Level1/Level2/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/importtestfolder/Level0/Level1/__init__.py b/importtestfolder/Level0/Level1/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/importtestfolder/Level0/__init__.py b/importtestfolder/Level0/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/importtestfolder/__init__.py b/importtestfolder/__init__.py new file mode 100644 index 000000000..e69de29bb From 3f13a28574b61bab7fc36da0bbe818fec8af7105 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Fri, 26 Jun 2020 15:35:20 -0400 Subject: [PATCH 03/24] Cleaned up symlink fix ideas --- bpython/importcompletion.py | 36 ++++++++---------------------------- importtest.py | 5 +---- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/bpython/importcompletion.py b/bpython/importcompletion.py index 88a95fd31..5b6956271 100644 --- a/bpython/importcompletion.py +++ b/bpython/importcompletion.py @@ -136,11 +136,8 @@ def complete(cursor_offset, line): def find_modules(path): """Find all modules (and packages) for a given directory.""" - global nameSubname - nameSubname = [] - - #global pathNameList - #pathNameList = [] + #global nameSubname + #nameSubname = [] if not os.path.isdir(path): # Perhaps a zip file @@ -199,28 +196,15 @@ def find_modules(path): else: if is_package: pathGood = True - #print("pathname:", pathname) - #for paths in pathNameList: - #print(paths) - #print("Hi") - - #if pathname == paths: - #pathGood = False - #break pathList = re.split("[/]", pathname) #print("pathL length:", len(pathList)) #for pathL in pathList: #print("pathL:", pathL) - for folder in range(len(pathList)): - for folderT in range(len(pathList)): - #print("folder:", folder, "folderT:", folderT) - #print("Pathlist Folder:", pathList[folder], "Pathlist FolderT:", pathList[folderT]) - if folder == folderT: - continue - elif pathList[folder] == pathList[folderT]: - pathGood = False + for folder in range(len(pathList) - 2): + if pathList[folder] == pathList[len(pathList) - 1]: + pathGood = False #print(pathGood) #print() if pathGood: @@ -242,14 +226,10 @@ def find_modules(path): #print() #if not doNotAppend: #nameSubname.append((name, subname)) - #print(name, subname) - yield "%s.%s" % (name, subname) + print(name, subname) + yield "%s.%s" % (name, subname) + print(name) yield name - for obj in nameSubname: - #print(obj[0] + " " + obj[1]) - pass - #print("PathNameList len:", len(pathNameList)) - def find_all_modules(path=None): """Return a list with all modules in `path`, which should be a list of diff --git a/importtest.py b/importtest.py index 6b3380db0..836fb0816 100644 --- a/importtest.py +++ b/importtest.py @@ -4,10 +4,7 @@ foo = find_modules(os.path.abspath("./importtestfolder")) for thing in foo: - print(thing) - -#for obj in foo.nameSubname: - #print(obj[0] + " " + obj[1]) + pass #bpython import_completion yield name | #bpython import yield name subname and yield name #bpdb | #bpdb From 47ea5ee6728f032664d5a150e1ddfe59e1059fe4 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Fri, 26 Jun 2020 15:37:57 -0400 Subject: [PATCH 04/24] More clean up --- bpython/importcompletion.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bpython/importcompletion.py b/bpython/importcompletion.py index 5b6956271..0954e3e4a 100644 --- a/bpython/importcompletion.py +++ b/bpython/importcompletion.py @@ -237,7 +237,7 @@ def find_all_modules(path=None): if path is None: modules.update(try_decode(m, "ascii") for m in sys.builtin_module_names) path = sys.path - path = ['/Users/eerichart/bpython'] + for p in path: if not p: p = os.curdir From 6eff3b2ca6ea228772be8e381a6a225372fc7520 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Fri, 26 Jun 2020 16:20:11 -0400 Subject: [PATCH 05/24] Make it easier to test different methods --- bpython/importcompletion.py | 85 ++++++++++++++++++++++--------------- importtest.py | 64 +--------------------------- 2 files changed, 52 insertions(+), 97 deletions(-) diff --git a/bpython/importcompletion.py b/bpython/importcompletion.py index 0954e3e4a..362c7a70c 100644 --- a/bpython/importcompletion.py +++ b/bpython/importcompletion.py @@ -136,8 +136,14 @@ def complete(cursor_offset, line): def find_modules(path): """Find all modules (and packages) for a given directory.""" - #global nameSubname - #nameSubname = [] + global nameSubname + nameSubname = [] + + #Decides if you are using the first method: usng name subname (1), + # the second method: using pathname (2) or the original (3) + global useNameSubname + useNameSubname = 3 + #print("useNameSubname:", useNameSubname) if not os.path.isdir(path): # Perhaps a zip file @@ -195,40 +201,51 @@ def find_modules(path): continue else: if is_package: - pathGood = True - - pathList = re.split("[/]", pathname) - #print("pathL length:", len(pathList)) - #for pathL in pathList: - #print("pathL:", pathL) - - for folder in range(len(pathList) - 2): - if pathList[folder] == pathList[len(pathList) - 1]: - pathGood = False - #print(pathGood) - #print() - if pathGood: - #pathNameList.append(pathname) - #print("PathGood len", len(pathNameList), pathname) + pathGood = False + if useNameSubname == 2: + pathGood = True + + pathList = re.split("[/]", pathname) + #print("pathL length:", len(pathList)) + #for pathL in pathList: + #print("pathL:", pathL) + + #I did path len - 2 because I am worried about folders like bpython/bpython + # but if it is a symbolic link it will stop at bpython/bpython/bpython + for folder in range(len(pathList) - 2): + if pathList[folder] == pathList[len(pathList) - 1]: + pathGood = False + #print(pathGood) + #print() + if useNameSubname == 1 or pathGood: + for subname in find_modules(pathname): + if subname != "__init__": + #If trying the first method using name and subname + if useNameSubname == 1: + doNotAppend = False + #print("name: ", name, " subname: ", subname) + for obj in nameSubname: + nam = obj[0] + subnam = obj[1] + #print("name: ", name, " nam: ", nam, " subname: ", subname, " subnam: ", subnam) + if (name == nam and subname == subnam) or \ + any(name in sub for sub in re.split("[.]", subnam)): + #print("Excluded: ", name, subname, "because ", nam, subnam) + doNotAppend = True + break + #print() + if not doNotAppend: + nameSubname.append((name, subname)) + #print(name, subname) + yield "%s.%s" % (name, subname) + #If trying seconf methond using the pathname + else: + yield "%s.%s" % (name, subname) + elif useNameSubname == 3: for subname in find_modules(pathname): if subname != "__init__": - #doNotAppend = False - #print("name: ", name, " subname: ", subname) - #for obj in nameSubname: - #nam = obj[0] - #subnam = obj[1] - #print("name: ", name, " nam: ", nam, " subname: ", subname, " subnam: ", subnam) - #if (name == nam and subname == subnam) or \ - #any(name in sub for sub in re.split("[.]", subnam)): - #print("Excluded: ", name, subname, "because ", nam, subnam) - #doNotAppend = True - #break - #print() - #if not doNotAppend: - #nameSubname.append((name, subname)) - print(name, subname) - yield "%s.%s" % (name, subname) - print(name) + yield "%s.%s" % (name, subname) + #print("Name: ", name) yield name def find_all_modules(path=None): diff --git a/importtest.py b/importtest.py index 836fb0816..2dce5fa37 100644 --- a/importtest.py +++ b/importtest.py @@ -4,66 +4,4 @@ foo = find_modules(os.path.abspath("./importtestfolder")) for thing in foo: - pass - -#bpython import_completion yield name | #bpython import yield name subname and yield name -#bpdb | #bpdb -#__pycache__ | #__pycache__ -# | #bpython __pycache__ -#__pycache__ | #__pycache__ -# | #curtsiesfrontend __pycache__ -# | #bpython curtsiesfrontend.__pycache__ -#curtsiesfrontend | #curtsiesfrontend -# | #bpython curtsiesfrontend -#fodder | #fodder -# | #test fodder -# | #bpython test.fodder -#test | #test -# | #bpython test -#__pycache__ | #__pycache__ -# | #translations __pycache__ -# | #bpython translations.__pycache__ -#LC_MESSAGES | #LC_MESSAGES -# | #de LC_MESSAGES -# | #translations de.LC_MESSAGES -# | #bpython translations.de.LC_MESSAGES -#de | #de -#LC_MESSAGES | #LC_MESSAGES -# | #es_ES LC_MESSAGES -# | #translations es_ES.LC_MESSAGES -# | #bpython translations.es_ES.LC_MESSAGES -#es_ES | #es_ES -#LC_MESSAGES | #LC_MESSAGES -# | #fr_FR LC_MESSAGES -# | #translations fr_FR.LC_MESSAGES -# | #bpython translations.fr_FR.LC_MESSAGES -#fr_FR | #fr_FR -#LC_MESSAGES | #LC_MESSAGES -# | #it_IT LC_MESSAGES -# | #translations it_IT.LC_MESSAGES -# | #bpython translations.it_IT.LC_MESSAGES -#it_IT | #it_IT -#LC_MESSAGES | #LC_MESSAGES -# | #nl_NL LC_MESSAGES -# | #translations nl_NL.LC_MESSAGES -# | #bpython translations.nl_NL.LC_MESSAGES -#nl_NL | #nl_NL -#translations | #translations -# | #bpython translations -#bpython | #bpython -#data | #data -#source | #source -# | #sphinx source -# | #doc sphinx.source -#sphinx | #sphinx -# | #doc sphinx -#doc | #doc -#Level2 | #Level2 -# | #Level1 Level2 -# | #Level0 Level1.Level2 -# | #importtestfolder Level0.Level1.Level2 -#Level1 | #Level1 -#Level0 | #Level0 -# | #importtestfolder Level0 -#importtestfolder | #importtestfolder -#pip-wheel-metadata | #pip-wheel-metadata \ No newline at end of file + print("YIELD:", thing) \ No newline at end of file From 8e08f3a7b963b36466449cc2e6b57f6df671b7d0 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Fri, 26 Jun 2020 16:56:15 -0400 Subject: [PATCH 06/24] Found an even better way. useNameSubname = 4 --- bpython/importcompletion.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bpython/importcompletion.py b/bpython/importcompletion.py index 362c7a70c..37135423f 100644 --- a/bpython/importcompletion.py +++ b/bpython/importcompletion.py @@ -140,9 +140,9 @@ def find_modules(path): nameSubname = [] #Decides if you are using the first method: usng name subname (1), - # the second method: using pathname (2) or the original (3) + # the second method: using pathname (2) or the original (3), os.realpath global useNameSubname - useNameSubname = 3 + useNameSubname = 4 #print("useNameSubname:", useNameSubname) if not os.path.isdir(path): @@ -217,6 +217,12 @@ def find_modules(path): pathGood = False #print(pathGood) #print() + elif useNameSubname == 4: + pathGood = True + pathReal = os.path.realpath(pathname) + if len(pathReal) < len(pathname) and pathReal in pathname: + #print("PathReal:", pathReal, "Path:", pathname) + pathGood = False if useNameSubname == 1 or pathGood: for subname in find_modules(pathname): if subname != "__init__": From 2b96e8d69ace845794102d398e361e6f2da5b6f1 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Mon, 29 Jun 2020 16:40:34 -0400 Subject: [PATCH 07/24] "Used os.path.realpath to fix issue" --- bpython/importcompletion.py | 55 ++++-------------------------- importtestfolder/Left/__init__.py | 0 importtestfolder/Left/toRight | 1 + importtestfolder/Right/__init__.py | 0 importtestfolder/Right/toLeft | 1 + 5 files changed, 8 insertions(+), 49 deletions(-) create mode 100644 importtestfolder/Left/__init__.py create mode 120000 importtestfolder/Left/toRight create mode 100644 importtestfolder/Right/__init__.py create mode 120000 importtestfolder/Right/toLeft diff --git a/bpython/importcompletion.py b/bpython/importcompletion.py index 37135423f..c8c3f015e 100644 --- a/bpython/importcompletion.py +++ b/bpython/importcompletion.py @@ -201,57 +201,14 @@ def find_modules(path): continue else: if is_package: - pathGood = False - if useNameSubname == 2: - pathGood = True - - pathList = re.split("[/]", pathname) - #print("pathL length:", len(pathList)) - #for pathL in pathList: - #print("pathL:", pathL) - - #I did path len - 2 because I am worried about folders like bpython/bpython - # but if it is a symbolic link it will stop at bpython/bpython/bpython - for folder in range(len(pathList) - 2): - if pathList[folder] == pathList[len(pathList) - 1]: - pathGood = False - #print(pathGood) - #print() - elif useNameSubname == 4: - pathGood = True - pathReal = os.path.realpath(pathname) - if len(pathReal) < len(pathname) and pathReal in pathname: - #print("PathReal:", pathReal, "Path:", pathname) - pathGood = False - if useNameSubname == 1 or pathGood: + pathGood = True + pathReal = os.path.realpath(pathname) + if len(pathReal) < len(pathname) and pathReal in pathname: + pathGood = False + if pathGood: for subname in find_modules(pathname): if subname != "__init__": - #If trying the first method using name and subname - if useNameSubname == 1: - doNotAppend = False - #print("name: ", name, " subname: ", subname) - for obj in nameSubname: - nam = obj[0] - subnam = obj[1] - #print("name: ", name, " nam: ", nam, " subname: ", subname, " subnam: ", subnam) - if (name == nam and subname == subnam) or \ - any(name in sub for sub in re.split("[.]", subnam)): - #print("Excluded: ", name, subname, "because ", nam, subnam) - doNotAppend = True - break - #print() - if not doNotAppend: - nameSubname.append((name, subname)) - #print(name, subname) - yield "%s.%s" % (name, subname) - #If trying seconf methond using the pathname - else: - yield "%s.%s" % (name, subname) - elif useNameSubname == 3: - for subname in find_modules(pathname): - if subname != "__init__": - yield "%s.%s" % (name, subname) - #print("Name: ", name) + yield "%s.%s" % (name, subname) yield name def find_all_modules(path=None): diff --git a/importtestfolder/Left/__init__.py b/importtestfolder/Left/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/importtestfolder/Left/toRight b/importtestfolder/Left/toRight new file mode 120000 index 000000000..044f3e5dc --- /dev/null +++ b/importtestfolder/Left/toRight @@ -0,0 +1 @@ +/Users/eerichart/bpython/importtestfolder/Right \ No newline at end of file diff --git a/importtestfolder/Right/__init__.py b/importtestfolder/Right/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/importtestfolder/Right/toLeft b/importtestfolder/Right/toLeft new file mode 120000 index 000000000..064170877 --- /dev/null +++ b/importtestfolder/Right/toLeft @@ -0,0 +1 @@ +/Users/eerichart/bpython/importtestfolder/Left \ No newline at end of file From 44f76f7fbd1655748a74167d45d3c712b5444033 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Mon, 29 Jun 2020 16:47:47 -0400 Subject: [PATCH 08/24] Removed code that I was using for testing --- bpython/importcompletion.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/bpython/importcompletion.py b/bpython/importcompletion.py index c8c3f015e..e8482ff23 100644 --- a/bpython/importcompletion.py +++ b/bpython/importcompletion.py @@ -135,16 +135,7 @@ def complete(cursor_offset, line): def find_modules(path): """Find all modules (and packages) for a given directory.""" - - global nameSubname - nameSubname = [] - - #Decides if you are using the first method: usng name subname (1), - # the second method: using pathname (2) or the original (3), os.realpath - global useNameSubname - useNameSubname = 4 - #print("useNameSubname:", useNameSubname) - + if not os.path.isdir(path): # Perhaps a zip file return From 513f37d45c48464297d3fa792ede5e7358d820bb Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Tue, 30 Jun 2020 16:55:15 -0400 Subject: [PATCH 09/24] Made variable to store paths for comparison. --- bpython/importcompletion.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bpython/importcompletion.py b/bpython/importcompletion.py index e8482ff23..c5b50104b 100644 --- a/bpython/importcompletion.py +++ b/bpython/importcompletion.py @@ -49,6 +49,8 @@ # The cached list of all known modules modules = set() +#List of stored paths +paths = set() fully_loaded = False @@ -192,11 +194,9 @@ def find_modules(path): continue else: if is_package: - pathGood = True pathReal = os.path.realpath(pathname) - if len(pathReal) < len(pathname) and pathReal in pathname: - pathGood = False - if pathGood: + if not pathReal in paths: + paths.add(pathReal) for subname in find_modules(pathname): if subname != "__init__": yield "%s.%s" % (name, subname) From 01a6a4c1a789b37d02e59a613b2c5e30b50cca73 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Thu, 2 Jul 2020 21:43:13 -0400 Subject: [PATCH 10/24] further finalize changes to importcompletion.py --- bpython/importcompletion.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bpython/importcompletion.py b/bpython/importcompletion.py index c5b50104b..745a4cea6 100644 --- a/bpython/importcompletion.py +++ b/bpython/importcompletion.py @@ -35,7 +35,6 @@ import os import sys import warnings -import re from six.moves import filter if py3: @@ -49,7 +48,8 @@ # The cached list of all known modules modules = set() -#List of stored paths +# List of stored paths to compare against so that real paths are not repeated +# handles symlinks not mount points paths = set() fully_loaded = False @@ -137,7 +137,6 @@ def complete(cursor_offset, line): def find_modules(path): """Find all modules (and packages) for a given directory.""" - if not os.path.isdir(path): # Perhaps a zip file return @@ -194,21 +193,22 @@ def find_modules(path): continue else: if is_package: - pathReal = os.path.realpath(pathname) - if not pathReal in paths: - paths.add(pathReal) + path_real = os.path.realpath(pathname) + if path_real not in paths: + paths.add(path_real) for subname in find_modules(pathname): if subname != "__init__": yield "%s.%s" % (name, subname) yield name + def find_all_modules(path=None): """Return a list with all modules in `path`, which should be a list of directory names. If path is not given, sys.path will be used.""" if path is None: modules.update(try_decode(m, "ascii") for m in sys.builtin_module_names) path = sys.path - + for p in path: if not p: p = os.curdir From 2edc977f46f73ff4b79804eb600d032b3931fa7e Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Mon, 6 Jul 2020 12:26:02 -0400 Subject: [PATCH 11/24] Working on test but am having issues with the try --- importtest.py | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/importtest.py b/importtest.py index 2dce5fa37..09b571acb 100644 --- a/importtest.py +++ b/importtest.py @@ -1,7 +1,44 @@ from bpython.importcompletion import find_modules -import os +import os, sys, tempfile -foo = find_modules(os.path.abspath("./importtestfolder")) +with tempfile.TemporaryDirectory() as import_test_folder: + try: + os.chdir(import_test_folder) + except: + print("Can't change the Current Working Directory") + sys.exit() -for thing in foo: - print("YIELD:", thing) \ No newline at end of file + os.mkdir(os.path.join(os.getcwd(), "Level0") + try: + os.chdir(Level0) + open("__init__.py", w) + except OSError: + print("Can't change the Current Working Directory") + sys.exit() + + os.mkdir(os.path.join(os.getcwd(), "Level1") + try: + os.chdir(Level1) + open("__init__.py", w) + except OSError: + print("Can't change the Current Working Directory") + sys.exit() + + os.mkdir(os.path.join(os.getcwd(), "Level2") + try: + os.chdir(Level2) + open("__init__.py", w) + except OSError: + print("Can't change the Current Working Directory") + sys.exit() + + os.symlink( + "import_test_folder/Level0/Level1", + os.path.join(os.getcwd, "Level3"), + True, + ) + + foo = find_modules(os.path.abspath("import_test_folder")) + + for thing in foo: + print("YIELD:", thing) From 62bed480afa42c6fa2757fb83cf31a4affe1ca9b Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Tue, 7 Jul 2020 15:40:17 -0400 Subject: [PATCH 12/24] replaced import test file with them file directory --- importtest.py | 79 ++++++++++++++++--- importtestfolder/Left/__init__.py | 0 importtestfolder/Left/toRight | 1 - importtestfolder/Level0/Level1/Level2/Level3 | 1 - .../Level0/Level1/Level2/__init__.py | 0 importtestfolder/Level0/Level1/__init__.py | 0 importtestfolder/Level0/__init__.py | 0 importtestfolder/Right/__init__.py | 0 importtestfolder/Right/toLeft | 1 - importtestfolder/__init__.py | 0 10 files changed, 66 insertions(+), 16 deletions(-) delete mode 100644 importtestfolder/Left/__init__.py delete mode 120000 importtestfolder/Left/toRight delete mode 120000 importtestfolder/Level0/Level1/Level2/Level3 delete mode 100644 importtestfolder/Level0/Level1/Level2/__init__.py delete mode 100644 importtestfolder/Level0/Level1/__init__.py delete mode 100644 importtestfolder/Level0/__init__.py delete mode 100644 importtestfolder/Right/__init__.py delete mode 120000 importtestfolder/Right/toLeft delete mode 100644 importtestfolder/__init__.py diff --git a/importtest.py b/importtest.py index 09b571acb..aaa828436 100644 --- a/importtest.py +++ b/importtest.py @@ -1,3 +1,4 @@ +from bpython.test import unittest from bpython.importcompletion import find_modules import os, sys, tempfile @@ -8,37 +9,89 @@ print("Can't change the Current Working Directory") sys.exit() - os.mkdir(os.path.join(os.getcwd(), "Level0") + os.mkdir(os.path.join(os.getcwd(), "Level0")) + os.mkdir(os.path.join(os.getcwd(), "Right")) + os.mkdir(os.path.join(os.getcwd(), "Left")) try: - os.chdir(Level0) - open("__init__.py", w) + os.chdir("Level0") + open("__init__.py", "w") except OSError: print("Can't change the Current Working Directory") sys.exit() - os.mkdir(os.path.join(os.getcwd(), "Level1") + os.mkdir(os.path.join(os.getcwd(), "Level1")) try: - os.chdir(Level1) - open("__init__.py", w) + os.chdir("Level1") + open("__init__.py", "w") except OSError: print("Can't change the Current Working Directory") sys.exit() - os.mkdir(os.path.join(os.getcwd(), "Level2") + os.mkdir(os.path.join(os.getcwd(), "Level2")) try: - os.chdir(Level2) - open("__init__.py", w) + os.chdir("Level2") + open("__init__.py", "w") except OSError: print("Can't change the Current Working Directory") sys.exit() os.symlink( "import_test_folder/Level0/Level1", - os.path.join(os.getcwd, "Level3"), + os.path.join(os.getcwd(), "Level3"), True, ) - foo = find_modules(os.path.abspath("import_test_folder")) + try: + os.chdir(import_test_folder) + except: + print("Can't change the Current Working Directory") + sys.exit() + + try: + os.chdir("Right") + open("__init__.py", "w") + except OSError: + print("Can't change the Current Working Directory") + sys.exit() + + os.symlink( + "import_test_folder/Left", + os.path.join(os.getcwd(), "toLeft"), + True, + ) + + try: + os.chdir(import_test_folder) + except: + print("Can't change the Current Working Directory") + sys.exit() + + try: + os.chdir("Left") + open("__init__.py", "w") + except OSError: + print("Can't change the Current Working Directory") + sys.exit() + + os.symlink( + "import_test_folder/Right", + os.path.join(os.getcwd(), "toRight"), + True, + ) + foob = find_modules(os.path.abspath(import_test_folder)) + for things in foob: + print("Yield", things) + +class TestAvoidSymbolicLinks(unittest.TestCase): + def setUp(self): + self.foo = find_modules(os.path.abspath(import_test_folder)) + self.counter = 0 + self.filepaths = ["Level0.Level1.Level2", "Level0.Level1", "Level0", "Right", "Left"] + + def test_simple_symbolic_link_loop(self): + for thing in self.foo: + self.assertEqual(thing, self.filepaths[self.counter]) + self.counter = self.counter + 1 - for thing in foo: - print("YIELD:", thing) +if __name__ == '__main__': + unittest.main() diff --git a/importtestfolder/Left/__init__.py b/importtestfolder/Left/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/importtestfolder/Left/toRight b/importtestfolder/Left/toRight deleted file mode 120000 index 044f3e5dc..000000000 --- a/importtestfolder/Left/toRight +++ /dev/null @@ -1 +0,0 @@ -/Users/eerichart/bpython/importtestfolder/Right \ No newline at end of file diff --git a/importtestfolder/Level0/Level1/Level2/Level3 b/importtestfolder/Level0/Level1/Level2/Level3 deleted file mode 120000 index 0eb0122bd..000000000 --- a/importtestfolder/Level0/Level1/Level2/Level3 +++ /dev/null @@ -1 +0,0 @@ -/Users/eerichart/bpython/importtestfolder/Level0/Level1 \ No newline at end of file diff --git a/importtestfolder/Level0/Level1/Level2/__init__.py b/importtestfolder/Level0/Level1/Level2/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/importtestfolder/Level0/Level1/__init__.py b/importtestfolder/Level0/Level1/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/importtestfolder/Level0/__init__.py b/importtestfolder/Level0/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/importtestfolder/Right/__init__.py b/importtestfolder/Right/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/importtestfolder/Right/toLeft b/importtestfolder/Right/toLeft deleted file mode 120000 index 064170877..000000000 --- a/importtestfolder/Right/toLeft +++ /dev/null @@ -1 +0,0 @@ -/Users/eerichart/bpython/importtestfolder/Left \ No newline at end of file diff --git a/importtestfolder/__init__.py b/importtestfolder/__init__.py deleted file mode 100644 index e69de29bb..000000000 From 45ada741bb37876ce126cc8b6192df25bfb67168 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Wed, 8 Jul 2020 10:37:25 -0400 Subject: [PATCH 13/24] fixed importtest.py --- importtest.py | 177 +++++++++++++++++++++++++++----------------------- 1 file changed, 94 insertions(+), 83 deletions(-) diff --git a/importtest.py b/importtest.py index aaa828436..6ed597481 100644 --- a/importtest.py +++ b/importtest.py @@ -2,96 +2,107 @@ from bpython.importcompletion import find_modules import os, sys, tempfile -with tempfile.TemporaryDirectory() as import_test_folder: - try: - os.chdir(import_test_folder) - except: - print("Can't change the Current Working Directory") - sys.exit() - - os.mkdir(os.path.join(os.getcwd(), "Level0")) - os.mkdir(os.path.join(os.getcwd(), "Right")) - os.mkdir(os.path.join(os.getcwd(), "Left")) - try: - os.chdir("Level0") - open("__init__.py", "w") - except OSError: - print("Can't change the Current Working Directory") - sys.exit() - - os.mkdir(os.path.join(os.getcwd(), "Level1")) - try: - os.chdir("Level1") - open("__init__.py", "w") - except OSError: - print("Can't change the Current Working Directory") - sys.exit() - - os.mkdir(os.path.join(os.getcwd(), "Level2")) - try: - os.chdir("Level2") - open("__init__.py", "w") - except OSError: - print("Can't change the Current Working Directory") - sys.exit() - - os.symlink( - "import_test_folder/Level0/Level1", - os.path.join(os.getcwd(), "Level3"), - True, - ) - - try: - os.chdir(import_test_folder) - except: - print("Can't change the Current Working Directory") - sys.exit() - - try: - os.chdir("Right") - open("__init__.py", "w") - except OSError: - print("Can't change the Current Working Directory") - sys.exit() - - os.symlink( - "import_test_folder/Left", - os.path.join(os.getcwd(), "toLeft"), - True, - ) - - try: - os.chdir(import_test_folder) - except: - print("Can't change the Current Working Directory") - sys.exit() - - try: - os.chdir("Left") - open("__init__.py", "w") - except OSError: - print("Can't change the Current Working Directory") - sys.exit() - - os.symlink( - "import_test_folder/Right", - os.path.join(os.getcwd(), "toRight"), - True, - ) - foob = find_modules(os.path.abspath(import_test_folder)) - for things in foob: - print("Yield", things) class TestAvoidSymbolicLinks(unittest.TestCase): def setUp(self): - self.foo = find_modules(os.path.abspath(import_test_folder)) - self.counter = 0 - self.filepaths = ["Level0.Level1.Level2", "Level0.Level1", "Level0", "Right", "Left"] + with tempfile.TemporaryDirectory() as import_test_folder: + try: + os.chdir(import_test_folder) + except: + print("Can't change the Current Working Directory") + import_test_folder.cleanup() + sys.exit() + + os.mkdir(os.path.join(os.getcwd(), "Level0")) + os.mkdir(os.path.join(os.getcwd(), "Right")) + os.mkdir(os.path.join(os.getcwd(), "Left")) + try: + os.chdir("Level0") + with open("__init__.py", "w") as init_file: + init_file.close() + except OSError: + print("Can't change the Current Working Directory") + sys.exit() + + os.mkdir(os.path.join(os.getcwd(), "Level1")) + try: + os.chdir("Level1") + with open("__init__.py", "w") as init_file: + init_file.close() + except OSError: + print("Can't change the Current Working Directory") + sys.exit() + + os.mkdir(os.path.join(os.getcwd(), "Level2")) + try: + os.chdir("Level2") + with open("__init__.py", "w") as init_file: + init_file.close() + except OSError: + print("Can't change the Current Working Directory") + sys.exit() + + os.symlink( + "import_test_folder/Level0/Level1", + os.path.join(os.getcwd(), "Level3"), + True, + ) + + try: + os.chdir(import_test_folder) + except: + print("Can't change the Current Working Directory") + sys.exit() + + try: + os.chdir("Right") + with open("__init__.py", "w") as init_file: + init_file.close() + except OSError: + print("Can't change the Current Working Directory") + sys.exit() + + os.symlink( + "import_test_folder/Left", + os.path.join(os.getcwd(), "toLeft"), + True, + ) + + try: + os.chdir(import_test_folder) + except: + print("Can't change the Current Working Directory") + sys.exit() + + try: + os.chdir("Left") + with open("__init__.py", "w") as init_file: + init_file.close() + except OSError: + print("Can't change the Current Working Directory") + sys.exit() + + os.symlink( + "import_test_folder/Right", + os.path.join(os.getcwd(), "toRight"), + True, + ) + + self.foo = list(find_modules(os.path.abspath(import_test_folder))) + self.counter = 0 + self.filepaths = [ + "Left", + "Level0.Level1.Level2", + "Level0.Level1", + "Level0", + "Right", + ] def test_simple_symbolic_link_loop(self): for thing in self.foo: self.assertEqual(thing, self.filepaths[self.counter]) self.counter = self.counter + 1 -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() From 9fafb2ee2a82fd385b9c8973194c94bda12045c1 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Wed, 8 Jul 2020 16:07:54 -0400 Subject: [PATCH 14/24] moved and renamed importtest to test folder --- importtest.py => bpython/test/test_import_not_cyclical.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename importtest.py => bpython/test/test_import_not_cyclical.py (100%) diff --git a/importtest.py b/bpython/test/test_import_not_cyclical.py similarity index 100% rename from importtest.py rename to bpython/test/test_import_not_cyclical.py From 52cef9ffb115d82d2396fe816502dfe225e43972 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Thu, 9 Jul 2020 09:23:14 -0400 Subject: [PATCH 15/24] cleaned up test file --- bpython/test/test_import_not_cyclical.py | 72 +++++++----------------- 1 file changed, 20 insertions(+), 52 deletions(-) diff --git a/bpython/test/test_import_not_cyclical.py b/bpython/test/test_import_not_cyclical.py index 6ed597481..76b1db72a 100644 --- a/bpython/test/test_import_not_cyclical.py +++ b/bpython/test/test_import_not_cyclical.py @@ -6,41 +6,25 @@ class TestAvoidSymbolicLinks(unittest.TestCase): def setUp(self): with tempfile.TemporaryDirectory() as import_test_folder: - try: - os.chdir(import_test_folder) - except: - print("Can't change the Current Working Directory") - import_test_folder.cleanup() - sys.exit() + os.chdir(import_test_folder) os.mkdir(os.path.join(os.getcwd(), "Level0")) os.mkdir(os.path.join(os.getcwd(), "Right")) os.mkdir(os.path.join(os.getcwd(), "Left")) - try: - os.chdir("Level0") - with open("__init__.py", "w") as init_file: - init_file.close() - except OSError: - print("Can't change the Current Working Directory") - sys.exit() + + os.chdir("Level0") + with open("__init__.py", "w") as init_file: + pass os.mkdir(os.path.join(os.getcwd(), "Level1")) - try: - os.chdir("Level1") - with open("__init__.py", "w") as init_file: - init_file.close() - except OSError: - print("Can't change the Current Working Directory") - sys.exit() + os.chdir("Level1") + with open("__init__.py", "w") as init_file: + pass os.mkdir(os.path.join(os.getcwd(), "Level2")) - try: - os.chdir("Level2") - with open("__init__.py", "w") as init_file: - init_file.close() - except OSError: - print("Can't change the Current Working Directory") - sys.exit() + os.chdir("Level2") + with open("__init__.py", "w") as init_file: + pass os.symlink( "import_test_folder/Level0/Level1", @@ -48,19 +32,11 @@ def setUp(self): True, ) - try: - os.chdir(import_test_folder) - except: - print("Can't change the Current Working Directory") - sys.exit() + os.chdir(import_test_folder) - try: - os.chdir("Right") - with open("__init__.py", "w") as init_file: - init_file.close() - except OSError: - print("Can't change the Current Working Directory") - sys.exit() + os.chdir("Right") + with open("__init__.py", "w") as init_file: + pass os.symlink( "import_test_folder/Left", @@ -68,19 +44,11 @@ def setUp(self): True, ) - try: - os.chdir(import_test_folder) - except: - print("Can't change the Current Working Directory") - sys.exit() - - try: - os.chdir("Left") - with open("__init__.py", "w") as init_file: - init_file.close() - except OSError: - print("Can't change the Current Working Directory") - sys.exit() + os.chdir(import_test_folder) + + os.chdir("Left") + with open("__init__.py", "w") as init_file: + pass os.symlink( "import_test_folder/Right", From 6983428af5bbc717a9ee3a72a89ca5cff1792806 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Thu, 9 Jul 2020 10:10:47 -0400 Subject: [PATCH 16/24] improved test --- bpython/test/test_import_not_cyclical.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bpython/test/test_import_not_cyclical.py b/bpython/test/test_import_not_cyclical.py index 76b1db72a..cd702e78f 100644 --- a/bpython/test/test_import_not_cyclical.py +++ b/bpython/test/test_import_not_cyclical.py @@ -57,19 +57,18 @@ def setUp(self): ) self.foo = list(find_modules(os.path.abspath(import_test_folder))) - self.counter = 0 self.filepaths = [ "Left", "Level0.Level1.Level2", "Level0.Level1", "Level0", - "Right", + "Right" ] def test_simple_symbolic_link_loop(self): for thing in self.foo: - self.assertEqual(thing, self.filepaths[self.counter]) - self.counter = self.counter + 1 + self.assertTrue(thing in self.filepaths) + self.filepaths.remove(thing) if __name__ == "__main__": From 5928198b149db10e8a7f8b2024123085432f3513 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Thu, 9 Jul 2020 15:00:38 -0400 Subject: [PATCH 17/24] made it so test skips in python 2 --- bpython/test/test_import_not_cyclical.py | 139 ++++++++++++----------- 1 file changed, 72 insertions(+), 67 deletions(-) diff --git a/bpython/test/test_import_not_cyclical.py b/bpython/test/test_import_not_cyclical.py index cd702e78f..291f7934f 100644 --- a/bpython/test/test_import_not_cyclical.py +++ b/bpython/test/test_import_not_cyclical.py @@ -2,73 +2,78 @@ from bpython.importcompletion import find_modules import os, sys, tempfile - -class TestAvoidSymbolicLinks(unittest.TestCase): - def setUp(self): - with tempfile.TemporaryDirectory() as import_test_folder: - os.chdir(import_test_folder) - - os.mkdir(os.path.join(os.getcwd(), "Level0")) - os.mkdir(os.path.join(os.getcwd(), "Right")) - os.mkdir(os.path.join(os.getcwd(), "Left")) - - os.chdir("Level0") - with open("__init__.py", "w") as init_file: - pass - - os.mkdir(os.path.join(os.getcwd(), "Level1")) - os.chdir("Level1") - with open("__init__.py", "w") as init_file: - pass - - os.mkdir(os.path.join(os.getcwd(), "Level2")) - os.chdir("Level2") - with open("__init__.py", "w") as init_file: - pass - - os.symlink( - "import_test_folder/Level0/Level1", - os.path.join(os.getcwd(), "Level3"), - True, - ) - - os.chdir(import_test_folder) - - os.chdir("Right") - with open("__init__.py", "w") as init_file: - pass - - os.symlink( - "import_test_folder/Left", - os.path.join(os.getcwd(), "toLeft"), - True, - ) - - os.chdir(import_test_folder) - - os.chdir("Left") - with open("__init__.py", "w") as init_file: - pass - - os.symlink( - "import_test_folder/Right", - os.path.join(os.getcwd(), "toRight"), - True, - ) - - self.foo = list(find_modules(os.path.abspath(import_test_folder))) - self.filepaths = [ - "Left", - "Level0.Level1.Level2", - "Level0.Level1", - "Level0", - "Right" - ] - - def test_simple_symbolic_link_loop(self): - for thing in self.foo: - self.assertTrue(thing in self.filepaths) - self.filepaths.remove(thing) +if sys.version_info[0] > 2: + class TestAvoidSymbolicLinks(unittest.TestCase): + def setUp(self): + with tempfile.TemporaryDirectory() as import_test_folder: + os.chdir(import_test_folder) + + os.mkdir(os.path.join(os.getcwd(), "Level0")) + os.mkdir(os.path.join(os.getcwd(), "Right")) + os.mkdir(os.path.join(os.getcwd(), "Left")) + + os.chdir("Level0") + with open("__init__.py", "w") as init_file: + pass + + os.mkdir(os.path.join(os.getcwd(), "Level1")) + os.chdir("Level1") + with open("__init__.py", "w") as init_file: + pass + + os.mkdir(os.path.join(os.getcwd(), "Level2")) + os.chdir("Level2") + with open("__init__.py", "w") as init_file: + pass + + os.symlink( + "import_test_folder/Level0/Level1", + os.path.join(os.getcwd(), "Level3"), + True, + ) + + os.chdir(import_test_folder) + + os.chdir("Right") + with open("__init__.py", "w") as init_file: + pass + + os.symlink( + "import_test_folder/Left", + os.path.join(os.getcwd(), "toLeft"), + True, + ) + + os.chdir(import_test_folder) + + os.chdir("Left") + with open("__init__.py", "w") as init_file: + pass + + os.symlink( + "import_test_folder/Right", + os.path.join(os.getcwd(), "toRight"), + True, + ) + + self.foo = list(find_modules(os.path.abspath(import_test_folder))) + self.filepaths = [ + "Left", + "Level0.Level1.Level2", + "Level0.Level1", + "Level0", + "Right" + ] + + def test_simple_symbolic_link_loop(self): + for thing in self.foo: + self.assertTrue(thing in self.filepaths) + self.filepaths.remove(thing) + +else: + @unittest.skip() + def test_skip(): + pass if __name__ == "__main__": From dbc1d4fe7a4dddef5e96a7d7f50ecbda5e769335 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Thu, 9 Jul 2020 15:03:28 -0400 Subject: [PATCH 18/24] made skipping work --- bpython/test/test_import_not_cyclical.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bpython/test/test_import_not_cyclical.py b/bpython/test/test_import_not_cyclical.py index 291f7934f..418214910 100644 --- a/bpython/test/test_import_not_cyclical.py +++ b/bpython/test/test_import_not_cyclical.py @@ -71,7 +71,7 @@ def test_simple_symbolic_link_loop(self): self.filepaths.remove(thing) else: - @unittest.skip() + @unittest.skip("test doesn't work in python 2") def test_skip(): pass From 5f15d7d61e1b95a01db126123afa8e6b2308686b Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Mon, 13 Jul 2020 08:22:00 -0500 Subject: [PATCH 19/24] removed chdir and made better test skip --- bpython/test/test_import_not_cyclical.py | 146 +++++++++++------------ 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/bpython/test/test_import_not_cyclical.py b/bpython/test/test_import_not_cyclical.py index 418214910..76016ed8c 100644 --- a/bpython/test/test_import_not_cyclical.py +++ b/bpython/test/test_import_not_cyclical.py @@ -2,79 +2,79 @@ from bpython.importcompletion import find_modules import os, sys, tempfile -if sys.version_info[0] > 2: - class TestAvoidSymbolicLinks(unittest.TestCase): - def setUp(self): - with tempfile.TemporaryDirectory() as import_test_folder: - os.chdir(import_test_folder) - - os.mkdir(os.path.join(os.getcwd(), "Level0")) - os.mkdir(os.path.join(os.getcwd(), "Right")) - os.mkdir(os.path.join(os.getcwd(), "Left")) - - os.chdir("Level0") - with open("__init__.py", "w") as init_file: - pass - - os.mkdir(os.path.join(os.getcwd(), "Level1")) - os.chdir("Level1") - with open("__init__.py", "w") as init_file: - pass - - os.mkdir(os.path.join(os.getcwd(), "Level2")) - os.chdir("Level2") - with open("__init__.py", "w") as init_file: - pass - - os.symlink( - "import_test_folder/Level0/Level1", - os.path.join(os.getcwd(), "Level3"), - True, - ) - - os.chdir(import_test_folder) - - os.chdir("Right") - with open("__init__.py", "w") as init_file: - pass - - os.symlink( - "import_test_folder/Left", - os.path.join(os.getcwd(), "toLeft"), - True, - ) - - os.chdir(import_test_folder) - - os.chdir("Left") - with open("__init__.py", "w") as init_file: - pass - - os.symlink( - "import_test_folder/Right", - os.path.join(os.getcwd(), "toRight"), - True, - ) - - self.foo = list(find_modules(os.path.abspath(import_test_folder))) - self.filepaths = [ - "Left", - "Level0.Level1.Level2", - "Level0.Level1", - "Level0", - "Right" - ] - - def test_simple_symbolic_link_loop(self): - for thing in self.foo: - self.assertTrue(thing in self.filepaths) - self.filepaths.remove(thing) - -else: - @unittest.skip("test doesn't work in python 2") - def test_skip(): - pass - +@unittest.skipIf(sys.version_info[0] <= 2, "Test doesn't work in python 2.") +class TestAvoidSymbolicLinks(unittest.TestCase): + def setUp(self): + with tempfile.TemporaryDirectory() as import_test_folder: + os.mkdir(os.path.join(import_test_folder, "Level0")) + os.mkdir(os.path.join(import_test_folder, "Right")) + os.mkdir(os.path.join(import_test_folder, "Left")) + + current_path = os.path.join(import_test_folder, "Level0") + with open( + os.path.join(current_path, "__init__.py"), "x" + ) as init_file: + pass + + current_path = os.path.join(current_path, "Level1") + os.mkdir(current_path) + with open( + os.path.join(current_path, "__init__.py"), "x" + ) as init_file: + pass + + current_path = os.path.join(current_path, "Level2") + os.mkdir(current_path) + with open( + os.path.join(current_path, "__init__.py"), "x" + ) as init_file: + pass + + os.symlink( + "import_test_folder/Level0/Level1", + os.path.join(current_path, "Level3"), + True, + ) + + current_path = os.path.join(import_test_folder, "Right") + with open( + os.path.join(current_path, "__init__.py"), "x" + ) as init_file: + pass + + os.symlink( + "import_test_folder/Left", + os.path.join(current_path, "toLeft"), + True, + ) + + current_path = os.path.join(import_test_folder, "Left") + with open( + os.path.join(current_path, "__init__.py"), "x" + ) as init_file: + pass + + os.symlink( + "import_test_folder/Right", + os.path.join(current_path, "toRight"), + True, + ) + + self.foo = list( + find_modules(os.path.abspath(import_test_folder)) + ) + self.filepaths = [ + "Left", + "Level0.Level1.Level2", + "Level0.Level1", + "Level0", + "Right", + ] + + def test_simple_symbolic_link_loop(self): + for thing in self.foo: + self.assertTrue(thing in self.filepaths) + self.filepaths.remove(thing) if __name__ == "__main__": unittest.main() From 8bd85e91ee203e3915265cb50e40a75bbd1f728b Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Thu, 16 Jul 2020 09:34:11 -0500 Subject: [PATCH 20/24] fix symbolic links for the test --- bpython/test/test_import_not_cyclical.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bpython/test/test_import_not_cyclical.py b/bpython/test/test_import_not_cyclical.py index 76016ed8c..5307bd08c 100644 --- a/bpython/test/test_import_not_cyclical.py +++ b/bpython/test/test_import_not_cyclical.py @@ -31,7 +31,7 @@ def setUp(self): pass os.symlink( - "import_test_folder/Level0/Level1", + os.path.join(import_test_folder, "Level0/Level1"), os.path.join(current_path, "Level3"), True, ) @@ -43,7 +43,7 @@ def setUp(self): pass os.symlink( - "import_test_folder/Left", + os.path.join(import_test_folder, "Left"), os.path.join(current_path, "toLeft"), True, ) @@ -55,7 +55,7 @@ def setUp(self): pass os.symlink( - "import_test_folder/Right", + os.path.join(import_test_folder, "Right"), os.path.join(current_path, "toRight"), True, ) @@ -64,7 +64,10 @@ def setUp(self): find_modules(os.path.abspath(import_test_folder)) ) self.filepaths = [ + "Left.toRight.toLeft", + "Left.toRight", "Left", + "Level0.Level1.Level2.Level3", "Level0.Level1.Level2", "Level0.Level1", "Level0", @@ -76,5 +79,6 @@ def test_simple_symbolic_link_loop(self): self.assertTrue(thing in self.filepaths) self.filepaths.remove(thing) + if __name__ == "__main__": unittest.main() From 0a2973112710b3568db36642f29de18600d987d2 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Thu, 16 Jul 2020 09:39:47 -0500 Subject: [PATCH 21/24] used black auto format --- bpython/test/test_import_not_cyclical.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bpython/test/test_import_not_cyclical.py b/bpython/test/test_import_not_cyclical.py index 5307bd08c..f4f716ec9 100644 --- a/bpython/test/test_import_not_cyclical.py +++ b/bpython/test/test_import_not_cyclical.py @@ -2,6 +2,7 @@ from bpython.importcompletion import find_modules import os, sys, tempfile + @unittest.skipIf(sys.version_info[0] <= 2, "Test doesn't work in python 2.") class TestAvoidSymbolicLinks(unittest.TestCase): def setUp(self): @@ -60,9 +61,7 @@ def setUp(self): True, ) - self.foo = list( - find_modules(os.path.abspath(import_test_folder)) - ) + self.foo = list(find_modules(os.path.abspath(import_test_folder))) self.filepaths = [ "Left.toRight.toLeft", "Left.toRight", From cec627a7f67eb8dffe47664e6dd6e844a085624e Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Thu, 16 Jul 2020 10:42:15 -0500 Subject: [PATCH 22/24] improved test to work on other computers --- bpython/test/test_import_not_cyclical.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bpython/test/test_import_not_cyclical.py b/bpython/test/test_import_not_cyclical.py index f4f716ec9..ca2c53917 100644 --- a/bpython/test/test_import_not_cyclical.py +++ b/bpython/test/test_import_not_cyclical.py @@ -71,6 +71,8 @@ def setUp(self): "Level0.Level1", "Level0", "Right", + "Right.toLeft", + "Right.toLeft.toRight", ] def test_simple_symbolic_link_loop(self): From 629bf1e915fa3ebff12f9f73ce6ceb7900b52a83 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Thu, 16 Jul 2020 10:58:37 -0500 Subject: [PATCH 23/24] made testing strickter --- bpython/test/test_import_not_cyclical.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bpython/test/test_import_not_cyclical.py b/bpython/test/test_import_not_cyclical.py index ca2c53917..baf3d8fae 100644 --- a/bpython/test/test_import_not_cyclical.py +++ b/bpython/test/test_import_not_cyclical.py @@ -78,6 +78,12 @@ def setUp(self): def test_simple_symbolic_link_loop(self): for thing in self.foo: self.assertTrue(thing in self.filepaths) + if thing == "Left.toRight.toLeft": + self.filepaths.remove("Right.toLeft") + self.filepaths.remove("Right.toLeft.toRight") + if thing == "Right.toLeft.toRight": + self.filepaths.remove("Left.toRight.toLeft") + self.filepaths.remove("Left.toRight") self.filepaths.remove(thing) From 11369fcc2cd60dd9f4dcf2618424f9b3ae994696 Mon Sep 17 00:00:00 2001 From: Etienne Richart Date: Thu, 16 Jul 2020 11:32:41 -0500 Subject: [PATCH 24/24] further testing --- bpython/test/test_import_not_cyclical.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bpython/test/test_import_not_cyclical.py b/bpython/test/test_import_not_cyclical.py index baf3d8fae..4e2d99c35 100644 --- a/bpython/test/test_import_not_cyclical.py +++ b/bpython/test/test_import_not_cyclical.py @@ -85,6 +85,7 @@ def test_simple_symbolic_link_loop(self): self.filepaths.remove("Left.toRight.toLeft") self.filepaths.remove("Left.toRight") self.filepaths.remove(thing) + self.assertFalse(self.filepaths) if __name__ == "__main__":