-
Notifications
You must be signed in to change notification settings - Fork 125
feat: instrument vscode, jupyter and 3p plugin usage #925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e143c1f
feat: instrument vscode, jupyter and 3p plugin usage
shobsi 6dbb376
fix the return value
shobsi 5f79b53
add unit test coverage
shobsi bbaaf54
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 218cba8
use pathlib, reduce indentation, format
shobsi 53cd216
Merge remote-tracking branch 'origin/shobsi-instrument-ide-plugin' in…
shobsi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
# Copyright (c) 2025 pandas-gbq Authors All rights reserved. | ||
# Use of this source code is governed by a BSD-style | ||
# license that can be found in the LICENSE file. | ||
|
||
|
||
import importlib | ||
import json | ||
import os | ||
import pathlib | ||
|
||
Path = pathlib.Path | ||
|
||
|
||
# The identifier for GCP VS Code extension | ||
# https://cloud.google.com/code/docs/vscode/install | ||
GOOGLE_CLOUD_CODE_EXTENSION_NAME = "googlecloudtools.cloudcode" | ||
|
||
|
||
# The identifier for BigQuery Jupyter notebook plugin | ||
# https://cloud.google.com/bigquery/docs/jupyterlab-plugin | ||
BIGQUERY_JUPYTER_PLUGIN_NAME = "bigquery_jupyter_plugin" | ||
|
||
|
||
def _is_vscode_extension_installed(extension_id: str) -> bool: | ||
""" | ||
Checks if a given Visual Studio Code extension is installed. | ||
|
||
Args: | ||
extension_id: The ID of the extension (e.g., "ms-python.python"). | ||
|
||
Returns: | ||
True if the extension is installed, False otherwise. | ||
""" | ||
try: | ||
# Determine the user's VS Code extensions directory. | ||
user_home = Path.home() | ||
vscode_extensions_dir = user_home / ".vscode" / "extensions" | ||
|
||
# Check if the extensions directory exists. | ||
if not vscode_extensions_dir.exists(): | ||
return False | ||
|
||
# Iterate through the subdirectories in the extensions directory. | ||
for item in vscode_extensions_dir.iterdir(): | ||
# Ignore non-directories. | ||
if not item.is_dir(): | ||
continue | ||
|
||
# Directory must start with the extension ID. | ||
if not item.name.startswith(extension_id + "-"): | ||
continue | ||
|
||
# As a more robust check, the manifest file must exist. | ||
manifest_path = item / "package.json" | ||
if not manifest_path.exists() or not manifest_path.is_file(): | ||
continue | ||
|
||
# Finally, the manifest file must be a valid json | ||
with open(manifest_path, "r", encoding="utf-8") as f: | ||
json.load(f) | ||
|
||
return True | ||
except Exception: | ||
pass | ||
|
||
return False | ||
|
||
|
||
def _is_package_installed(package_name: str) -> bool: | ||
""" | ||
Checks if a Python package is installed. | ||
|
||
Args: | ||
package_name: The name of the package to check (e.g., "requests", "numpy"). | ||
|
||
Returns: | ||
True if the package is installed, False otherwise. | ||
""" | ||
try: | ||
importlib.import_module(package_name) | ||
return True | ||
except Exception: | ||
return False | ||
|
||
|
||
def is_vscode() -> bool: | ||
return os.getenv("VSCODE_PID") is not None | ||
|
||
|
||
def is_jupyter() -> bool: | ||
return os.getenv("JPY_PARENT_PID") is not None | ||
|
||
|
||
def is_vscode_google_cloud_code_extension_installed() -> bool: | ||
return _is_vscode_extension_installed(GOOGLE_CLOUD_CODE_EXTENSION_NAME) | ||
|
||
|
||
def is_jupyter_bigquery_plugin_installed() -> bool: | ||
return _is_package_installed(BIGQUERY_JUPYTER_PLUGIN_NAME) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.