Skip to content

Commit

Permalink
Merge pull request #486 from z8v/rm-python2
Browse files Browse the repository at this point in the history
Remove support for python2
  • Loading branch information
z8v authored Mar 14, 2024
2 parents 9b13ed0 + 8b043cd commit d30e493
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 109 deletions.
34 changes: 3 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2065,9 +2065,9 @@ optional.
### nixpkgs_python_configure

<pre>
nixpkgs_python_configure(<a href="#nixpkgs_python_configure-name">name</a>, <a href="#nixpkgs_python_configure-python2_attribute_path">python2_attribute_path</a>, <a href="#nixpkgs_python_configure-python2_bin_path">python2_bin_path</a>, <a href="#nixpkgs_python_configure-python3_attribute_path">python3_attribute_path</a>,
<a href="#nixpkgs_python_configure-python3_bin_path">python3_bin_path</a>, <a href="#nixpkgs_python_configure-repository">repository</a>, <a href="#nixpkgs_python_configure-repositories">repositories</a>, <a href="#nixpkgs_python_configure-nix_file_deps">nix_file_deps</a>, <a href="#nixpkgs_python_configure-nixopts">nixopts</a>,
<a href="#nixpkgs_python_configure-fail_not_supported">fail_not_supported</a>, <a href="#nixpkgs_python_configure-quiet">quiet</a>, <a href="#nixpkgs_python_configure-exec_constraints">exec_constraints</a>, <a href="#nixpkgs_python_configure-target_constraints">target_constraints</a>, <a href="#nixpkgs_python_configure-register">register</a>)
nixpkgs_python_configure(<a href="#nixpkgs_python_configure-name">name</a>, <a href="#nixpkgs_python_configure-python3_attribute_path">python3_attribute_path</a>, <a href="#nixpkgs_python_configure-python3_bin_path">python3_bin_path</a>, <a href="#nixpkgs_python_configure-repository">repository</a>, <a href="#nixpkgs_python_configure-repositories">repositories</a>,
<a href="#nixpkgs_python_configure-nix_file_deps">nix_file_deps</a>, <a href="#nixpkgs_python_configure-nixopts">nixopts</a>, <a href="#nixpkgs_python_configure-fail_not_supported">fail_not_supported</a>, <a href="#nixpkgs_python_configure-quiet">quiet</a>, <a href="#nixpkgs_python_configure-exec_constraints">exec_constraints</a>,
<a href="#nixpkgs_python_configure-target_constraints">target_constraints</a>, <a href="#nixpkgs_python_configure-register">register</a>)
</pre>

Define and register a Python toolchain provided by nixpkgs.
Expand Down Expand Up @@ -2100,34 +2100,6 @@ default is <code>"nixpkgs_python_toolchain"</code>

The name-prefix for the created external repositories.

</p>
</td>
</tr>
<tr id="nixpkgs_python_configure-python2_attribute_path">
<td><code>python2_attribute_path</code></td>
<td>

optional.
default is <code>None</code>

<p>

The nixpkgs attribute path for python2.

</p>
</td>
</tr>
<tr id="nixpkgs_python_configure-python2_bin_path">
<td><code>python2_bin_path</code></td>
<td>

optional.
default is <code>"bin/python"</code>

<p>

The path to the interpreter within the package.

</p>
</td>
</tr>
Expand Down
1 change: 0 additions & 1 deletion testing/python/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package(default_testonly = 1)
test_suite(
name = "python-test",
tests = [
"@nixpkgs_python_configure_test//:python2-test",
"@nixpkgs_python_configure_test//:python3-test",
],
)
Expand Down
12 changes: 6 additions & 6 deletions testing/python/tests/nixpkgs_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ def nixpkgs_repositories(*, bzlmod):
register = not bzlmod,
)

nixpkgs_package(
name = "nixpkgs_python_configure_test",
nix_file = "//tests:python-test.nix",
nixpkgs_python_configure(
python3_attribute_path = "python3",
repository = "@nixpkgs",
register = not bzlmod,
)

nixpkgs_python_configure(
python2_attribute_path = "python2",
nixpkgs_package(
name = "nixpkgs_python_configure_test",
nix_file = "//tests:python-test.nix",
repository = "@nixpkgs",
register = not bzlmod,
)

nixpkgs_python_repository(
Expand Down
14 changes: 2 additions & 12 deletions testing/python/tests/python-test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ runCommand "test-nixpkgs-python-toolchain"
mkdir -p $out
cat >$out/BUILD.bazel <<'EOF_BUILD'
py_test(
name = "python2-test",
main = "python-test.py",
srcs = ["python-test.py"],
python_version = "PY2",
srcs_version = "PY2",
visibility = ["//visibility:public"],
)
py_test(
name = "python3-test",
main = "python-test.py",
Expand All @@ -34,10 +26,8 @@ runCommand "test-nixpkgs-python-toolchain"
"""
if __name__ == "__main__":
if sys.version_info.major == 2:
python_bin = "${python2}/bin/python"
else:
python_bin = "${python3}/bin/python"
python_bin = "${python3}/bin/python"
if not sys.executable == python_bin:
sys.stderr.write(_failure_message.format(
expected = python_bin,
Expand Down
34 changes: 3 additions & 31 deletions toolchains/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Rules to import Python toolchains and packages from Nixpkgs.
### nixpkgs_python_configure

<pre>
nixpkgs_python_configure(<a href="#nixpkgs_python_configure-name">name</a>, <a href="#nixpkgs_python_configure-python2_attribute_path">python2_attribute_path</a>, <a href="#nixpkgs_python_configure-python2_bin_path">python2_bin_path</a>, <a href="#nixpkgs_python_configure-python3_attribute_path">python3_attribute_path</a>,
<a href="#nixpkgs_python_configure-python3_bin_path">python3_bin_path</a>, <a href="#nixpkgs_python_configure-repository">repository</a>, <a href="#nixpkgs_python_configure-repositories">repositories</a>, <a href="#nixpkgs_python_configure-nix_file_deps">nix_file_deps</a>, <a href="#nixpkgs_python_configure-nixopts">nixopts</a>,
<a href="#nixpkgs_python_configure-fail_not_supported">fail_not_supported</a>, <a href="#nixpkgs_python_configure-quiet">quiet</a>, <a href="#nixpkgs_python_configure-exec_constraints">exec_constraints</a>, <a href="#nixpkgs_python_configure-target_constraints">target_constraints</a>, <a href="#nixpkgs_python_configure-register">register</a>)
nixpkgs_python_configure(<a href="#nixpkgs_python_configure-name">name</a>, <a href="#nixpkgs_python_configure-python3_attribute_path">python3_attribute_path</a>, <a href="#nixpkgs_python_configure-python3_bin_path">python3_bin_path</a>, <a href="#nixpkgs_python_configure-repository">repository</a>, <a href="#nixpkgs_python_configure-repositories">repositories</a>,
<a href="#nixpkgs_python_configure-nix_file_deps">nix_file_deps</a>, <a href="#nixpkgs_python_configure-nixopts">nixopts</a>, <a href="#nixpkgs_python_configure-fail_not_supported">fail_not_supported</a>, <a href="#nixpkgs_python_configure-quiet">quiet</a>, <a href="#nixpkgs_python_configure-exec_constraints">exec_constraints</a>,
<a href="#nixpkgs_python_configure-target_constraints">target_constraints</a>, <a href="#nixpkgs_python_configure-register">register</a>)
</pre>

Define and register a Python toolchain provided by nixpkgs.
Expand Down Expand Up @@ -52,34 +52,6 @@ default is <code>"nixpkgs_python_toolchain"</code>

The name-prefix for the created external repositories.

</p>
</td>
</tr>
<tr id="nixpkgs_python_configure-python2_attribute_path">
<td><code>python2_attribute_path</code></td>
<td>

optional.
default is <code>None</code>

<p>

The nixpkgs attribute path for python2.

</p>
</td>
</tr>
<tr id="nixpkgs_python_configure-python2_bin_path">
<td><code>python2_bin_path</code></td>
<td>

optional.
default is <code>"bin/python"</code>

<p>

The path to the interpreter within the package.

</p>
</td>
</tr>
Expand Down
31 changes: 3 additions & 28 deletions toolchains/python/python.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ load(
def _nixpkgs_python_toolchain_impl(repository_ctx):
exec_constraints, target_constraints = ensure_constraints(repository_ctx)

python2_runtime = ""
if repository_ctx.attr.python2_repo:
python2_runtime = repository_ctx.attr.python2_repo + ":runtime"

python3_runtime = ""
if repository_ctx.attr.python3_repo:
python3_runtime = repository_ctx.attr.python3_repo + ":runtime"
Expand All @@ -34,7 +30,6 @@ def _nixpkgs_python_toolchain_impl(repository_ctx):
load("@bazel_tools//tools/python:toolchain.bzl", "py_runtime_pair")
py_runtime_pair(
name = "py_runtime_pair",
py2_runtime = {python2_runtime},
py3_runtime = {python3_runtime},
)
toolchain(
Expand All @@ -45,15 +40,14 @@ toolchain(
target_compatible_with = {target_constraints},
)
""".format(
python2_runtime = label_string(python2_runtime),
python3_runtime = label_string(python3_runtime),
exec_constraints = exec_constraints,
target_constraints = target_constraints,
))

python_repo = repository_ctx.attr.python3_repo
if not python_repo:
python_repo = repository_ctx.attr.python2_repo
fail("python3_repo has to be specified.")

repository_ctx.file("defs.bzl", executable = False, content = """
# Generated by rules_nixpkgs/toolchains/python/python.bzl
Expand All @@ -66,7 +60,6 @@ _nixpkgs_python_toolchain = repository_rule(
# Using attr.string instead of attr.label, so that the repository rule
# does not explicitly depend on the nixpkgs_package instances. This is
# necessary, so that builds don't fail on platforms without nixpkgs.
"python2_repo": attr.string(),
"python3_repo": attr.string(),
"exec_constraints": attr.string_list(),
"target_constraints": attr.string_list(),
Expand Down Expand Up @@ -117,8 +110,6 @@ runCommand "bazel-nixpkgs-python-toolchain"

def nixpkgs_python_configure(
name = "nixpkgs_python_toolchain",
python2_attribute_path = None,
python2_bin_path = "bin/python",
python3_attribute_path = "python3",
python3_bin_path = "bin/python",
repository = None,
Expand All @@ -142,8 +133,6 @@ def nixpkgs_python_configure(
Args:
name: The name-prefix for the created external repositories.
python2_attribute_path: The nixpkgs attribute path for python2.
python2_bin_path: The path to the interpreter within the package.
python3_attribute_path: The nixpkgs attribute path for python3.
python3_bin_path: The path to the interpreter within the package.
repository: See [`nixpkgs_package`](#nixpkgs_package-repository).
Expand All @@ -155,10 +144,9 @@ def nixpkgs_python_configure(
exec_constraints: Constraints for the execution platform.
target_constraints: Constraints for the target platform.
"""
python2_specified = python2_attribute_path and python2_bin_path
python3_specified = python3_attribute_path and python3_bin_path
if not python2_specified and not python3_specified:
fail("At least one of python2 or python3 has to be specified.")
if not python3_specified:
fail("python3 has to be specified.")
kwargs = dict(
repository = repository,
repositories = repositories,
Expand All @@ -167,18 +155,6 @@ def nixpkgs_python_configure(
fail_not_supported = fail_not_supported,
quiet = quiet,
)
python2_repo = None
if python2_attribute_path:
python2_repo = "@%s_python2//" % name
nixpkgs_package(
name = name + "_python2",
nix_file_content = _python_nix_file_content(
attribute_path = python2_attribute_path,
bin_path = python2_bin_path,
version = "PY2",
),
**kwargs
)
python3_repo = None
if python3_attribute_path:
python3_repo = "@%s_python3//" % name
Expand All @@ -193,7 +169,6 @@ def nixpkgs_python_configure(
)
_nixpkgs_python_toolchain(
name = name,
python2_repo = python2_repo,
python3_repo = python3_repo,
exec_constraints = exec_constraints,
target_constraints = target_constraints,
Expand Down

0 comments on commit d30e493

Please sign in to comment.