Skip to content

feat(config): honor COGNITE_DISABLE_PYPI_VERSION_CHECK for PyPI version warning#2531

Open
andersfylling wants to merge 1 commit intomasterfrom
andersfylling/cognite-sdk/disable-pypi-version-check-env
Open

feat(config): honor COGNITE_DISABLE_PYPI_VERSION_CHECK for PyPI version warning#2531
andersfylling wants to merge 1 commit intomasterfrom
andersfylling/cognite-sdk/disable-pypi-version-check-env

Conversation

@andersfylling
Copy link
Copy Markdown
Contributor

Summary

Honor COGNITE_DISABLE_PYPI_VERSION_CHECK when instantiating ClientConfig, so deployments can disable the newer-version UserWarning without importing global_config first.

Truthy values: 1, true, yes, on (case-insensitive).

Motivation

Downstream projects (e.g. unstructured-search) already set this env var; the SDK previously ignored it and only respected global_config.disable_pypi_version_check.

Changes

  • config.py: _env_truthy / _pypi_version_check_disabled
  • _version_checker.py: mention env var in warning text
  • test_config.py: unit tests for env + global precedence

Made with Cursor

…on warning

Read the env var when building ClientConfig so deployments can disable
the newer-version check without importing global_config first. Truthy
values match common conventions (1, true, yes, on).

Update the UserWarning text to document the env-based escape hatch.

Made-with: Cursor
@andersfylling andersfylling marked this pull request as ready for review March 25, 2026 14:20
@andersfylling andersfylling requested review from a team as code owners March 25, 2026 14:20
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the SDK's configuration flexibility by allowing users to disable the PyPI version check warning through an environment variable, COGNITE_DISABLE_PYPI_VERSION_CHECK. This provides an alternative to setting global_config.disable_pypi_version_check directly, which is particularly useful for deployments or automated environments where modifying global_config might be less convenient. The change ensures that the warning can be suppressed more easily and consistently across different operational contexts.

Highlights

  • Environment Variable Support: Added support for the COGNITE_DISABLE_PYPI_VERSION_CHECK environment variable to disable PyPI version warnings, providing an alternative to global_config.
  • Configuration Logic: Introduced helper functions _env_truthy and _pypi_version_check_disabled to parse truthy environment variable values and consolidate the logic for disabling the version check.
  • User Guidance: Updated the PyPI version warning message to explicitly include instructions for using the new environment variable option.
  • Testing: Implemented comprehensive unit tests to ensure correct precedence and functionality of the environment variable and global configuration settings for the version check.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces the capability to disable the PyPI version check using an environment variable, COGNITE_DISABLE_PYPI_VERSION_CHECK, in addition to the existing global configuration. This involves adding new helper functions, updating configuration logic, and enhancing the warning message. The review identifies that the new helper functions, _env_truthy and _pypi_version_check_disabled, lack docstrings, and _env_truthy uses a magic value that should be refactored into an UPPER_SNAKE_CASE constant, both of which violate the repository's style guide.

Comment on lines +105 to +109
def _env_truthy(name: str) -> bool:
val = os.environ.get(name)
if val is None:
return False
return val.strip().lower() in {"1", "true", "yes", "on"}
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.

high

This function is missing a docstring, which is required by the repository style guide (lines 94, 117). Additionally, the set of truthy strings is a magic value and should be defined as a constant with an UPPER_SNAKE_CASE name, as per the style guide (line 87).

Since a module-level constant cannot be added within the scope of this change, defining it inside the function is an acceptable alternative.

def _env_truthy(name: str) -> bool:
    """Check if an environment variable is set to a truthy value.

    Truthy values are "1", "true", "yes", "on" (case-insensitive).

    Args:
        name (str): The name of the environment variable.

    Returns:
        bool: True if the environment variable has a truthy value, False otherwise.
    """
    TRUTHY_STRINGS = frozenset({"1", "true", "yes", "on"})
    val = os.environ.get(name)
    if val is None:
        return False
    return val.strip().lower() in TRUTHY_STRINGS
References
  1. Functions require concise docstrings in google-style format, including Args and Returns sections for clarity. (link)
  2. Constants should be named using UPPER_SNAKE_CASE. (link)

Comment on lines +112 to +113
def _pypi_version_check_disabled() -> bool:
return global_config.disable_pypi_version_check or _env_truthy("COGNITE_DISABLE_PYPI_VERSION_CHECK")
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.

high

This function is missing a docstring, which is required by the repository style guide (lines 94, 117).

def _pypi_version_check_disabled() -> bool:
    """Check if the PyPI version check is disabled.

    The check is disabled if either the global config flag is set or the
    corresponding environment variable is set to a truthy value.

    Returns:
        bool: True if the version check is disabled, False otherwise.
    """
    return global_config.disable_pypi_version_check or _env_truthy("COGNITE_DISABLE_PYPI_VERSION_CHECK")
References
  1. Functions require concise docstrings in google-style format, including Args and Returns sections for clarity. (link)

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.40%. Comparing base (c890725) to head (89f3149).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2531      +/-   ##
==========================================
+ Coverage   91.35%   91.40%   +0.05%     
==========================================
  Files         192      192              
  Lines       26218    26226       +8     
==========================================
+ Hits        23951    23972      +21     
+ Misses       2267     2254      -13     
Files with missing lines Coverage Δ
cognite/client/config.py 96.26% <100.00%> (+2.32%) ⬆️
cognite/client/utils/_version_checker.py 48.00% <ø> (+48.00%) ⬆️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@haakonvt
Copy link
Copy Markdown
Contributor

To simplify, we could consider just the presence of the env.var. to be thruthy here imo.

I also would like the opinion of @erlendvollset, as I remember he removed all these COGNITE-prefixed env.vars. some time ago

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants