Repository: spyder-ide/spyder

Issue:
Files or directories including ".git" in their path are ignored in project pane
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [ ] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [ ] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description

Hi there,

The project pane doesn't show any file or directory which includes ".git" in its path.
If the directory of the opened project  is something like `<name>.git` the project pane stays all empty.

Variations like "-git", "_git" are fine.


### What steps reproduce the problem?

1. Create a file/folder within a spyder project with ".git" in its path
2. Open spyder
3. The file/folder will not show up in the projects pane

### What is the expected output? What do you see instead?

In the previous major spyder version this was not a problem.
Now if the project directory is named `<name>.git` the project pane is all empty.

This behaviour could be reproduced with a fresh environment.

conda env create -n py39testing python=3.9
conda activate py39testing
spyder

cd <spyder_project_dir>

touch invisible.git
touch also-invisible.git.txt
mkdir invis-dir.git

mkdir visible-git-something-dir
touch visible_git_containing_file.txt





## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 5.1.5
* Python version: 3.9.7
* Qt version: 5.9.7
* PyQt version: 5.9.2
* Operating System name/version: Linux 5.15.12-1-MANJARO 

### Dependencies

# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.2 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.6.0               :  7.29.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.0 (OK)
jsonschema >=3.2.0            :  3.2.0 (OK)
keyring >=17.0.0              :  23.4.0 (OK)
nbconvert >=4.0               :  6.3.0 (OK)
numpydoc >=0.6.0              :  1.1.0 (OK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.10.0 (OK)
pylint >=2.5.0;<2.10.0        :  2.9.6 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.2.2;<1.3.0          :  1.2.4 (OK)
pylsp_black >=1.0.0           :  None (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.1.10 (OK)
qtawesome >=1.0.2             :  1.0.3 (OK)
qtconsole >=5.1.0             :  5.1.1 (OK)
qtpy >=1.5.0                  :  1.10.0 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  58.0.4 (OK)
sphinx >=0.6.6                :  4.2.0 (OK)
spyder_kernels >=2.1.1;<2.2.0 :  2.1.3 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.6 (OK)
xdg >=0.26                    :  0.27 (OK)
zmq >=17                      :  22.3.0 (OK)

# Optional:
cython >=0.21                 :  None (OK)
matplotlib >=2.0.0            :  3.5.0 (OK)
numpy >=1.7                   :  1.21.2 (OK)
pandas >=1.1.1                :  1.3.5 (OK)
scipy >=0.17.0                :  1.7.3 (OK)
sympy >=0.7.3                 :  None (OK)


Discussion:
Hi @snuppets thank you for the feedback! I was able to reproduce this :+1:

Just in case, most probably the lines causing it are these:

https://github.com/spyder-ide/spyder/blob/4d59427d96db4f519a1af9271e77c4905d7d50a0/spyder/plugins/projects/widgets/projectexplorer.py#L40

https://github.com/spyder-ide/spyder/blob/4d59427d96db4f519a1af9271e77c4905d7d50a0/spyder/plugins/projects/widgets/projectexplorer.py#L95


Thanks for finding the right line of code.

Could it be a solution to allow the user a modification of the list `PATHS_TO_HIDE`?
It seems to me this list is currently hard coded and can't be modified though GUI or a config file.

I would suggest something like an entry `ignored paths` in the hamburger menu of the project pane, where the user can remove or even add filter items.
I think something like that could be the right thing yep :+1: (something similar to what is being done for the Files pane where you have a filter and an option to edit it).

Not sure if something like that is in the [ux-improvements](https://github.com/spyder-ide/ux-improvements/) repo. Should we move this to that repo @ccordoba12 ?
> I think something like that could be the right thing yep +1 (something similar to what is being done for the Files pane where you have a filter and an option to edit it).

I disagree because it'd imply adding more functionality to the project explorer which I find really unnecessary. I implemented the filtering @dalthviz referenced above and just didn't think that people would name their directories with `.git`. So the solution is to be more strict with the list comprehension that filters `PATHS_TO_HIDE`.

> Not sure if something like that is in the ux-improvements repo. Should we move this to that repo @ccordoba12 ?

Not for now because the solution to this bug is quite simple, as I said above.

Resolving patch:
diff --git a/spyder/plugins/projects/widgets/projectexplorer.py b/spyder/plugins/projects/widgets/projectexplorer.py
--- a/spyder/plugins/projects/widgets/projectexplorer.py
+++ b/spyder/plugins/projects/widgets/projectexplorer.py
@@ -91,8 +91,10 @@ def filterAcceptsRow(self, row, parent_index):
         else:
             for p in [osp.normcase(p) for p in self.path_list]:
                 if path == p or path.startswith(p + os.sep):
-                    if not any([d in path for d in self.PATHS_TO_SHOW]):
-                        if any([d in path for d in self.PATHS_TO_HIDE]):
+                    if not any([path.endswith(os.sep + d)
+                                for d in self.PATHS_TO_SHOW]):
+                        if any([path.endswith(os.sep + d)
+                                for d in self.PATHS_TO_HIDE]):
                             return False
                         else:
                             return True


Test patch: