Skip to content
Merged
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
799f9c3
wip: flag to evaluate dep specs
rickeylev Apr 27, 2025
a658e8f
add some todo, fake some more values
rickeylev Apr 27, 2025
e7ea75b
Merge branch 'main' into pep508.flag
rickeylev Apr 27, 2025
e65c973
source values from select and flags
rickeylev Apr 27, 2025
6181509
sorta fix platform_python_implementation
rickeylev Apr 27, 2025
bf2173c
wip: analysis tests basic
rickeylev Apr 28, 2025
1e23941
trying to get tests to work
rickeylev Apr 29, 2025
ef61724
got basic test passing
rickeylev Apr 29, 2025
d1b9c0d
Merge branch 'main' of https://github.com/bazel-contrib/rules_python …
rickeylev Apr 29, 2025
77decbc
parameterize test
rickeylev Apr 29, 2025
bda07f7
expand testing a bit
rickeylev Apr 29, 2025
5d37d7d
a few notes and links and continue with impl
aignas Apr 29, 2025
38e6f5b
rename to env_marker_setting
rickeylev Apr 29, 2025
be7e007
Merge remote-tracking branch 'origin/pep508.flag' into pep508.flag
rickeylev Apr 29, 2025
3f794c2
move select mappings to constants
rickeylev Apr 29, 2025
7dae5d0
remove extras_flag; various code/comment cleanup
rickeylev Apr 30, 2025
2f1b528
minor cleanup, doc
rickeylev Apr 30, 2025
7ff220e
fixup: forgot to pass args
rickeylev Apr 30, 2025
b340de7
code share with pep508_env.bzl, add config_setting,
rickeylev Apr 30, 2025
104c27b
Merge branch 'main' of https://github.com/bazel-contrib/rules_python …
rickeylev Apr 30, 2025
b2c73c0
more cleanup
rickeylev May 1, 2025
ba05d71
more cleanup
rickeylev May 1, 2025
5316f2a
remove platform_version and platform_release flags for now
rickeylev May 1, 2025
2b30b54
wire platform_release back to osx flag
rickeylev May 1, 2025
a6bc605
cleanup comment
rickeylev May 2, 2025
764879d
Merge branch 'main' of https://github.com/bazel-contrib/rules_python …
rickeylev May 2, 2025
72a8f1e
update dleted packages
rickeylev May 2, 2025
8a210d2
restore bazelrc
rickeylev May 2, 2025
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
97 changes: 97 additions & 0 deletions python/private/pypi/dependency_specifier_flag.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
load("//python/private:toolchain_types.bzl", "TARGET_TOOLCHAIN_TYPE")
load(":pep508_evaluate.bzl", "evaluate")

def _impl(ctx):
env = {}

runtime = ctx.toolchains[TARGET_TOOLCHAIN_TYPE].py3_runtime
if runtime.interpreter_version_info:
version_info = runtime.interpreter_version_info
env["python_version"] = "{v.major}.{v.minor}".format(v = version_info)
full_version = format_full_version(version_info)
env["python_full_version"] = full_version
env["implementation_version"] = full_version
else:
env["python_version"] = get_flag(ctx.attr._python_version)
full_version = get_flag(ctx.attr._python_full_version)
env["python_full_version"] = full_version
env["implementation_version"] = full_version

# We assume cpython if the toolchain doesn't specify because it's most
# likely to be true.
env["implementation_name"] = runtime.implementation_name or "cpython"

# todo: map from os constraint
env["os_name"] = struct()

# todo: map from os constraint
env["sys_platform"] = struct()

# todo: map from cpu flag (x86_64, etc)
env["platform_machine"] = struct()

# todo: add PyRuntimeInfo.platform_python_implementation
# The values are slightly different to implementation_name
env["platform_python_implementation"] = runtime.implementation_name

# todo: add flag to carry this
env["platform_release"] = struct()

# todo: map from os constraint
env["platform_system"] = struct()

# todo: add flag to carry this
env["platform_version"] = struct()

if evalute(ctx.attr.expression, env):
value = "yes"
else:
value = "no"
return [config_common.FeatureFlagInfo(value = value)]

# Adapted from spec code at:
# https://packaging.python.org/en/latest/specifications/dependency-specifiers/#environment-markers
def format_full_info(info):
kind = info.releaselevel
if kind == "final":
kind = ""
serial = ""
else:
kind = kind[0] if kind else ""
serial = str(info.serial) if info.serial else ""

return "{v.major}.{v.minor}.{v.micro}{kind}{serial}".format(
v = version_info,
kind = kind,
serial = serial,
)
return version

pypa_dependency_specification = rule(
implementation = _impl,
attrs = {
"expression": attt.string(),
"_os_name": attr.label(),
"_sys_platform_flag": attr.label(),
"_platform_release_flag": attr.label(),
"_platform_system_flag": attr.label(),
"_platform_version_flag": attr.label(),
"_python_version_flag": attr.label(
default = "//python/config_settings:_python_version_major_minor",
),
"_python_full_version_flag": attr.label(
default = "//python/config_settings:python_version",
),
"_extra_flag": attr.label(),
},
toolchains = [
TARGET_TOOLCHAIN_TYPE,
],
)

def _get_flag(t):
if config_common.FeatureFlagInfo in t:
return t[config_common.FeatureFlagInfo].value
if BuildSettingInfo in t:
return t[BuildSettingInfo].value
fail("Should not occur: {} does not have necessary providers")