Skip to content

Commit

Permalink
Avoid loading CWD config when API is called too
Browse files Browse the repository at this point in the history
  • Loading branch information
brichet committed Mar 4, 2024
1 parent cc9b6a3 commit c37c273
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions nbgrader/apps/baseapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class NbGrader(JupyterApp):
aliases = nbgrader_aliases
flags = nbgrader_flags

load_cwd_config = True

_log_formatter_cls = LogFormatter

@default("log_level")
Expand Down Expand Up @@ -358,16 +360,18 @@ def load_config_file(self, **kwargs: Any) -> None:
paths = [os.path.abspath("{}.py".format(self.config_file))]
else:
config_dir = self.config_file_paths.copy()
config_dir.insert(0, os.getcwd())
if self.load_cwd_config:
config_dir.insert(0, os.getcwd())
paths = [os.path.join(x, "{}.py".format(self.config_file_name)) for x in config_dir]

if not any(os.path.exists(x) for x in paths):
self.log.warning("No nbgrader_config.py file found (rerun with --debug to see where nbgrader is looking)")

super(NbGrader, self).load_config_file(**kwargs)

# Load also config from current working directory
super(JupyterApp, self).load_config_file(self.config_file_name, os.getcwd())
if (self.load_cwd_config):
# Load also config from current working directory
super(JupyterApp, self).load_config_file(self.config_file_name, os.getcwd())

def start(self) -> None:
super(NbGrader, self).start()
Expand Down
1 change: 1 addition & 0 deletions nbgrader/server_extensions/formgrader/formgrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def url_prefix(self):

def load_config(self):
app = NbGrader()
app.load_cwd_config = self.load_cwd_config
app.config_dir = self.config_dir
app.load_config_file()

Expand Down
2 changes: 2 additions & 0 deletions nbgrader/server_extensions/formgrader/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def get(self):
path = self.get_argument('path', '')
if path:
path = os.path.abspath(path)
formgrader.load_cwd_config = False
formgrader.config = Config()
formgrader.config_dir = path
formgrader.initialize([], root=path)
Expand All @@ -28,6 +29,7 @@ def get(self):
formgrader.config = self.settings['initial_config']
formgrader.config_dir = jupyter_config_dir()
formgrader.initialize([])
formgrader.load_cwd_config = True
self.redirect(f"{self.base_url}/formgrader/manage_assignments/")


Expand Down

0 comments on commit c37c273

Please sign in to comment.