Skip to content
Open
6 changes: 5 additions & 1 deletion src/questionnaire_data/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ def _hash_properties(props: sp.SproutProperties) -> str:
).hexdigest()


@mark.metadata
@mark.skipif(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was it the intention to make the metadata tasks run without the download step? If I run uv run pytask build -m metadata it will skip all tasks now because -- I think -- it still can't see that this first dependency is satisfied (rather, the file's existence doesn't mean that the dependency is satisfied). Or is it working for you?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmmm, I hadn't noticed that it wasn't working for me, but I wasn't specifically checking how you describe it. It might need a @mark.persist tag...?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, I played around with it a bit and I think @mark.persist might actually be better than skip here. At least, with just @mark.persist it skips the download task but runs the processing tasks.

Then there is also the older idea of having the download task in a separate pipeline with no pytask dependency between the download step and the other steps.

common.redcap.is_empty_env(),
reason="API key is not present in the environment, so skipping.",
)
@mark.raw
def task_download_metadata(
raw_metadata_path: Annotated[Path, Product] = RAW_METADATA_PATH,
) -> None:
Expand Down
16 changes: 14 additions & 2 deletions src/questionnaire_data/common/redcap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from dataclasses import dataclass
from typing import Any, Literal
from typing import Any, Literal, Optional

import requests

Expand All @@ -23,7 +23,7 @@ def get(
api_config: APIConfig = API_CONFIG,
) -> requests.Response:
"""Send a request to the REDCap API."""
token = os.environ.get(api_config.env_key)
token = _get_env(api_config)
if not token:
raise RuntimeError(f"{api_config.env_key} environment variable is not set.")

Expand All @@ -46,3 +46,15 @@ def get_json(
}
response = get(request_data)
return response.json()


def is_empty_api_key() -> bool:
"""Check if env is empty."""
return _get_env(API_CONFIG) is None


def _get_api_key(api_config: APIConfig) -> Optional[str]:
env_var = os.environ.get(api_config.env_key)
if env_var == "":
env_var = None
return env_var
Loading