Skip to content

Commit

Permalink
Add GitHub Codespaces and VS Code Remote Container support (#2949)
Browse files Browse the repository at this point in the history
* Add GitHub Codespaces and VS Code Remote Container support

* Add new environment type in enums
  • Loading branch information
htahir1 authored Aug 27, 2024
1 parent 03f4cc5 commit 8ffd9a7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/zenml/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ class EnvironmentType(StrEnum):
PAPERSPACE = "paperspace"
WSL = "wsl"
LIGHTNING_AI_STUDIO = "lightning_ai_studio"
GITHUB_CODESPACES = "github_codespaces"
VSCODE_REMOTE_CONTAINER = "vscode_remote_container"


class ModelStages(StrEnum):
Expand Down
31 changes: 31 additions & 0 deletions src/zenml/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def get_environment() -> str:
return EnvironmentType.BITBUCKET_CI
elif Environment.in_ci():
return EnvironmentType.GENERIC_CI
elif Environment.in_github_codespaces():
return EnvironmentType.GITHUB_CODESPACES
elif Environment.in_vscode_remote_container():
return EnvironmentType.VSCODE_REMOTE_CONTAINER
elif Environment.in_lightning_ai_studio():
return EnvironmentType.LIGHTNING_AI_STUDIO
elif Environment.in_docker():
Expand Down Expand Up @@ -271,6 +275,33 @@ def in_notebook() -> bool:
return True
return False

@staticmethod
def in_github_codespaces() -> bool:
"""If the current Python process is running in GitHub Codespaces.
Returns:
`True` if the current Python process is running in GitHub Codespaces,
`False` otherwise.
"""
return (
"CODESPACES" in os.environ
or "GITHUB_CODESPACE_TOKEN" in os.environ
or "GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN" in os.environ
)

@staticmethod
def in_vscode_remote_container() -> bool:
"""If the current Python process is running in a VS Code Remote Container.
Returns:
`True` if the current Python process is running in a VS Code Remote Container,
`False` otherwise.
"""
return (
"REMOTE_CONTAINERS" in os.environ
or "VSCODE_REMOTE_CONTAINERS_SESSION" in os.environ
)

@staticmethod
def in_paperspace_gradient() -> bool:
"""If the current Python process is running in Paperspace Gradient.
Expand Down

0 comments on commit 8ffd9a7

Please sign in to comment.