Skip to content

Commit

Permalink
feat: Add IDC_INDEX_DATA_GENERATE_PARQUET option
Browse files Browse the repository at this point in the history
  • Loading branch information
jcfr committed Mar 22, 2024
1 parent c65f32b commit 4c2e6ef
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@ if(NOT DEFINED ENV{GCP_PROJECT})
message(FATAL_ERROR "GCP_PROJECT env. variable is not set")
endif()

option(IDC_INDEX_DATA_GENERATE_PARQUET "Generate idc_index.parquet file" OFF)

set(download_dir "${PROJECT_BINARY_DIR}")

add_custom_command(
OUTPUT
${download_dir}/idc_index.csv.zip
#${download_dir}/idc_index.parquet
$<$<BOOL:IDC_INDEX_DATA_GENERATE_PARQUET>:${download_dir}/idc_index.parquet>
COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/python/idc_index_data_manager.py
)

add_custom_target(run_idc_index_data_manager ALL
DEPENDS ${download_dir}/idc_index.csv.zip
#${download_dir}/idc_index.parquet
DEPENDS
${download_dir}/idc_index.csv.zip
$<$<BOOL:IDC_INDEX_DATA_GENERATE_PARQUET>:${download_dir}/idc_index.parquet>
)

install(FILES ${download_dir}/idc_index.csv.zip DESTINATION "idc_index_data")
#install(FILES ${download_dir}/idc_index.parquet DESTINATION "idc_index_data")
install(
FILES
${download_dir}/idc_index.csv.zip
$<$<BOOL:IDC_INDEX_DATA_GENERATE_PARQUET>:${download_dir}/idc_index.parquet>
DESTINATION "idc_index_data")
13 changes: 10 additions & 3 deletions src/idc_index_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@
]


def _lookup(path: str) -> Path:
def _lookup(path: str, optional: bool = False) -> Path | None:
"""Support editable installation by looking up path using distribution API."""
files = distribution("idc_index_data").files
if files is not None:
for _file in files:
if str(_file) == path:
return Path(str(_file.locate())).resolve(strict=True)
if optional:
return None

msg = f"Failed to lookup '{path}`."
raise FileNotFoundError(msg)


IDC_INDEX_CSV_ARCHIVE_FILEPATH: Path = _lookup("idc_index_data/idc_index.csv.zip")
# IDC_INDEX_PARQUET_FILEPATH: Path = _lookup("idc_index_data/idc_index.parquet")
IDC_INDEX_CSV_ARCHIVE_FILEPATH: Path | None = _lookup(
"idc_index_data/idc_index.csv.zip"
)
IDC_INDEX_PARQUET_FILEPATH: Path | None = _lookup(
"idc_index_data/idc_index.parquet", optional=True
)
7 changes: 5 additions & 2 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ def test_version():


def test_filepath():
assert m.IDC_INDEX_CSV_ARCHIVE_FILEPATH is not None
assert m.IDC_INDEX_CSV_ARCHIVE_FILEPATH.is_file()
assert m.IDC_INDEX_CSV_ARCHIVE_FILEPATH.name == "idc_index.csv.zip"
# assert m.IDC_INDEX_PARQUET_FILEPATH.is_file()
# assert m.IDC_INDEX_PARQUET_FILEPATH.name == "idc_index.parquet"

if m.IDC_INDEX_PARQUET_FILEPATH is not None:
assert m.IDC_INDEX_PARQUET_FILEPATH.is_file()
assert m.IDC_INDEX_PARQUET_FILEPATH.name == "idc_index.parquet"

0 comments on commit 4c2e6ef

Please sign in to comment.