Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration to exclude paths #1163

Merged
merged 12 commits into from
Sep 6, 2022

Conversation

divyansshhh
Copy link
Contributor

@divyansshhh divyansshhh commented Sep 1, 2022

Resolves #1162

@welcome
Copy link

welcome bot commented Sep 1, 2022

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please make sure you followed the pull request template, as this will help us review your contribution more quickly.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also a intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@github-actions
Copy link

github-actions bot commented Sep 1, 2022

Binder 👈 Launch a binder notebook on branch divyansshhh/jupyterlab-git/feat/exclude_paths

@divyansshhh
Copy link
Contributor Author

@fcollonval , a few of the tests have failed and it seems because I'm accessing the settings through self.git._config.excluded_paths.

Do you have any other recommendations for this?

The configuration will be accessible from self.git.config.excluded_paths

I tried this as well but this doesn't work because self.git.config is a function and also it returns the git config not JupyterLabGit config.

@krassowski
Copy link
Member

One option could be to expose excluded_paths as a property of GitHandler

diff --git a/jupyterlab_git/git.py b/jupyterlab_git/git.py
--- a/jupyterlab_git/git.py
+++ b/jupyterlab_git/git.py
@@ -1750,3 +1750,7 @@ class Git:
 
         elif self._GIT_CREDENTIAL_CACHE_DAEMON_PROCESS.poll():
             self.ensure_git_credential_cache_daemon(socket, debug, True, cwd, env)
+
+    @property
+    def excluded_paths(self):
+        return self._config.excluded_paths
diff --git a/jupyterlab_git/handlers.py b/jupyterlab_git/handlers.py
--- a/jupyterlab_git/handlers.py
+++ b/jupyterlab_git/handlers.py
@@ -43,7 +43,7 @@ class GitHandler(APIHandler):
         super().prepare()
         path = self.path_kwargs.get("path")
         if path is not None:
-            excluded_paths = self.git._config.excluded_paths
+            excluded_paths = self.git.excluded_paths
             for excluded_path in excluded_paths:
                 if re.match(excluded_path, path):
                     self.set_status(404)

@divyansshhh
Copy link
Contributor Author

I was planning to write a test for this in jupyterlab_git/test/test_handlers.py but I can't figure out how I should pass the excluded paths setting.

Also, another question I have is -
Consider -

def test_GitHandler_url2localpath(path, with_cm, jp_web_app, jp_root_dir):

Where do jp_web_app and jp_root_dir parameters come from?

@fcollonval
Copy link
Member

You can override the default server configuration by overriding the jp_server_config in the test file as done in

def jp_server_config(jp_server_config):

The fixture requested are provided by the jupyter Server pytest Plugin (loaded in the file linked above).

This makes it quite convenient to create pytest for Jupyter server.

Copy link
Member

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @divyansshhh

I made some suggestions to improve the code and add some more documentation.

conftest.py Outdated Show resolved Hide resolved
jupyterlab_git/git.py Outdated Show resolved Hide resolved
jupyterlab_git/handlers.py Outdated Show resolved Hide resolved
jupyterlab_git/tests/test_handlers.py Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
jupyterlab_git/handlers.py Outdated Show resolved Hide resolved
divyansshhh and others added 7 commits September 6, 2022 15:11
Co-authored-by: Frédéric Collonval <[email protected]>
Co-authored-by: Frédéric Collonval <[email protected]>
Co-authored-by: Frédéric Collonval <[email protected]>
Co-authored-by: Frédéric Collonval <[email protected]>
Co-authored-by: Frédéric Collonval <[email protected]>
Copy link
Member

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @divyansshhh

@fcollonval fcollonval merged commit 54db65f into jupyterlab:master Sep 6, 2022
@welcome
Copy link

welcome bot commented Sep 6, 2022

Congrats on your first merged pull request in this project! 🎉
congrats
Thank you for contributing, we are very proud of you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent git rev-parse --show-origin from running in some dirs
3 participants