qjawls2003 / Windows_Anomaly_Detection

0 stars 0 forks source link

Utilize bazel runfiles to ensure data files are dynamically referenced at build/run times #1

Closed abemelvin closed 1 year ago

abemelvin commented 1 year ago

https://github.com/qjawls2003/Windows_Anomaly_Detection/blob/3401cb6cc71969395a232447a4613a06054e2f08/pre_processing/src/csv_to_df.py#L8

Bazel runfiles: https://github.com/bazelbuild/bazel/blob/master/tools/python/runfiles/runfiles.py

abemelvin commented 1 year ago

nvm I see you're utilizing data field in the BUILD target :) closing

qjawls2003 commented 1 year ago

I need to do something like this to get any csv files inside the /data folder, but I dont think Bazel likes this.

export_files(["*.csv])

abemelvin commented 1 year ago

If you use bazel runfiles, you can get entire directories of files

In the relevant BUILD file/target, add requirement("bazel-runfiles") to your deps list (this is a Python library so you'll need to install it bazel_runfiles)

Then, in the Python target itself you can do

import os
import runfiles

r = runfiles.CreateDirectoryBased(os.path.join(os.environ["BUILD_WORKSPACE_DIRECTORY"], your_dir_here))
dir_path = r.Rlocation('.')