Skip to content

Commit 12ece41

Browse files
Add :native_tls option to Pythonx.uv_init/2 (#41)
Co-authored-by: Jonatan Kłosko <jonatanklosko@gmail.com>
1 parent 1398ea9 commit 12ece41

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/pythonx.ex

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,19 @@ defmodule Pythonx do
5454
* `:uv_version` - select the version of the uv package manager to use.
5555
Defaults to `#{inspect(Pythonx.Uv.default_uv_version())}`.
5656
57+
* `:native_tls` - if true, uses the system's native TLS implementation instead
58+
of vendored rustls. This is useful in corporate environments where the system
59+
certificate store must be used. Defaults to `false`.
60+
5761
'''
5862
@spec uv_init(String.t(), keyword()) :: :ok
5963
def uv_init(pyproject_toml, opts \\ []) when is_binary(pyproject_toml) and is_list(opts) do
60-
opts = Keyword.validate!(opts, force: false, uv_version: Pythonx.Uv.default_uv_version())
64+
opts =
65+
Keyword.validate!(opts,
66+
force: false,
67+
uv_version: Pythonx.Uv.default_uv_version(),
68+
native_tls: false
69+
)
6170

6271
Pythonx.Uv.fetch(pyproject_toml, false, opts)
6372
install_paths = Pythonx.Uv.init(pyproject_toml, false, Keyword.take(opts, [:uv_version]))

lib/pythonx/uv.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ defmodule Pythonx.Uv do
1010
"""
1111
@spec fetch(String.t(), boolean(), keyword()) :: :ok
1212
def fetch(pyproject_toml, priv?, opts \\ []) do
13-
opts = Keyword.validate!(opts, force: false, uv_version: default_uv_version())
13+
opts =
14+
Keyword.validate!(opts, force: false, uv_version: default_uv_version(), native_tls: false)
1415

1516
project_dir = project_dir(pyproject_toml, priv?, opts[:uv_version])
1617
python_install_dir = python_install_dir(priv?, opts[:uv_version])
@@ -28,7 +29,10 @@ defmodule Pythonx.Uv do
2829
File.write!(Path.join(project_dir, "pyproject.toml"), pyproject_toml)
2930

3031
# We always use uv-managed Python, so the paths are predictable.
31-
if run!(["sync", "--managed-python", "--no-config"],
32+
base_args = ["sync", "--managed-python", "--no-config"]
33+
uv_args = if opts[:native_tls], do: base_args ++ ["--native-tls"], else: base_args
34+
35+
if run!(uv_args,
3236
cd: project_dir,
3337
env: %{"UV_PYTHON_INSTALL_DIR" => python_install_dir},
3438
uv_version: opts[:uv_version]

0 commit comments

Comments
 (0)