Skip to content

Commit e60d2ad

Browse files
authored
Refac venv inst (#12)
1 parent 0aa0d15 commit e60d2ad

File tree

5 files changed

+141
-339
lines changed

5 files changed

+141
-339
lines changed

get-platformio.py

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pioinstaller/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import logging.config
1717

18-
__version__ = "1.4.0"
18+
__version__ = "1.5.0"
1919

2020
__title__ = "pioarduino-installer"
2121
__description__ = "An installer for pioarduino Core"

pioinstaller/__main__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ def cli(
5757
raise click.ClickException(str(exc))
5858

5959

60+
@cli.command()
61+
@click.option("--shutdown-piohome/--no-shutdown-piohome", is_flag=True, default=True)
62+
@click.pass_context
63+
def install(ctx, shutdown_piohome):
64+
"""Install PlatformIO Core."""
65+
try:
66+
core.install_platformio_core(shutdown_piohome, ctx.obj.get("dev", False))
67+
click.secho("PlatformIO Core has been successfully installed!", fg="green")
68+
except exception.PIOInstallerException as exc:
69+
raise click.ClickException(str(exc))
70+
71+
6072
@cli.command()
6173
@click.argument(
6274
"target",

pioinstaller/core.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,12 @@ def get_cache_dir():
105105

106106

107107
def install_platformio_core(shutdown_piohome=True, develop=False, ignore_pythons=None):
108+
# pylint: disable=unused-argument
109+
# ignore_pythons is deprecated but kept for backward compatibility
108110
try:
109111
return _install_platformio_core(
110112
shutdown_piohome=shutdown_piohome,
111113
develop=develop,
112-
ignore_pythons=ignore_pythons,
113114
)
114115
except subprocess.CalledProcessError as exc:
115116
# Issue #221: Workaround for Windows OS when username contains a space
@@ -122,19 +123,18 @@ def install_platformio_core(shutdown_piohome=True, develop=False, ignore_pythons
122123
return _install_platformio_core(
123124
shutdown_piohome=shutdown_piohome,
124125
develop=develop,
125-
ignore_pythons=ignore_pythons,
126126
)
127127
raise exc
128128

129129

130-
def _install_platformio_core(shutdown_piohome=True, develop=False, ignore_pythons=None):
130+
def _install_platformio_core(shutdown_piohome=True, develop=False):
131131
# pylint: disable=bad-option-value, import-outside-toplevel, unused-import, import-error, unused-variable, cyclic-import
132132
from pioinstaller import penv
133133

134134
if shutdown_piohome:
135135
home.shutdown_pio_home_servers()
136136

137-
penv_dir = penv.create_core_penv(ignore_pythons=ignore_pythons)
137+
penv_dir = penv.create_core_penv()
138138

139139
# Use uv for installation
140140
uv_exe = penv.get_uv_executable()
@@ -144,6 +144,10 @@ def _install_platformio_core(shutdown_piohome=True, develop=False, ignore_python
144144
)
145145

146146
_install_with_uv(uv_exe, penv_dir, develop)
147+
148+
# Install UV in the penv for future use
149+
_install_uv_in_penv(uv_exe, penv_dir)
150+
147151
_post_install_message(penv_dir)
148152
return True
149153

@@ -194,6 +198,31 @@ def _install_with_uv(uv_exe, penv_dir, develop):
194198
) from e
195199

196200

201+
def _install_uv_in_penv(uv_exe, penv_dir):
202+
"""Install UV in the penv for future use."""
203+
from pioinstaller import penv
204+
205+
click.echo("Installing UV in penv for future use")
206+
207+
venv_python = os.path.join(
208+
penv.get_penv_bin_dir(penv_dir),
209+
"python.exe" if util.IS_WINDOWS else "python",
210+
)
211+
212+
command = [uv_exe, "pip", "install", "--python", venv_python, "uv"]
213+
214+
log.debug("Running: %s", " ".join(command))
215+
try:
216+
subprocess.check_call(
217+
command, stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT
218+
)
219+
click.echo("UV successfully installed in penv")
220+
except subprocess.CalledProcessError as e:
221+
# Don't fail the entire installation if UV installation fails
222+
log.warning("Could not install UV in penv: %s", e)
223+
click.echo("Warning: Could not install UV in penv (non-critical)")
224+
225+
197226
def _post_install_message(penv_dir):
198227
"""Display post-installation success message."""
199228
from pioinstaller import penv

0 commit comments

Comments
 (0)