Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions qiita_db/environment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# -----------------------------------------------------------------------------

from os.path import abspath, dirname, join, exists, basename, splitext
from shutil import copytree
from functools import partial
from os import mkdir
import gzip
Expand Down Expand Up @@ -127,6 +128,37 @@ def _download_reference_files():
_insert_processed_params(ref)


def create_mountpoints():
r"""In a fresh qiita setup, sub-directories under
qiita_config.base_data_dir might not yet exist. To avoid failing in
later steps, they are created here.
"""
with qdb.sql_connection.TRN:
sql = """SELECT DISTINCT mountpoint FROM qiita.data_directory
WHERE active = TRUE"""
qdb.sql_connection.TRN.add(sql)
created_subdirs = []
for mountpoint in qdb.sql_connection.TRN.execute_fetchflatten():
for (ddid, subdir) in qdb.util.get_mountpoint(mountpoint,
retrieve_all=True):
if not exists(join(qiita_config.base_data_dir, subdir)):
if qiita_config.test_environment and \
exists(get_support_file('test_data', subdir)):
Copy link
Member

Choose a reason for hiding this comment

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

out of curiosity, why do we need this check? In which scenario that folder will not exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. But it actually happened to me, that I have accidentally moved these support files instead of coping and then they were missing.

Copy link
Member

Choose a reason for hiding this comment

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

I see; on that scenario, it should fail, no? and if I understand this correctly, it will not fail here and not copy anything, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

exactly

Copy link
Member

@antgonza antgonza Mar 8, 2025

Choose a reason for hiding this comment

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

Well, I'm a little concerned about that behavior but if you think is the correct one, then fine. My concern is that I think that if there is nothing to copy it should error with the copytree error of file not found. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you are right: better fail with a traceable error message than to silently do workarounds which might be hard to debug / understand for the user

# if in test mode, we want to potentially fill the
# new directory with according test data
copytree(get_support_file('test_data', subdir),
join(qiita_config.base_data_dir, subdir))
else:
# in production mode, an empty directory is created
mkdir(join(qiita_config.base_data_dir, subdir))
created_subdirs.append(subdir)

if len(created_subdirs) > 0:
print("Created %i sub-directories as 'mount points':\n%s"
% (len(created_subdirs),
''.join(map(lambda x: ' - %s\n' % x, created_subdirs))))


def make_environment(load_ontologies, download_reference, add_demo_user):
r"""Creates the new environment specified in the configuration

Expand Down Expand Up @@ -397,6 +429,9 @@ def patch(patches_dir=PATCHES_DIR, verbose=False, test=False):
with qdb.sql_connection.TRN:
_populate_test_db()

# create mountpoints as subdirectories in BASE_DATA_DIR
create_mountpoints()

patch_update_sql = "UPDATE settings SET current_patch = %s"
for sql_patch_fp in sql_patch_files[next_patch_index:]:
sql_patch_filename = basename(sql_patch_fp)
Expand Down