src/eric7/Project/Project.py

branch
eric7
changeset 9646
ab5678db972f
parent 9644
9875d5f11cbf
child 9647
e4c2ae118781
equal deleted inserted replaced
9645:31aaa11672d3 9646:ab5678db972f
2028 """ 2028 """
2029 # first perform the addition of source 2029 # first perform the addition of source
2030 self.__addSingleDirectory(filetype, source, target, True) 2030 self.__addSingleDirectory(filetype, source, target, True)
2031 2031
2032 ignore_patterns = [ 2032 ignore_patterns = [
2033 ".svn",
2034 ".hg",
2035 ".git",
2036 ".ropeproject",
2037 ".eric7project",
2038 ".jedi",
2039 "__pycache__",
2040 ] + [
2033 pattern 2041 pattern
2034 for pattern, filetype in self.__pdata["FILETYPES"].items() 2042 for pattern, filetype in self.__pdata["FILETYPES"].items()
2035 if filetype == "__IGNORE__" 2043 if filetype == "__IGNORE__"
2036 ] 2044 ]
2037 2045
2038 # TODO: replace os.listdir() with os.scandir()
2039 # now recurse into subdirectories 2046 # now recurse into subdirectories
2040 for name in os.listdir(source): 2047 with os.scandir(source) as dirEntriesIterator:
2041 ns = os.path.join(source, name) 2048 for dirEntry in dirEntriesIterator:
2042 if os.path.isdir(ns): 2049 if dirEntry.is_dir() and not any(
2043 skip = False 2050 fnmatch.fnmatch(dirEntry.name, ignore_pattern)
2044 for ignore_pattern in ignore_patterns: 2051 for ignore_pattern in ignore_patterns
2045 if fnmatch.fnmatch(name, ignore_pattern): 2052 ):
2046 skip = True 2053 self.__addRecursiveDirectory(
2047 break 2054 filetype, dirEntry.path, os.path.join(target, dirEntry.name)
2048 if skip: 2055 )
2049 continue
2050
2051 nt = os.path.join(target, name)
2052 self.__addRecursiveDirectory(filetype, ns, nt)
2053 2056
2054 @pyqtSlot() 2057 @pyqtSlot()
2055 def addDirectory(self, fileTypeFilter=None, startdir=None): 2058 def addDirectory(self, fileTypeFilter=None, startdir=None):
2056 """ 2059 """
2057 Public method used to add all files of a directory to the project. 2060 Public method used to add all files of a directory to the project.
6923 @return path of the embedded virtual environment (empty if not found) 6926 @return path of the embedded virtual environment (empty if not found)
6924 @rtype str 6927 @rtype str
6925 """ 6928 """
6926 with os.scandir(self.getProjectPath()) as ppathDirEntriesIterator: 6929 with os.scandir(self.getProjectPath()) as ppathDirEntriesIterator:
6927 for dirEntry in ppathDirEntriesIterator: 6930 for dirEntry in ppathDirEntriesIterator:
6928 if dirEntry.is_dir(): 6931 # potential venv directory; check for 'pyvenv.cfg'
6929 # potential venv directory; check for 'pyvenv.cfg' 6932 if dirEntry.is_dir() and os.path.exists(
6930 if os.path.exists(os.path.join(dirEntry.path, "pyvenv.cfg")): 6933 os.path.join(dirEntry.path, "pyvenv.cfg")
6931 return dirEntry.path 6934 ):
6935 return dirEntry.path
6932 6936
6933 # check for some common names in case 'pyvenv.cfg' is missing 6937 # check for some common names in case 'pyvenv.cfg' is missing
6934 for venvPathName in (".venv", "venv", ".env", "env"): 6938 for venvPathName in (".venv", "venv", ".env", "env"):
6935 venvPath = os.path.join(self.getProjectPath(), venvPathName) 6939 venvPath = os.path.join(self.getProjectPath(), venvPathName)
6936 if os.path.isdir(venvPath): 6940 if os.path.isdir(venvPath):

eric ide

mercurial