Skip to content

Commit e2b07ee

Browse files
authored
Update from upstream. (#59)
* Update from upstream. Some changes: - compatibility with configs and Metaflow 2.16+ (new packaging) - updates to better support Mamba 2.0 - lots of bug fixes around debugging command * Forgot one change * Trying to fix tests/installs * Change to prefix.dev mirror. Remove borked test * Cleanup yml test file * Wrong channel alias * Fix tests * More test fixes; hopefully for real * Fix and can now use 2.3.2 * Strip out build info for glibc * Remove broken test for 3.8 * Remove borked test
1 parent 5df045d commit e2b07ee

28 files changed

Lines changed: 1727 additions & 544 deletions

.github/workflows/test.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
fail-fast: false
2020
matrix:
2121
os: [ubuntu-latest, macos-latest]
22-
python-version: ["3.8", "3.10", "3.12"]
22+
python-version: ["3.8", "3.10", "3.12", "3.13"]
2323
resolver: [mamba, conda, micromamba]
2424
micromamba-version: ["1.5.10-0", "latest"]
2525
mamba-version: ["mamba=1.5.10", "mamba"]
@@ -34,22 +34,29 @@ jobs:
3434
mamba-version: "mamba=1.5.10"
3535
- python-version: "3.8"
3636
mamba-version: "mamba=1.5.10"
37+
- python-version: "3.13"
38+
mamba-version: "mamba=1.5.10"
3739
env:
3840
METAFLOW_CONDA_DEPENDENCY_RESOLVER: ${{ matrix.resolver }}
3941
METAFLOW_CONDA_TEST: 1
4042
METAFLOW_DATASTORE_SYSROOT_LOCAL: .metaflow
43+
METAFLOW_HACK_CONDA_CHANNEL_ALIAS: prefix.dev
4144
steps:
4245
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
4346

44-
- uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 # v1.9.0
47+
- uses: mamba-org/setup-micromamba@b09ef9b599704322748535812ca03efb2625677b # v2.0.5
4548
with:
4649
micromamba-version: ${{ matrix.micromamba-version }}
4750
environment-file: dev-env.yml
4851
init-shell: bash
52+
post-cleanup: all
53+
condarc: |
54+
channels:
55+
- conda-forge
56+
channel_alias: https://prefix.dev
4957
create-args: >-
5058
python=${{ matrix.python-version }}
5159
${{ matrix.mamba-version }}
52-
5360
- name: install nflx-extension
5461
shell: bash -eo pipefail -l {0}
5562
run: |

metaflow_extensions/netflix_ext/cmd/debug/constants.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
class Constants(object):
77
# Default Python version
8-
DEFAULT_PYTHON_VERSION = "3.7"
8+
DEFAULT_PYTHON_VERSION = "3.10"
9+
10+
# Name of the main debug file
11+
DEBUG_SCRIPT_NAME = "00_DEBUG_ME.ipynb"
912

1013
# Stubbed class for Metaflow artifacts
1114
DEBUG_INPUT_ITEM_STUB = """
@@ -115,6 +118,12 @@ def __getattr__(self, name):
115118
116119
raise AttributeError(f"No such attribute: {{name}}")
117120
121+
def __delattr__(self, name):
122+
if name in self._artifact_data:
123+
del self._artifact_data[name]
124+
return
125+
return super().__delattr__(name)
126+
118127
def load_artifact_data(self, name):
119128
for artifact in self._prev_task.artifacts:
120129
if artifact.id == name:
@@ -236,9 +245,10 @@ def merge_artifacts(
236245

237246
# Escape hatch stub
238247
ESCAPE_HATCH_STUB = """
239-
# Uncomment the following lines if os.environ.get("PYTHONPATH") is not set
240-
# import sys
241-
# sys.path.insert(0, "{MetaflowEnvEscapeDir}")
248+
import os
249+
import sys
250+
if os.environ.get("PYTHONPATH") is None:
251+
sys.path.insert(0, "{MetaflowEnvEscapeDir}")
242252
"""
243253

244254
# Imports needed to define stubbed classes & Debug steps

metaflow_extensions/netflix_ext/cmd/debug/debug_cmd.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import os
22
import json
3-
import tarfile
4-
import datetime
53

6-
from metaflow import namespace, Flow, Run, Step, Task
4+
from metaflow import Flow, Run, Step, Task
75
from metaflow._vendor import click
8-
from typing import Any, Dict, Optional, Union
6+
from typing import Any, Optional, Union
97
from metaflow.exception import CommandException
108
from metaflow.cli import echo_dev_null, echo_always
9+
from metaflow.packaging_sys import MetaflowCodeContent
10+
from .constants import Constants
1111
from .debug_script_generator import DebugScriptGenerator
1212
from .debug_utils import (
13-
fetch_environment_type,
1413
copy_stub_generator_to_metaflow_root_dir,
1514
_set_python_environment,
1615
_extract_code_package,
@@ -277,7 +276,8 @@ def _generate_debug_scripts(
277276
os.makedirs(metaflow_root_dir, exist_ok=True)
278277
python_executable = python_executable.strip() if python_executable else None
279278
flow_name = task_pathspec.split("/")[0]
280-
debug_file_name = task_pathspec.replace("/", "_").replace("-", "_") + "_debug.py"
279+
translation_table = str.maketrans("/.-+=", "_____")
280+
debug_file_name = task_pathspec.translate(translation_table) + "_debug.py"
281281
debug_script_generator = DebugScriptGenerator(task_pathspec, inspect)
282282
script = debug_script_generator.generate_debug_script(metaflow_root_dir, flow_name)
283283
debug_script_generator.write_debug_script(
@@ -301,7 +301,8 @@ def _generate_debug_scripts(
301301
debug_script_generator.write_debug_notebook(metaflow_root_dir, notebook_json)
302302

303303
obj.echo(
304-
f"Debug scripts and notebook generated at {metaflow_root_dir}",
304+
f"Debug scripts and notebook generated at {metaflow_root_dir}; "
305+
f"launch {Constants.DEBUG_SCRIPT_NAME} to debug the task",
305306
fg="green",
306307
bold=True,
307308
)
@@ -313,7 +314,9 @@ def _generate_debug_scripts(
313314

314315
def _update_kernel_pythonpath(kernelspec_path, metaflow_root_dir):
315316
"""
316-
Updates the kernelspec with the escape trampolines added to the PYTHONPATH.
317+
Updates the kernelspec with the escape trampolines added to the PYTHONPATH
318+
as well as any other environment variables that may be needed by the
319+
version of Metaflow installed.
317320
318321
Parameters
319322
----------
@@ -329,5 +332,18 @@ def _update_kernel_pythonpath(kernelspec_path, metaflow_root_dir):
329332
_ = kernel_json.setdefault("env", {})["PYTHONPATH"] = os.path.abspath(
330333
os.path.join(metaflow_root_dir, "_escape_trampolines")
331334
)
335+
336+
for key, value in MetaflowCodeContent.get_env_vars_for_packaged_metaflow(
337+
metaflow_root_dir
338+
).items():
339+
if key.endswith(":"):
340+
# If the key ends with a colon, we override the existing value
341+
kernel_json["env"][key[:-1]] = value
342+
elif key not in kernel_json["env"]:
343+
kernel_json["env"][key] = value
344+
else:
345+
# If the key already exists, we prepend the value to the existing one
346+
kernel_json["env"][key] = f"{value}:{kernel_json['env'][key]}"
347+
332348
with open(kernel_json_path, "w") as f:
333349
json.dump(kernel_json, f, indent=4)

metaflow_extensions/netflix_ext/cmd/debug/debug_script_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ def write_debug_notebook(
336336
The name of the debug notebook.
337337
"""
338338
# We then write out the notebook JSON
339-
debug_notebook_name = "00_DEBUG_ME.ipynb"
339+
debug_notebook_name = Constants.DEBUG_SCRIPT_NAME
340340
debug_notebook_path = os.path.join(metaflow_root_dir, debug_notebook_name)
341341
with open(debug_notebook_path, "w") as f:
342342
json.dump(notebook_json, f, indent=4)

metaflow_extensions/netflix_ext/cmd/debug/debug_stub_generator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ def __init__(self, task_pathspec):
2121
self.run_id = self.task.parent.parent.id
2222
self.flow_name = self.task.parent.parent.parent.id
2323
self.is_new_conda_step = self.is_new_conda_step()
24-
self.workflow_dag = self.task["_graph_info"].data
24+
25+
parameters_task = Step(
26+
"%s/_parameters" % self.task.parent.parent.pathspec, _namespace_check=False
27+
).task
28+
29+
self.workflow_dag = parameters_task["_graph_info"].data
2530
self.file_name = self.workflow_dag["file"]
2631
self._dag_structure = self.get_dag_structure(self.workflow_dag["steps"])
2732
self.step_type = self.get_step_type(self.step_name)

0 commit comments

Comments
 (0)