tlpytools 0.2.7__tar.gz → 0.2.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tlpytools-0.2.7 → tlpytools-0.2.9}/.env.example +4 -1
- {tlpytools-0.2.7 → tlpytools-0.2.9}/.github/copilot-instructions.md +2 -2
- {tlpytools-0.2.7 → tlpytools-0.2.9}/.github/workflows/deploy.yml +1 -1
- {tlpytools-0.2.7 → tlpytools-0.2.9}/CHANGELOG.md +27 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/DEVELOPER_GUIDE.md +2 -2
- {tlpytools-0.2.7 → tlpytools-0.2.9}/ENVIRONMENT_VARIABLES.md +12 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/PKG-INFO +2 -2
- {tlpytools-0.2.7 → tlpytools-0.2.9}/pyproject.toml +1 -1
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/__init__.py +1 -1
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/adls_server.py +69 -17
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/orca/batch_task_runner.py +5 -2
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/orca/orchestrator.py +138 -48
- {tlpytools-0.2.7 → tlpytools-0.2.9}/tests/test_orca_unit.py +9 -4
- {tlpytools-0.2.7 → tlpytools-0.2.9}/uv.lock +1 -1
- {tlpytools-0.2.7 → tlpytools-0.2.9}/.github/skills/README.md +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/.github/skills/prepare-official-release/SKILL.md +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/.github/workflows/code-formatting-pr.yml +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/.github/workflows/code-formatting.yml +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/.github/workflows/test.yml +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/.gitignore +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/.pre-commit-config.yaml +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/.python-version +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/Makefile +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/README.md +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/docs/adls_server.md +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/docs/azure_credential_manager.md +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/docs/diagrams/README.md +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/docs/diagrams/orca_cloud_workflow.drawio +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/docs/diagrams/orca_detailed_steps.drawio +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/docs/diagrams/orca_file_structure.drawio +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/docs/diagrams/orca_local_workflow.drawio +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/docs/diagrams/orca_main_features.drawio +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/docs/unified_logging.md +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/requirements.txt +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/examples/batchtask.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/examples/data_files/example.csv +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/examples/mydataproject.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/examples/readwritedata.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/examples/unified_logging.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/azure_credential.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/config.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/data.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/data_store.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/env_config.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/log.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/orca/README.md +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/orca/__init__.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/orca/__main__.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/orca/cli.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/orca/orca_model_config_barebone.yaml +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/orca/orca_model_config_example.yaml +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/src/tlpytools/sql_server.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/tests/README.md +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/tests/__init__.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/tests/conftest.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/tests/run_tests.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/tests/test_azure_credential.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/tests/test_basic.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/tests/test_core.py +0 -0
- {tlpytools-0.2.7 → tlpytools-0.2.9}/tests/test_orca_integration.py +0 -0
|
@@ -14,9 +14,12 @@ AZURE_SUBSCRIPTION_ID=your-subscription-id
|
|
|
14
14
|
AZURE_RESOURCE_GROUP=your-resource-group
|
|
15
15
|
MANAGED_IDENTITY_NAME=your-managed-identity
|
|
16
16
|
|
|
17
|
+
# Optional Environment Variables for Azure Batch (Do not set these unless for testing different VM set up for Batch)
|
|
18
|
+
# AZ_BATCH_NODE_CUSTOM_MOUNT=$AZ_BATCH_NODE_MOUNTS_DIR/datadisk
|
|
19
|
+
|
|
17
20
|
# Azure Data Lake Storage
|
|
18
21
|
ORCA_ADLS_URL=yourstorageaccount.dfs.core.windows.net
|
|
19
|
-
|
|
22
|
+
ORCA_ADLS_CONTAINER_PATH=yourcontainer/sub/path
|
|
20
23
|
|
|
21
24
|
# Azure SQL Server URI
|
|
22
25
|
TLPT_AZURE_SQL_URI=yoursever.database.windows.net
|
|
@@ -98,8 +98,8 @@ Interpretation for agent PRs:
|
|
|
98
98
|
|
|
99
99
|
Observed result:
|
|
100
100
|
- Build succeeds and produces:
|
|
101
|
-
- `dist/tlpytools-0.2.
|
|
102
|
-
- `dist/tlpytools-0.2.
|
|
101
|
+
- `dist/tlpytools-0.2.9.tar.gz`
|
|
102
|
+
- `dist/tlpytools-0.2.9-py3-none-any.whl`
|
|
103
103
|
|
|
104
104
|
### 5) Run
|
|
105
105
|
- ORCA CLI (module form):
|
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to TLPyTools will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.2.9]
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
- **`initialize_scenario.input_data` now supports per-entry `exclude` lists:**
|
|
9
|
+
- Each source entry in an `input_data` category can now be a dict `{path: ..., exclude: [...]}` instead of a plain path string
|
|
10
|
+
- The `exclude` list contains file/directory names to skip when copying that specific source
|
|
11
|
+
- Applies to both directory copies (item-by-item scan) and glob-pattern matches
|
|
12
|
+
- Example: `- {path: shared/inputs, exclude: [large_file.csv, scratch/]}`
|
|
13
|
+
|
|
14
|
+
## [0.2.8]
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- **Renamed `ORCA_ADLS_CONTAINER` to `ORCA_ADLS_CONTAINER_PATH`:**
|
|
18
|
+
- Variable now accepts either a bare container name (`mycontainer`) or a container with a sub-path (`mycontainer/projects/v2`)
|
|
19
|
+
- The first path segment is used as the ADLS filesystem (container) name; any remaining segments are prepended to the project folder path
|
|
20
|
+
- **Breaking Change**: Users must rename `ORCA_ADLS_CONTAINER` to `ORCA_ADLS_CONTAINER_PATH` in their `.env` files
|
|
21
|
+
- **Configurable Azure Batch node mount path via `AZ_BATCH_NODE_CUSTOM_MOUNT`:**
|
|
22
|
+
- Replaces the hardcoded `$AZ_BATCH_NODE_MOUNTS_DIR/datadisk` volume mount in `BatchTaskRunner`
|
|
23
|
+
- Default: `$AZ_BATCH_NODE_MOUNTS_DIR/datadisk` (virtual file system mount on the Azure Batch VM node)
|
|
24
|
+
- Override to use task working directory, e.g. `$AZ_BATCH_TASK_WORKING_DIR`
|
|
25
|
+
- See [Azure Batch: Files and directories](https://learn.microsoft.com/en-us/azure/batch/files-and-directories) for available node environment variables
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
- **`InvalidQueryParameterValue` error when `ORCA_ADLS_CONTAINER_PATH` contains a sub-path:**
|
|
29
|
+
- The ADLS SDK requires the filesystem (container) name to be a single path component with no slashes
|
|
30
|
+
- `_get_adls_config` now splits the value on the first `/` and prepends any sub-path to `adls_folder`
|
|
31
|
+
|
|
5
32
|
## [0.2.7]
|
|
6
33
|
|
|
7
34
|
### Fixed
|
|
@@ -200,7 +200,7 @@ make check-all
|
|
|
200
200
|
4. Click **"Run workflow"** button
|
|
201
201
|
5. Fill in the required information:
|
|
202
202
|
- **Branch**: Select `main` (or your release branch)
|
|
203
|
-
- **Version number**: Enter the new version (e.g., `0.2.
|
|
203
|
+
- **Version number**: Enter the new version (e.g., `0.2.9`)
|
|
204
204
|
- **Is this a pre-release?**: Check if this is a pre-release version
|
|
205
205
|
|
|
206
206
|
#### 3. Monitor the Release
|
|
@@ -219,7 +219,7 @@ After the workflow completes:
|
|
|
219
219
|
|
|
220
220
|
```bash
|
|
221
221
|
# Verify the package is available on PyPI
|
|
222
|
-
pip install tlpytools==0.2.
|
|
222
|
+
pip install tlpytools==0.2.9 # Replace with your version
|
|
223
223
|
|
|
224
224
|
# Test installation in a fresh environment
|
|
225
225
|
python -c "import tlpytools; print(tlpytools.__version__)"
|
|
@@ -53,6 +53,14 @@ nano .env # Linux/macOS
|
|
|
53
53
|
- Note: The https:// prefix is automatically added by the application
|
|
54
54
|
- **Breaking Change**: Previously used "yourstorageaccount.dfs.core.windows.net" as default
|
|
55
55
|
|
|
56
|
+
- `ORCA_ADLS_CONTAINER_PATH`: ADLS container name, optionally followed by a sub-path to scope all operations under a specific directory within that container.
|
|
57
|
+
- Format: `{container}` or `{container}/{sub/path}`
|
|
58
|
+
- Example (container only): `mycontainer`
|
|
59
|
+
- Example (container + sub-path): `mycontainer/projects/v2`
|
|
60
|
+
- Used by: orchestrator.py
|
|
61
|
+
- **Strictly Required**: Application will fail with ValueError if not set
|
|
62
|
+
- Note: The first path segment is used as the ADLS filesystem (container) name; any remaining segments are prepended to the project folder path.
|
|
63
|
+
|
|
56
64
|
### Azure SQL Server
|
|
57
65
|
- `TLPT_AZURE_SQL_URI`: Azure SQL Server URI
|
|
58
66
|
- Example: `yourserver.database.windows.net`
|
|
@@ -109,6 +117,10 @@ See ENVIRONMENT_VARIABLES.md for details.
|
|
|
109
117
|
- Default: `2024-07-01.20.0`
|
|
110
118
|
- Used by: batch_task_runner.py
|
|
111
119
|
|
|
120
|
+
- `AZ_BATCH_NODE_CUSTOM_MOUNT`: Path on the Azure Batch VM node to mount into the Docker container's working directory (`/home/ubuntu/wd`). This should be a directory accessible to the task on the node. Use Azure Batch built-in environment variables to reference standard node paths — for example, `$AZ_BATCH_NODE_MOUNTS_DIR/<mountname>` (a virtual file system mounted on the node) or `$AZ_BATCH_TASK_WORKING_DIR` (the task's own working directory). See [Azure Batch: Files and directories](https://learn.microsoft.com/en-us/azure/batch/files-and-directories) for the full list of available node environment variables.
|
|
121
|
+
- Default: `$AZ_BATCH_NODE_MOUNTS_DIR/datadisk`
|
|
122
|
+
- Used by: batch_task_runner.py
|
|
123
|
+
|
|
112
124
|
### Cache Configuration
|
|
113
125
|
- `TLPT_ADLS_CACHE_DIR`: Directory for ADLS cache files
|
|
114
126
|
- Default: `C:/Temp/tlpytools/adls`
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: tlpytools
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.9
|
|
4
4
|
Summary: TransLink's Python Tools - A comprehensive toolkit for transportation modeling and forecasting
|
|
5
5
|
Project-URL: Homepage, https://github.com/TransLinkForecasting/tlpytools
|
|
6
6
|
Project-URL: Bug Tracker, https://github.com/TransLinkForecasting/tlpytools/issues
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tlpytools"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.9"
|
|
8
8
|
description = "TransLink's Python Tools - A comprehensive toolkit for transportation modeling and forecasting"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10.0, <3.13"
|
|
@@ -6,7 +6,11 @@ import time
|
|
|
6
6
|
from functools import wraps
|
|
7
7
|
from io import BytesIO
|
|
8
8
|
|
|
9
|
-
from azure.core.exceptions import
|
|
9
|
+
from azure.core.exceptions import (
|
|
10
|
+
HttpResponseError,
|
|
11
|
+
ResourceNotFoundError,
|
|
12
|
+
ServiceRequestError,
|
|
13
|
+
)
|
|
10
14
|
from azure.storage.filedatalake import (
|
|
11
15
|
DataLakeDirectoryClient,
|
|
12
16
|
# DataLakeServiceClient,
|
|
@@ -104,9 +108,19 @@ class adls_util(UnifiedLogger):
|
|
|
104
108
|
|
|
105
109
|
# Optimized chunk sizes for different file sizes
|
|
106
110
|
UPLOAD_CHUNK_SIZE_SMALL = 4 * 1024 * 1024 # 4MB for files < 100MB
|
|
107
|
-
UPLOAD_CHUNK_SIZE_MEDIUM =
|
|
111
|
+
UPLOAD_CHUNK_SIZE_MEDIUM = (
|
|
112
|
+
8 * 1024 * 1024
|
|
113
|
+
) # 8MB for files < 1GB (reduced to limit per-write socket time)
|
|
108
114
|
UPLOAD_CHUNK_SIZE_LARGE = 100 * 1024 * 1024 # 100MB for files >= 1GB
|
|
109
115
|
MAX_CONCURRENCY_DEFAULT = 4 # Default parallel threads for large files
|
|
116
|
+
UPLOAD_MAX_RETRIES = 3 # Retries on connection/timeout errors
|
|
117
|
+
# Dynamic socket timeout: per-chunk timeout = chunk_size / (MIN_TRANSFER_SPEED_MBPS * 125000) * FACTOR
|
|
118
|
+
MIN_TRANSFER_SPEED_MBPS = 2 # Conservative minimum speed (Mbps) — set lower than worst-case user connection
|
|
119
|
+
SOCKET_TIMEOUT_SAFETY_FACTOR = (
|
|
120
|
+
3 # Multiply calculated per-chunk transfer time by this before using as timeout
|
|
121
|
+
)
|
|
122
|
+
MIN_SOCKET_TIMEOUT_SECS = 60 # Floor: never set a socket timeout below this value
|
|
123
|
+
DOWNLOAD_CHUNK_SIZE_BYTES = 4 * 1024 * 1024 # Azure SDK default download chunk size
|
|
110
124
|
|
|
111
125
|
def __init__(self, logger: logging.Logger = None):
|
|
112
126
|
"""
|
|
@@ -150,6 +164,19 @@ class adls_util(UnifiedLogger):
|
|
|
150
164
|
except ResourceNotFoundError:
|
|
151
165
|
return False
|
|
152
166
|
|
|
167
|
+
@classmethod
|
|
168
|
+
def _calculate_chunk_timeout(cls, chunk_size_bytes: int) -> int:
|
|
169
|
+
"""Socket read/write timeout for one chunk at MIN_TRANSFER_SPEED_MBPS with safety margin."""
|
|
170
|
+
speed_bytes_per_sec = cls.MIN_TRANSFER_SPEED_MBPS * 1024 * 1024 / 8
|
|
171
|
+
return max(
|
|
172
|
+
int(
|
|
173
|
+
chunk_size_bytes
|
|
174
|
+
/ speed_bytes_per_sec
|
|
175
|
+
* cls.SOCKET_TIMEOUT_SAFETY_FACTOR
|
|
176
|
+
),
|
|
177
|
+
cls.MIN_SOCKET_TIMEOUT_SECS,
|
|
178
|
+
)
|
|
179
|
+
|
|
153
180
|
@classmethod
|
|
154
181
|
def upload_file_to_directory(
|
|
155
182
|
cls,
|
|
@@ -213,20 +240,38 @@ class adls_util(UnifiedLogger):
|
|
|
213
240
|
else:
|
|
214
241
|
max_concurrency = 1 # Single-threaded for small files
|
|
215
242
|
|
|
216
|
-
#
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
243
|
+
# Per-chunk socket timeout scaled to minimum expected transfer speed
|
|
244
|
+
socket_timeout = cls._calculate_chunk_timeout(chunk_size)
|
|
245
|
+
|
|
246
|
+
# upload file with retry logic for transient connection/timeout errors
|
|
247
|
+
for attempt in range(cls.UPLOAD_MAX_RETRIES):
|
|
248
|
+
try:
|
|
249
|
+
with open(file=file_path, mode="rb") as data:
|
|
250
|
+
file_client.upload_data(
|
|
251
|
+
data,
|
|
252
|
+
overwrite=True,
|
|
253
|
+
timeout=cls.UPLOAD_TIMEOUT_SECS,
|
|
254
|
+
chunk_size=chunk_size,
|
|
255
|
+
max_concurrency=max_concurrency,
|
|
256
|
+
read_timeout=socket_timeout,
|
|
257
|
+
connection_timeout=socket_timeout,
|
|
258
|
+
)
|
|
259
|
+
break # success
|
|
260
|
+
except ServiceRequestError as e:
|
|
261
|
+
if attempt < cls.UPLOAD_MAX_RETRIES - 1:
|
|
262
|
+
wait_secs = 5 * (2**attempt) # 5s, 10s
|
|
263
|
+
logger.warning(
|
|
264
|
+
"Upload attempt %d/%d failed for %s (connection error, socket_timeout=%ds): %s. Retrying in %ds...",
|
|
265
|
+
attempt + 1,
|
|
266
|
+
cls.UPLOAD_MAX_RETRIES,
|
|
267
|
+
local_file_name,
|
|
268
|
+
socket_timeout,
|
|
269
|
+
e,
|
|
270
|
+
wait_secs,
|
|
271
|
+
)
|
|
272
|
+
time.sleep(wait_secs)
|
|
273
|
+
else:
|
|
274
|
+
raise
|
|
230
275
|
|
|
231
276
|
logger.debug(
|
|
232
277
|
"Successfully uploaded %s (size: %.2f MB, chunk: %.1f MB, concurrency: %d)",
|
|
@@ -273,9 +318,16 @@ class adls_util(UnifiedLogger):
|
|
|
273
318
|
else:
|
|
274
319
|
max_concurrency = 1 # Single-threaded for small files
|
|
275
320
|
|
|
321
|
+
# Per-chunk socket timeout scaled to minimum expected transfer speed
|
|
322
|
+
socket_timeout = cls._calculate_chunk_timeout(cls.DOWNLOAD_CHUNK_SIZE_BYTES)
|
|
323
|
+
|
|
276
324
|
# Download with parallel streams for better performance
|
|
277
325
|
# Note: Azure SDK handles chunk sizing internally for downloads
|
|
278
|
-
download_stream = file_client.download_file(
|
|
326
|
+
download_stream = file_client.download_file(
|
|
327
|
+
max_concurrency=max_concurrency,
|
|
328
|
+
read_timeout=socket_timeout,
|
|
329
|
+
connection_timeout=socket_timeout,
|
|
330
|
+
)
|
|
279
331
|
data_bytes = download_stream.readall()
|
|
280
332
|
bytes_io = BytesIO(data_bytes)
|
|
281
333
|
|
|
@@ -227,10 +227,13 @@ class BatchTaskRunner:
|
|
|
227
227
|
|
|
228
228
|
# Build base container run options
|
|
229
229
|
# - /dev/shm is mounted for shared memory access, which is required for memory intensive programs
|
|
230
|
-
# -
|
|
230
|
+
# - AZ_BATCH_NODE_CUSTOM_MOUNT is the path on the Azure Batch VM node mounted to the docker container working directory
|
|
231
|
+
node_mount_path = get_env_var(
|
|
232
|
+
"AZ_BATCH_NODE_CUSTOM_MOUNT", "$AZ_BATCH_NODE_MOUNTS_DIR/datadisk"
|
|
233
|
+
)
|
|
231
234
|
container_run_options = (
|
|
232
235
|
"--workdir /home/ubuntu/wd --rm --volume /dev/shm:/dev/shm "
|
|
233
|
-
"--volume
|
|
236
|
+
f"--volume {node_mount_path}:/home/ubuntu/wd"
|
|
234
237
|
)
|
|
235
238
|
|
|
236
239
|
# Add entrypoint only if both override_python_env and override_python_command are provided
|
|
@@ -69,8 +69,12 @@ class OrcaLogger:
|
|
|
69
69
|
"""
|
|
70
70
|
Centralized logger class for ORCA orchestrator and related utilities.
|
|
71
71
|
|
|
72
|
-
Each instance creates
|
|
73
|
-
|
|
72
|
+
Each instance creates a fully isolated logger for a specific scenario.
|
|
73
|
+
The logger name is built from a git-derived base (tag > SHA > random UUID)
|
|
74
|
+
combined with an 8-character MD5 hash of the scenario folder name, e.g.
|
|
75
|
+
``orca_1cd9559.a3f2b891``. This guarantees that two OrcaOrchestrator
|
|
76
|
+
instances initialised in the same Python session always own separate
|
|
77
|
+
``logging.Logger`` objects, preventing cross-scenario log contamination.
|
|
74
78
|
"""
|
|
75
79
|
|
|
76
80
|
def __init__(self, log_file_path: str | None = None, log_level: int = logging.INFO):
|
|
@@ -120,7 +124,8 @@ class OrcaLogger:
|
|
|
120
124
|
|
|
121
125
|
def _setup_logger(self):
|
|
122
126
|
"""Set up the logger with consistent formatting and handlers."""
|
|
123
|
-
#
|
|
127
|
+
# Logger name is unique per scenario (git-base + scenario-folder hash),
|
|
128
|
+
# so getLogger always returns a fresh object; clearing handlers is safe.
|
|
124
129
|
logger_name = self._resolve_logger_name()
|
|
125
130
|
|
|
126
131
|
# Create logger
|
|
@@ -174,14 +179,22 @@ class OrcaLogger:
|
|
|
174
179
|
"""
|
|
175
180
|
Resolve a stable logger name using git metadata when available.
|
|
176
181
|
|
|
177
|
-
|
|
182
|
+
The name is made unique per scenario by appending the scenario folder name
|
|
183
|
+
(derived from the log file path), preventing logger-object sharing when
|
|
184
|
+
multiple OrcaOrchestrator instances are created in the same Python session.
|
|
185
|
+
|
|
186
|
+
Priority for base name:
|
|
178
187
|
1. Git tag pointing at HEAD -> f"orca_{tag}"
|
|
179
188
|
2. Git SHA (first 7 chars) -> f"orca_{sha}"
|
|
180
189
|
3. Random session UUID -> f"session_{uuid8}"
|
|
190
|
+
|
|
191
|
+
Scenario suffix: grandparent directory of the log file
|
|
192
|
+
(i.e. <scenario>/logs/orca_*.log -> <scenario>)
|
|
181
193
|
"""
|
|
182
194
|
project_cwd = os.getcwd()
|
|
195
|
+
base_name = None
|
|
196
|
+
|
|
183
197
|
try:
|
|
184
|
-
# Priority 1: git tag pointing exactly at HEAD
|
|
185
198
|
tag_result = subprocess.run(
|
|
186
199
|
["git", "describe", "--tags", "--exact-match", "HEAD"],
|
|
187
200
|
capture_output=True,
|
|
@@ -192,30 +205,45 @@ class OrcaLogger:
|
|
|
192
205
|
if tag_result.returncode == 0:
|
|
193
206
|
git_version = tag_result.stdout.strip()
|
|
194
207
|
if git_version:
|
|
195
|
-
|
|
208
|
+
base_name = f"orca_{git_version}"
|
|
196
209
|
except Exception:
|
|
197
210
|
pass
|
|
198
211
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
if base_name is None:
|
|
213
|
+
try:
|
|
214
|
+
sha_result = subprocess.run(
|
|
215
|
+
["git", "rev-parse", "--short=7", "HEAD"],
|
|
216
|
+
capture_output=True,
|
|
217
|
+
text=True,
|
|
218
|
+
timeout=5,
|
|
219
|
+
cwd=project_cwd,
|
|
220
|
+
)
|
|
221
|
+
if sha_result.returncode == 0:
|
|
222
|
+
git_sha = sha_result.stdout.strip()
|
|
223
|
+
if git_sha:
|
|
224
|
+
base_name = f"orca_{git_sha}"
|
|
225
|
+
except Exception:
|
|
226
|
+
pass
|
|
227
|
+
|
|
228
|
+
if base_name is None:
|
|
229
|
+
import uuid
|
|
214
230
|
|
|
215
|
-
|
|
216
|
-
|
|
231
|
+
base_name = f"session_{uuid.uuid4().hex[:8]}"
|
|
232
|
+
|
|
233
|
+
# Append a short hash of the scenario folder so each orchestrator gets its own logger tree
|
|
234
|
+
if self._log_file_path:
|
|
235
|
+
try:
|
|
236
|
+
import hashlib
|
|
237
|
+
from pathlib import Path as _Path
|
|
238
|
+
|
|
239
|
+
scenario_folder = _Path(self._log_file_path).parent.parent.name
|
|
240
|
+
if scenario_folder:
|
|
241
|
+
suffix = hashlib.md5(scenario_folder.encode()).hexdigest()[:8]
|
|
242
|
+
return f"{base_name}.{suffix}"
|
|
243
|
+
except Exception:
|
|
244
|
+
pass
|
|
217
245
|
|
|
218
|
-
return
|
|
246
|
+
return base_name
|
|
219
247
|
|
|
220
248
|
def _log_system_info(self):
|
|
221
249
|
"""
|
|
@@ -346,11 +374,19 @@ def get_orca_logger(
|
|
|
346
374
|
log_level: int = logging.INFO,
|
|
347
375
|
):
|
|
348
376
|
"""
|
|
349
|
-
|
|
377
|
+
Create and return an ORCA logger (or a named child of one).
|
|
378
|
+
|
|
379
|
+
Each call constructs a new OrcaLogger whose underlying ``logging.Logger``
|
|
380
|
+
name encodes both the git revision and an 8-char hash of the scenario
|
|
381
|
+
folder derived from ``log_file_path``. This makes every scenario
|
|
382
|
+
instance in a session use its own isolated logger tree, so handlers
|
|
383
|
+
and log output never bleed between concurrent or sequential runs.
|
|
350
384
|
|
|
351
385
|
Args:
|
|
352
|
-
name:
|
|
353
|
-
|
|
386
|
+
name: If provided, returns a child logger with this suffix
|
|
387
|
+
(e.g. ``"orchestrator"`` yields ``orca_<sha>.<hash>.orchestrator``).
|
|
388
|
+
log_file_path: Path to the scenario log file; used to derive the
|
|
389
|
+
scenario-specific hash component of the logger name.
|
|
354
390
|
log_level: Logging level (e.g., logging.DEBUG, logging.INFO). Defaults to INFO.
|
|
355
391
|
|
|
356
392
|
Returns:
|
|
@@ -1761,6 +1797,10 @@ class OrcaScenario:
|
|
|
1761
1797
|
|
|
1762
1798
|
with zipfile.ZipFile(zip_path, "w", **zip_kwargs) as zf:
|
|
1763
1799
|
for root, dirs, files in os.walk(dir_path, topdown=True):
|
|
1800
|
+
# Sort dirs and files for deterministic archive member order
|
|
1801
|
+
# across machines with different filesystem orderings.
|
|
1802
|
+
dirs.sort()
|
|
1803
|
+
files = sorted(files)
|
|
1764
1804
|
# Filter directories for traversal
|
|
1765
1805
|
dirs_to_remove = set()
|
|
1766
1806
|
for d in dirs:
|
|
@@ -1849,7 +1889,7 @@ class OrcaScenario:
|
|
|
1849
1889
|
full_pattern = os.path.join(base_dir, pattern)
|
|
1850
1890
|
|
|
1851
1891
|
# Find all files matching the pattern
|
|
1852
|
-
matching_files = glob.glob(full_pattern, recursive=True)
|
|
1892
|
+
matching_files = sorted(glob.glob(full_pattern, recursive=True))
|
|
1853
1893
|
|
|
1854
1894
|
# Delete each file
|
|
1855
1895
|
for file_path in matching_files:
|
|
@@ -3108,13 +3148,23 @@ class OrcaOrchestrator:
|
|
|
3108
3148
|
category_dir = os.path.join(input_data_dir, data_category)
|
|
3109
3149
|
os.makedirs(category_dir, exist_ok=True)
|
|
3110
3150
|
|
|
3111
|
-
#
|
|
3112
|
-
|
|
3113
|
-
|
|
3151
|
+
# Normalise: sources may be a plain list of strings, or a list where each
|
|
3152
|
+
# entry is either a plain path string or a dict {path: ..., exclude: [...]}.
|
|
3153
|
+
# The exclude list applies only to the source entry it is defined on.
|
|
3154
|
+
if not isinstance(sources, list):
|
|
3155
|
+
sources = [sources]
|
|
3156
|
+
|
|
3157
|
+
for source_entry in sources:
|
|
3158
|
+
# Each entry is a plain path string OR {path: ..., exclude: [...]}
|
|
3159
|
+
if isinstance(source_entry, dict):
|
|
3160
|
+
source_path = source_entry.get("path", "")
|
|
3161
|
+
entry_exclude = set(source_entry.get("exclude", []))
|
|
3162
|
+
else:
|
|
3163
|
+
source_path = source_entry
|
|
3164
|
+
entry_exclude = set()
|
|
3114
3165
|
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
self.logger.warning("Invalid source entry format: %s", source_path)
|
|
3166
|
+
if not isinstance(source_path, str) or not source_path:
|
|
3167
|
+
self.logger.warning("Invalid source entry format: %s", source_entry)
|
|
3118
3168
|
continue
|
|
3119
3169
|
|
|
3120
3170
|
# Resolve source path relative to scenario parent directory
|
|
@@ -3124,12 +3174,35 @@ class OrcaOrchestrator:
|
|
|
3124
3174
|
|
|
3125
3175
|
if os.path.exists(full_source_path):
|
|
3126
3176
|
if os.path.isdir(full_source_path):
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3177
|
+
if entry_exclude:
|
|
3178
|
+
# Copy directory contents item-by-item, skipping excluded names.
|
|
3179
|
+
for entry in os.scandir(full_source_path):
|
|
3180
|
+
if entry.name in entry_exclude:
|
|
3181
|
+
self.logger.debug(
|
|
3182
|
+
"Skipping excluded input data item: %s",
|
|
3183
|
+
entry.name,
|
|
3184
|
+
)
|
|
3185
|
+
continue
|
|
3186
|
+
target = os.path.join(category_dir, entry.name)
|
|
3187
|
+
if entry.is_dir():
|
|
3188
|
+
self.scenario.copy_template_directory(
|
|
3189
|
+
source_dir=entry.path,
|
|
3190
|
+
target_dir=target,
|
|
3191
|
+
overwrite=False,
|
|
3192
|
+
)
|
|
3193
|
+
else:
|
|
3194
|
+
self.scenario.copy_template_file(
|
|
3195
|
+
source_file=entry.path,
|
|
3196
|
+
target_file=target,
|
|
3197
|
+
overwrite=False,
|
|
3198
|
+
)
|
|
3199
|
+
else:
|
|
3200
|
+
# Copy directory
|
|
3201
|
+
self.scenario.copy_template_directory(
|
|
3202
|
+
source_dir=full_source_path,
|
|
3203
|
+
target_dir=category_dir,
|
|
3204
|
+
overwrite=False,
|
|
3205
|
+
)
|
|
3133
3206
|
else:
|
|
3134
3207
|
# Copy file
|
|
3135
3208
|
self.scenario.copy_template_file(
|
|
@@ -3146,6 +3219,8 @@ class OrcaOrchestrator:
|
|
|
3146
3219
|
matching_files = glob.glob(full_source_path)
|
|
3147
3220
|
if matching_files:
|
|
3148
3221
|
for file_path in matching_files:
|
|
3222
|
+
if os.path.basename(file_path) in exclude_names:
|
|
3223
|
+
continue
|
|
3149
3224
|
self.scenario.copy_template_file(
|
|
3150
3225
|
source_file=file_path,
|
|
3151
3226
|
target_file=os.path.join(
|
|
@@ -4172,9 +4247,23 @@ class OrcaOrchestrator:
|
|
|
4172
4247
|
adls_base = get_env_var("ORCA_ADLS_URL", required=True)
|
|
4173
4248
|
adls_url = f"https://{adls_base}"
|
|
4174
4249
|
|
|
4175
|
-
|
|
4250
|
+
adls_container_raw = get_env_var("ORCA_ADLS_CONTAINER_PATH", required=True)
|
|
4251
|
+
# The filesystem name must be a single path component; split any sub-path out
|
|
4252
|
+
container_parts = adls_container_raw.split("/", 1)
|
|
4253
|
+
adls_container = container_parts[0]
|
|
4254
|
+
container_path_prefix = container_parts[1] if len(container_parts) > 1 else ""
|
|
4255
|
+
if container_path_prefix:
|
|
4256
|
+
self.logger.debug(
|
|
4257
|
+
"ORCA_ADLS_CONTAINER_PATH contains a path prefix '%s'; prepending to folder",
|
|
4258
|
+
container_path_prefix,
|
|
4259
|
+
)
|
|
4176
4260
|
|
|
4177
|
-
|
|
4261
|
+
base_folder = self.project_folder_override or "proj_unnamed"
|
|
4262
|
+
adls_folder = (
|
|
4263
|
+
f"{container_path_prefix}/{base_folder}"
|
|
4264
|
+
if container_path_prefix
|
|
4265
|
+
else base_folder
|
|
4266
|
+
)
|
|
4178
4267
|
if self.project_folder_override:
|
|
4179
4268
|
self.logger.info("Using project folder override: %s", adls_folder)
|
|
4180
4269
|
|
|
@@ -6602,7 +6691,7 @@ class OrcaOrchestrator:
|
|
|
6602
6691
|
# Find all output archives that need to be backed up
|
|
6603
6692
|
backup_operations = []
|
|
6604
6693
|
|
|
6605
|
-
for filename in os.listdir(outputs_dir):
|
|
6694
|
+
for filename in sorted(os.listdir(outputs_dir)):
|
|
6606
6695
|
if not filename.endswith(".zip"):
|
|
6607
6696
|
continue
|
|
6608
6697
|
|
|
@@ -7739,11 +7828,10 @@ class OrcaUtil:
|
|
|
7739
7828
|
os.startfile(folder_path)
|
|
7740
7829
|
|
|
7741
7830
|
button.on_click(on_button_clicked)
|
|
7742
|
-
print(f"\n{folder_path}")
|
|
7743
7831
|
display(button)
|
|
7744
7832
|
except (ImportError, NameError):
|
|
7745
7833
|
# Fallback for non-Jupyter environments
|
|
7746
|
-
print(f"
|
|
7834
|
+
print(f"{folder_name}: {folder_path}")
|
|
7747
7835
|
|
|
7748
7836
|
@staticmethod
|
|
7749
7837
|
def check_cloud_config(orchestrator: "OrcaOrchestrator") -> dict:
|
|
@@ -7788,7 +7876,7 @@ class OrcaUtil:
|
|
|
7788
7876
|
# Required environment variables for cloud operations
|
|
7789
7877
|
required_env_vars = [
|
|
7790
7878
|
"ORCA_ADLS_URL",
|
|
7791
|
-
"
|
|
7879
|
+
"ORCA_ADLS_CONTAINER_PATH",
|
|
7792
7880
|
"BATCH_ACCOUNT_ENDPOINT",
|
|
7793
7881
|
"IMAGE_REGISTRY_ENDPOINT",
|
|
7794
7882
|
"AZURE_SUBSCRIPTION_ID",
|
|
@@ -7845,7 +7933,7 @@ class OrcaUtil:
|
|
|
7845
7933
|
|
|
7846
7934
|
# Get cloud configuration from environment variables
|
|
7847
7935
|
adls_url = os.getenv("ORCA_ADLS_URL", "")
|
|
7848
|
-
adls_container = os.getenv("
|
|
7936
|
+
adls_container = os.getenv("ORCA_ADLS_CONTAINER_PATH", "")
|
|
7849
7937
|
adls_folder = orchestrator.project_folder_override or ""
|
|
7850
7938
|
|
|
7851
7939
|
# Print detailed configuration status
|
|
@@ -7916,7 +8004,9 @@ class OrcaUtil:
|
|
|
7916
8004
|
print(
|
|
7917
8005
|
" 1. Set required environment variables in your .env file (see ENVIRONMENT_VARIABLES.md)"
|
|
7918
8006
|
)
|
|
7919
|
-
print(
|
|
8007
|
+
print(
|
|
8008
|
+
" 2. Ensure ORCA_ADLS_URL and ORCA_ADLS_CONTAINER_PATH are set correctly"
|
|
8009
|
+
)
|
|
7920
8010
|
print(" 3. Install and authenticate Azure CLI (az login)")
|
|
7921
8011
|
print(" 4. Verify managed identity or CLI credential is enabled")
|
|
7922
8012
|
|
|
@@ -558,9 +558,9 @@ class TestOrcaOrchestrator(unittest.TestCase):
|
|
|
558
558
|
"ORCA_ADLS_URL", env_vars, "ORCA_ADLS_URL missing from .env.example"
|
|
559
559
|
)
|
|
560
560
|
self.assertIn(
|
|
561
|
-
"
|
|
561
|
+
"ORCA_ADLS_CONTAINER_PATH",
|
|
562
562
|
env_vars,
|
|
563
|
-
"
|
|
563
|
+
"ORCA_ADLS_CONTAINER_PATH missing from .env.example",
|
|
564
564
|
)
|
|
565
565
|
|
|
566
566
|
with patch.dict(os.environ, env_vars):
|
|
@@ -570,8 +570,13 @@ class TestOrcaOrchestrator(unittest.TestCase):
|
|
|
570
570
|
adls_url, adls_container, adls_folder = orchestrator.get_adls_config()
|
|
571
571
|
|
|
572
572
|
self.assertEqual(adls_url, f"https://{env_vars['ORCA_ADLS_URL']}")
|
|
573
|
-
|
|
574
|
-
self.assertEqual(
|
|
573
|
+
container_parts = env_vars["ORCA_ADLS_CONTAINER_PATH"].split("/", 1)
|
|
574
|
+
self.assertEqual(adls_container, container_parts[0])
|
|
575
|
+
container_prefix = container_parts[1] if len(container_parts) > 1 else ""
|
|
576
|
+
expected_folder = (
|
|
577
|
+
f"{container_prefix}/test_folder" if container_prefix else "test_folder"
|
|
578
|
+
)
|
|
579
|
+
self.assertEqual(adls_folder, expected_folder)
|
|
575
580
|
|
|
576
581
|
def test_input_data_initialization(self):
|
|
577
582
|
"""Test that input_data configuration is properly loaded."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|