-
Notifications
You must be signed in to change notification settings - Fork 548
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Option to set root folder for chemprop web
- Loading branch information
1 parent
6b5cc17
commit 0ff6fd4
Showing
7 changed files
with
126 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
"""Runs the web interface version of chemprop, allowing for training and predicting in a web browser.""" | ||
import os | ||
|
||
from flask import Flask | ||
|
||
from chemprop.web.utils import set_root_folder | ||
|
||
|
||
app = Flask(__name__) | ||
app.config.from_object('chemprop.web.config') | ||
|
||
os.makedirs(app.config['CHECKPOINT_FOLDER'], exist_ok=True) | ||
os.makedirs(app.config['DATA_FOLDER'], exist_ok=True) | ||
set_root_folder( | ||
app=app, | ||
root_folder=os.path.dirname(os.path.dirname(os.path.realpath(__file__))), | ||
create_folders=False | ||
) | ||
|
||
from chemprop.web.app import views |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"""Contains utility functions for the Flask web app.""" | ||
|
||
import os | ||
import shutil | ||
|
||
from flask import Flask | ||
|
||
|
||
def set_root_folder(app: Flask, root_folder: str = None, create_folders: bool = True) -> None: | ||
""" | ||
Sets the root folder for the config along with subfolders like the data and checkpoint folders. | ||
:param app: Flask app. | ||
:param root_folder: Path to the root folder. If None, the current root folders is unchanged. | ||
:param create_folders: Whether to create the root folder and subfolders. | ||
""" | ||
# Set root folder and subfolders | ||
if root_folder is not None: | ||
app.config['ROOT_FOLDER'] = root_folder | ||
app.config['DATA_FOLDER'] = os.path.join(app.config['ROOT_FOLDER'], 'app/web_data') | ||
app.config['CHECKPOINT_FOLDER'] = os.path.join(app.config['ROOT_FOLDER'], 'app/web_checkpoints') | ||
app.config['TEMP_FOLDER'] = os.path.join(app.config['ROOT_FOLDER'], 'app/temp') | ||
app.config['DB_PATH'] = os.path.join(app.config['ROOT_FOLDER'], app.config['DB_FILENAME']) | ||
|
||
# Create folders | ||
if create_folders: | ||
for folder_name in ['ROOT_FOLDER', 'DATA_FOLDER', 'CHECKPOINT_FOLDER', 'TEMP_FOLDER']: | ||
os.makedirs(app.config[folder_name], exist_ok=True) | ||
|
||
|
||
def clear_temp_folder(app: Flask) -> None: | ||
"""Clears the temporary folder.""" | ||
shutil.rmtree(app.config['TEMP_FOLDER']) | ||
os.makedirs(app.config['TEMP_FOLDER'], exist_ok=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters