Skip to content
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

Lock updates support deleting & replacing reqs. #2335

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions pex/asserts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2024 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from __future__ import absolute_import

import os
import platform
import sys
from textwrap import dedent

from pex.version import __version__

_ASSERT_DETAILS = (
dedent(
"""\
Pex {version}
platform: {platform}
python: {python_version}
argv: {argv}
"""
)
.format(
version=__version__, platform=platform.platform(), python_version=sys.version, argv=sys.argv
)
.strip()
)

_ASSERT_ADVICE = dedent(
"""\
The error reported above resulted from an unexpected programming error which
you should never encounter.

Firstly, please accept our apology!

If you could file an issue with the error and details above, we'd be
grateful. You can do that at https://github.com/pantsbuild/pex/issues/new and
redact or amend any details that expose sensitive information.
"""
).strip()


def production_assert(condition, msg=""):
# type: (...) -> None

if condition:
return

message = [msg, "---", _ASSERT_DETAILS]
pex = os.environ.get("PEX")
if pex:
try:
import json

from pex.pex_info import PexInfo

pex_info = PexInfo.from_pex(pex)
pex_info.update(PexInfo.from_env())
pex_info_json = json.dumps(pex_info.as_json_dict(), indent=2)
except Exception:
pass
else:
message.append("PEX-INFO:")
message.append(pex_info_json)
message.append("---")
message.append(_ASSERT_ADVICE)

raise AssertionError("\n".join(message))
Loading