Skip to content

Conversation

@JennyPng
Copy link
Member

@JennyPng JennyPng commented Feb 4, 2026

closes #44883

packages with stable releases are required to have a Conda tool section in their pyproject.toml to specify if packages are to be released individually or as part of a bundle

service teams should be responsible for specifying this information

existing stable packages have already been batch updated

@JennyPng JennyPng marked this pull request as ready for review February 4, 2026 23:44
Copilot AI review requested due to automatic review settings February 4, 2026 23:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request enforces that Python packages with stable releases on PyPI must include a [tool.azure-sdk-conda] section in their pyproject.toml file. This automation supports the Conda release process by ensuring service teams specify whether packages should be released individually or bundled.

Changes:

  • Adds validation to check for Conda metadata in packages with stable PyPI versions
  • Fixes logging calls to use the correct logger instance
  • Removes unused import statement

Comment on lines +101 to +135
def has_stable_version_on_pypi(package_name: str) -> bool:
"""Check if the package has any stable (non-prerelease) version on PyPI."""
try:
all_versions = retrieve_versions_from_pypi(package_name)
stable_versions = [Version(v) for v in all_versions if not Version(v).is_prerelease]
return len(stable_versions) > 0
except Exception:
return False


def verify_conda_section(package_dir: str, package_name: str) -> bool:
"""Verify that packages with stable versions on PyPI have [tool.azure-sdk-conda] section in pyproject.toml."""
if not has_stable_version_on_pypi(package_name):
logger.info(f"Package {package_name} has no stable version on PyPI, skipping conda section check")
return True

pyproject_path = os.path.join(package_dir, "pyproject.toml")
if not os.path.exists(pyproject_path):
logger.error(f"Package {package_name} has a stable version on PyPI but is missing pyproject.toml")
return False

try:
with open(pyproject_path, "r", encoding="utf-8") as f:
content = f.read()

if "[tool.azure-sdk-conda]" not in content:
logger.error(
f"Package {package_name} has a stable version on PyPI but is missing "
"[tool.azure-sdk-conda] section in pyproject.toml"
)
return False
return True
except Exception as e:
logger.error(f"Failed to read pyproject.toml for {package_name}: {e}")
return False
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The new verify_conda_section and has_stable_version_on_pypi functions lack test coverage. The repository has comprehensive automated testing for verify_whl (see tests/test_metadata_verification.py), so these new functions should have corresponding tests. Consider adding test cases for: 1) packages with stable versions that have the conda section, 2) packages with stable versions missing the conda section, 3) packages without stable versions (should skip check), 4) packages missing pyproject.toml, and 5) error handling in has_stable_version_on_pypi.

Copilot uses AI. Check for mistakes.
# Verify conda section for packages with stable versions on PyPI
if not verify_conda_section(package_dir, package_name):
logger.error(
"As part of releasing stable packages to Conda, the pyproject.toml must include a [tool.azure-sdk-conda] section and specify if the package should be released individually or bundled."
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The error message duplicates information already provided by the logger.error call on lines 127-130. The message on line 297 should be removed or modified to add new information, such as a link to documentation on how to configure the conda section or an example configuration.

Suggested change
"As part of releasing stable packages to Conda, the pyproject.toml must include a [tool.azure-sdk-conda] section and specify if the package should be released individually or bundled."
"As part of releasing stable packages to Conda, the pyproject.toml must include a [tool.azure-sdk-conda] "
"section and specify if the package should be released individually or bundled. For configuration guidance, "
"see https://aka.ms/azsdk/python/conda-config, for example:\n"
"[tool.azure-sdk-conda]\n"
'publish = "individual" # or "bundle"\n'
'bundle_group = "azure-ai" # optional, when using bundle'

Copilot uses AI. Check for mistakes.
Comment on lines +126 to +132
if "[tool.azure-sdk-conda]" not in content:
logger.error(
f"Package {package_name} has a stable version on PyPI but is missing "
"[tool.azure-sdk-conda] section in pyproject.toml"
)
return False
return True
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The verification only checks for the presence of the [tool.azure-sdk-conda] section but doesn't validate that it contains the required fields. Based on existing pyproject.toml files (e.g., sdk/core/azure-core/pyproject.toml), packages should specify "in_bundle" and "bundle_name" fields. Consider validating that these required fields are present and properly configured to provide more helpful feedback to service teams.

Copilot uses AI. Check for mistakes.
Comment on lines +133 to +135
except Exception as e:
logger.error(f"Failed to read pyproject.toml for {package_name}: {e}")
return False
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The bare Exception catch in the try-except block is too broad. It catches all exceptions including KeyboardInterrupt and SystemExit, which could mask serious issues. Consider catching specific exceptions like OSError or IOError for file operations, or at minimum use "except Exception as e" and re-raise after logging if it's not a recoverable error. The current implementation silently returns False for any exception, which could hide bugs.

Copilot uses AI. Check for mistakes.
all_versions = retrieve_versions_from_pypi(package_name)
stable_versions = [Version(v) for v in all_versions if not Version(v).is_prerelease]
return len(stable_versions) > 0
except Exception:
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

Similar to verify_conda_section, the bare Exception catch here is too broad and could hide bugs. The function returns False for any exception (including network errors, JSON parsing errors, etc.), which makes debugging difficult. Consider either catching specific exceptions or logging the exception before returning False so that failures are visible in CI logs.

Suggested change
except Exception:
except Exception as exc:
logger.error("Failed to retrieve stable versions for %s from PyPI: %s", package_name, exc)

Copilot uses AI. Check for mistakes.
with open(pyproject_path, "r", encoding="utf-8") as f:
content = f.read()

if "[tool.azure-sdk-conda]" not in content:
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

The string search for "[tool.azure-sdk-conda]" may produce false positives if this string appears in comments or string literals within the pyproject.toml file. Consider parsing the TOML file properly to check for the actual section. The codebase already uses tomllib/tomli for TOML parsing (see ci_tools/parsing/parse_functions.py), so you could load the file and check if "azure-sdk-conda" exists in toml_dict.get("tool", {}).

Copilot uses AI. Check for mistakes.
@JennyPng JennyPng marked this pull request as draft February 5, 2026 00:01
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.

enforce in CI that the pyproject section is required

1 participant