Skip to content

Commit

Permalink
Relax glean_parser version requirement to "all compatible releases"
Browse files Browse the repository at this point in the history
In pip `~=V.N` is equivalent to `>= V.N, == V.*`
So we essentially allow everything from the specified minor version
upwards until the next major version (excluded).
As long as glean_parser is careful to not introduce breaking changes
before that this will simplify work a lot by allowing small bug fixes
without requiring subsequent Glean releases to bump versions all the
time.

This also relaxed the version check in the Glean Gradle Plugin.
We always upgrade if in online mode.
We allow semver-compatible versions in offline mode (we do the semver
check ourselves to avoid more dependencies).
  • Loading branch information
badboy committed Aug 10, 2022
1 parent e29ca21 commit b70a6c1
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 30 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[Full changelog](https://github.com/mozilla/glean/compare/v51.1.0...main)

* General
* Relax `glean_parser` version requirement. All "compatible releases" are now allowed ([#2086](https://github.com/mozilla/glean/pull/2086))
* Kotlin
* BUGFIX: Re-enable correctly connecting `glean.validation.foreground_count` again ([#2153](https://github.com/mozilla/glean/pull/2153))

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ python-docs: build-python ## Build the Python documentation
.PHONY: docs rust-docs swift-docs

metrics-docs: python-setup ## Build the internal metrics documentation
$(GLEAN_PYENV)/bin/pip install glean_parser==6.1.2
$(GLEAN_PYENV)/bin/pip install glean_parser~=6.1
$(GLEAN_PYENV)/bin/glean_parser translate --allow-reserved \
-f markdown \
-o ./docs/user/user/collected-metrics \
Expand Down
9 changes: 5 additions & 4 deletions bin/update-glean-parser-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,19 @@ if [ -z "$1" ]; then
fi

NEW_VERSION="$1"
NEW_VERSION_MAJOR_MINOR="$(echo "$NEW_VERSION" | awk -F'.' '{print $1"."$2}')"

# Update the version in glean-core/ios/sdk_generator.sh
FILE=glean-core/ios/sdk_generator.sh
run $SED -i.bak -E \
-e "s/^GLEAN_PARSER_VERSION=[0-9.]+/GLEAN_PARSER_VERSION=${NEW_VERSION}/" \
-e "s/^GLEAN_PARSER_VERSION=[0-9.]+/GLEAN_PARSER_VERSION=${NEW_VERSION_MAJOR_MINOR}/" \
"${WORKSPACE_ROOT}/${FILE}"
run rm "${WORKSPACE_ROOT}/${FILE}.bak"

# Update the version in glean-core/python/setup.py
FILE=glean-core/python/setup.py
run $SED -i.bak -E \
-e "s/\"glean_parser==[0-9.]+\"/\"glean_parser==${NEW_VERSION}\"/" \
-e "s/\"glean_parser~=[0-9.]+\"/\"glean_parser~=${NEW_VERSION_MAJOR_MINOR}\"/" \
"${WORKSPACE_ROOT}/${FILE}"
run rm "${WORKSPACE_ROOT}/${FILE}.bak"

Expand All @@ -52,7 +53,7 @@ run rm "${WORKSPACE_ROOT}/${FILE}.bak"
# update the version in gradle-plugin/src/main/groovy/mozilla/telemetry/glean-gradle-plugin/GleanGradlePlugin.groovy
FILE=gradle-plugin/src/main/groovy/mozilla/telemetry/glean-gradle-plugin/GleanGradlePlugin.groovy
run $SED -i.bak -E \
-e "s/GLEAN_PARSER_VERSION = \"[0-9.]+\"/GLEAN_PARSER_VERSION = \"${NEW_VERSION}\"/" \
-e "s/GLEAN_PARSER_VERSION = \"[0-9.]+\"/GLEAN_PARSER_VERSION = \"${NEW_VERSION_MAJOR_MINOR}\"/" \
"${WORKSPACE_ROOT}/${FILE}"
run rm "${WORKSPACE_ROOT}/${FILE}.bak"

Expand Down Expand Up @@ -80,6 +81,6 @@ run rm "${WORKSPACE_ROOT}/${FILE}.bak"
# update the version in the Makefile
FILE=Makefile
run $SED -i.bak -E \
-e "s/glean_parser==[0-9.]+/glean_parser==${NEW_VERSION}/" \
-e "s/glean_parser~=[0-9.]+/glean_parser~=${NEW_VERSION_MAJOR_MINOR}/" \
"${WORKSPACE_ROOT}/${FILE}"
run rm "${WORKSPACE_ROOT}/${FILE}.bak"
4 changes: 2 additions & 2 deletions glean-core/ios/sdk_generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

set -e

GLEAN_PARSER_VERSION=6.1.2
GLEAN_PARSER_VERSION=6.1

# CMDNAME is used in the usage text below.
# shellcheck disable=SC2034
Expand Down Expand Up @@ -159,7 +159,7 @@ VENVDIR="${SOURCE_ROOT}/.venv"
# We need at least pip 20.3 for Big Sur support, see https://pip.pypa.io/en/stable/news/#id48
# Latest pip is 21.0.1
"${VENVDIR}"/bin/pip install "pip>=20.3"
"${VENVDIR}"/bin/pip install --upgrade glean_parser==$GLEAN_PARSER_VERSION
"${VENVDIR}"/bin/pip install --upgrade "glean_parser~=$GLEAN_PARSER_VERSION"

# Run the glinter
# Turn its warnings into warnings visible in Xcode (but don't do for the success message)
Expand Down
8 changes: 6 additions & 2 deletions glean-core/python/glean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


from pkg_resources import get_distribution, DistributionNotFound
from semver import VersionInfo # type: ignore


import glean_parser # type: ignore
Expand All @@ -31,11 +32,14 @@


GLEAN_PARSER_VERSION = "6.1.2"
parser_version = VersionInfo.parse(GLEAN_PARSER_VERSION)
parser_version_next_major = parser_version.bump_major()


if glean_parser.__version__ != GLEAN_PARSER_VERSION:
current_parser = VersionInfo.parse(glean_parser.__version__)
if current_parser < parser_version or current_parser >= parser_version_next_major:
warnings.warn(
f"glean_sdk expected glean_parser v{GLEAN_PARSER_VERSION}, "
f"glean_sdk expected glean_parser ~= v{GLEAN_PARSER_VERSION}, "
f"found v{glean_parser.__version__}",
Warning,
)
Expand Down
1 change: 1 addition & 0 deletions glean-core/python/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pip
pytest-localserver==0.5.1
pytest-runner==5.3.1
pytest==7.0.1
semver==2.13.0
setuptools-git==1.2
twine==3.8.0
types-pkg_resources==0.1.3
Expand Down
3 changes: 2 additions & 1 deletion glean-core/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
version = "51.1.0"

requirements = [
"glean_parser==6.1.2",
"semver>=2.13.0",
"glean_parser~=6.1",
]

# The environment variable `GLEAN_BUILD_VARIANT` can be set to `debug` or `release`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class GleanMetricsYamlTransform extends ArtifactTransform {
@SuppressWarnings("GrPackage")
class GleanPlugin implements Plugin<Project> {
// The version of glean_parser to install from PyPI.
private String GLEAN_PARSER_VERSION = "6.1.2"
private String GLEAN_PARSER_VERSION = "6.1"
// The version of Miniconda is explicitly specified.
// Miniconda3-4.5.12 is known to not work on Windows.
private String MINICONDA_VERSION = "4.5.11"
Expand Down Expand Up @@ -71,25 +71,47 @@ except ImportError:
else:
found_version = getattr(module, '__version__')
if found_version != expected_version:
if not offline:
if 'git' in expected_version:
target=expected_version
else:
target=f'{module_name}=={expected_version}'
subprocess.check_call([
sys.executable,
'-m',
'pip',
'install',
'--upgrade',
target
])
if not offline:
# When running in online mode, we always install.
# If it is installed this is essentially a no-op,
# otherwise it installs/upgrades.
if 'git' in expected_version:
target=expected_version
else:
print(f'Using Python environment at {sys.executable},')
print(f'expected glean_parser version {expected_version}, found {found_version}.')
target=f'{module_name}~={expected_version}'
subprocess.check_call([
sys.executable,
'-m',
'pip',
'install',
'--upgrade',
target
])
else:
error_text = f'''
Using Python environment at {sys.executable},
expected glean_parser version ~={expected_version}, found {found_version}.
Please remove the Python environment, then prepare the package wheels for use:
mkdir -p glean-wheels
cd glean-wheels
pip download glean_parser~={expected_version}
'''
if found_version is None:
print(error_text)
sys.exit(1)
else:
# We check MAJOR.MINOR only
expected_ver = expected_version.split(".")
expected_maj, expected_min = int(expected_ver[0]), int(expected_ver[1])
current_ver = found_version.split(".")
current_maj, current_min = int(current_ver[0]), int(current_ver[1])
if current_maj > expected_maj or current_maj < expected_maj or (current_maj == expected_maj and current_min < expected_min):
print(error_text)
sys.exit(1)
try:
subprocess.check_call([
sys.executable,
Expand Down Expand Up @@ -384,7 +406,7 @@ except:
}

project.logger.warn("Building in offline mode, therefore, Glean is using a supplied Python at ${pythonBinary}")
project.logger.warn("The Python binary can be overridden GLEAN_PYTHON env var.")
project.logger.warn("The Python binary can be overridden with the GLEAN_PYTHON env var.")

commandLine pythonBinary
args "-m"
Expand Down Expand Up @@ -458,7 +480,7 @@ except:
if (parserVersion.matches("git.+")) {
conda "Miniconda3", "Miniconda3-${MINICONDA_VERSION}", "64", [parserVersion]
} else {
conda "Miniconda3", "Miniconda3-${MINICONDA_VERSION}", "64", ["glean_parser==${parserVersion}"]
conda "Miniconda3", "Miniconda3-${MINICONDA_VERSION}", "64", ["glean_parser~=${parserVersion}"]
}
}
File envDir = new File(
Expand Down

0 comments on commit b70a6c1

Please sign in to comment.