Skip to content

Source distribution build fails due to missing PackageVersion environment variable #248

@abhilash1in

Description

@abhilash1in

Description

The source distributions (sdist) for all packages in this repository cannot be built without setting the PackageVersion environment variable. This causes installation failures in enterprise environments and tooling that build packages from source.

Problem

All packages use a setup.py pattern similar to:

from os import environ
from setuptools import setup

package_version = environ.get("PackageVersion", "0.0.0")

setup(
    version=package_version,
)

When pip downloads and attempts to build the source distribution, the PackageVersion environment variable is not set, causing the package to build with version 0.0.0. This creates a version mismatch that pip detects and rejects:

WARNING: Requested microsoft-agents-activity===0.5.0 [...], but installing version 0.0.0
ERROR: [...] has inconsistent version: expected '0.5.0', but metadata has '0.0.0'

Impact

  • Enterprise environments: Many organizations use tooling and proxies that build packages from source distributions without environment variable passthrough
  • Offline installations: Users installing from downloaded sdist files cannot build the packages
  • Build reproducibility: The build process is not reproducible without external environment state

Affected Packages

All packages in this repository are affected:

  • microsoft-agents-activity
  • microsoft-agents-hosting-core
  • microsoft-agents-hosting-aiohttp
  • microsoft-agents-hosting-teams
  • microsoft-agents-storage-blob
  • microsoft-agents-storage-cosmos
  • microsoft-agents-authentication-msal
  • microsoft-agents-copilotstudio-client

Steps to Reproduce

  1. Force pip to build from source distribution (since wheels are available and will work fine):

    (.venv) ➜ pip install --no-binary microsoft-agents-activity microsoft-agents-activity==0.5.0
     DEPRECATION: --no-binary currently disables reading from the cache of locally built wheels. In the future --no-binary will not influence the wheel cache. pip 23.1 will enforce this behaviour change. A possible replacement is to use the --no-cache-dir option. You can use the flag --use-feature=no-binary-enable-wheel-cache to test the upcoming behaviour. Discussion can be found at https://github.com/pypa/pip/issues/11453
     Collecting microsoft-agents-activity==0.5.0
     Downloading microsoft_agents_activity-0.5.0.tar.gz (55 kB)
         ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 55.8/55.8 kB 3.4 MB/s eta 0:00:00
     Installing build dependencies ... done
     Getting requirements to build wheel ... done
     Preparing metadata (pyproject.toml) ... done
     WARNING: Requested microsoft-agents-activity==0.5.0 from https://files.pythonhosted.org/packages/a9/cd/c8656d41a5f60b5a931190d7c523406bfc261e2f4e0c41b9edee3d219a66/microsoft_agents_activity-0.5.0.tar.gz, but installing version 0.0.0
     Discarding https://files.pythonhosted.org/packages/a9/cd/c8656d41a5f60b5a931190d7c523406bfc261e2f4e0c41b9edee3d219a66/microsoft_agents_activity-0.5.0.tar.gz (from https://pypi.org/simple/microsoft-agents-activity/) (requires-python:>=3.10): Requested microsoft-agents-activity==0.5.0 from https://files.pythonhosted.org/packages/a9/cd/c8656d41a5f60b5a931190d7c523406bfc261e2f4e0c41b9edee3d219a66/microsoft_agents_activity-0.5.0.tar.gz has inconsistent version: expected '0.5.0', but metadata has '0.0.0'
     ERROR: Could not find a version that satisfies the requirement microsoft-agents-activity==0.5.0 (from versions: 0.0.0, 0.1.1, 0.1.2, 0.2.0.dev1, 0.2.0, 0.3.0.dev0, 0.3.0, 0.3.1, 0.3.2, 0.4.0.dev1, 0.4.0.dev3, 0.4.0.dev4, 0.4.0.dev6, 0.4.0.dev7, 0.4.0.dev10, 0.4.0.dev14, 0.4.0.dev16, 0.4.0.dev18, 0.4.0, 0.5.0.dev3, 0.5.0.dev5, 0.5.0.dev7, 0.5.0.dev10, 0.5.0.dev11, 0.5.0.dev17, 0.5.0.dev19, 0.5.0, 0.5.1, 0.5.2, 0.5.3, 0.6.0.dev1, 0.6.0.dev4, 0.6.0.dev7, 0.6.0.dev8, 0.6.0.dev9, 0.6.0.dev10, 0.6.0.dev11, 0.6.0.dev15, 0.6.0.dev16, 0.6.0.dev17, 0.6.0)
     ERROR: No matching distribution found for microsoft-agents-activity==0.5.0
    
     [notice] A new release of pip is available: 23.0.1 -> 25.3
     [notice] To update, run: pip install --upgrade pip
     (.venv) ➜

    Or download the .tar.gz source distribution and install directly:

    pip download --no-binary :all: microsoft-agents-activity==0.5.0
    pip install microsoft_agents_activity-0.5.0.tar.gz
  2. Observe version mismatch error during metadata preparation

Note: This issue doesn't affect wheel installations (.whl files), which is why most users won't encounter this problem. However, it affects:

  • Environments that require building from source for security/compliance
  • Platforms where wheels aren't available or compatible
  • Tooling that builds from source distributions by default

Proposed Solution

Include the version directly in the source distribution rather than relying on environment variables at build time. Options include:

  1. Use setuptools-scm or similar: Automatically generate version from git tags
  2. Version file: Generate a _version.py file during release that gets included in the sdist
  3. Hardcode in sdist: Modify the release process to replace the environment variable with the actual version in the setup.py before creating the source distribution

The environment variable approach should remain for your CI/CD pipeline, but the sdist should contain the actual version number so it can be built independently.

Environment

  • Python version: 3.12 (affects all Python versions)
  • pip version: Latest
  • Affected package versions: 0.5.0 and likely all versions

Additional Context

This pattern works well for CI/CD pipelines where environment variables are controlled, but breaks the standard Python packaging workflow where users should be able to install from source distributions without external dependencies or configuration.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions