Skip to content

Commit

Permalink
Fetch last release pioarduino core via github api
Browse files Browse the repository at this point in the history
* load portable python from repo pioarduino
* fetch latest release dynamically via API
* rename to pioarduino core / remove link to Platformio faq
  • Loading branch information
Jason2866 authored Oct 5, 2024
1 parent abc31fd commit 2dba218
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 36 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -35,6 +35,11 @@ jobs:
- name: Pack Installer Script
run: |
make pack
- name: Commit changed `get-platformio.py`
if: matrix.os == 'macos-latest' && matrix.python-version == '"3.12"'
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Github Action: Updated `get-platformio.py`"
- name: Install PlatformIO Core
run: |
python3 get-platformio.py
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
__pycache__/
*.py[cod]
*$py.class
.venv/

# App specific
*.egg-info/
Expand All @@ -11,3 +12,4 @@ build/

# Misc
.idea
.DS_Store
2 changes: 1 addition & 1 deletion get-platformio.py

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions pioinstaller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
VERSION = (1, 2, 3)
__version__ = ".".join([str(s) for s in VERSION])

__title__ = "platformio-installer"
__description__ = "An installer for PlatformIO Core"
__title__ = "pioarduino-installer"
__description__ = "An installer for PlatformIO pioarduino Core"

__url__ = "https://platformio.org"
__url__ = "https://pioarduino.org"

__author__ = "PlatformIO Labs"
__author__ = "PlatformIO Labs and pioarduino"
__email__ = "[email protected]"


__license__ = "Apache-2.0"
__copyright__ = "Copyright 2014-present PlatformIO"
__copyright__ = "Copyright 2014-present PlatformIO and pioarduino"


logging.basicConfig(format="%(levelname)s: %(message)s")
Expand Down
6 changes: 3 additions & 3 deletions pioinstaller/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
@click.pass_context
def cli(
ctx, verbose, shutdown_piohome, dev, ignore_python, pypi_index_url
): # pylint:disable=too-many-arguments
): # pylint: disable=too-many-arguments,too-many-positional-arguments
if verbose:
logging.getLogger("pioinstaller").setLevel(logging.DEBUG)
if pypi_index_url:
Expand Down Expand Up @@ -119,13 +119,13 @@ def core_check(ctx, **kwargs):
if kwargs.get("dump_state"):
core.dump_state(target=str(kwargs.get("dump_state")), state=state)
click.secho(
"Found compatible PlatformIO Core %s -> %s"
"Found compatible pioarduino Core %s -> %s"
% (state.get("core_version"), state.get("platformio_exe")),
fg="green",
)
except exception.InvalidPlatformIOCore as e:
raise click.ClickException(
"Compatible PlatformIO Core not found.\nReason: %s" % str(e)
"Compatible pioarduino Core not found.\nReason: %s" % str(e)
)


Expand Down
44 changes: 26 additions & 18 deletions pioinstaller/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import subprocess
import sys
import time
import requests

import click
import semantic_version
Expand All @@ -29,15 +30,24 @@

log = logging.getLogger(__name__)

PIO_CORE_API_URL = (
"https://api.github.com/repos/pioarduino/"
"platformio-core/releases/latest"
)
api_data = requests.get(PIO_CORE_API_URL, timeout=10).json()
try:
data = api_data["zipball_url"]
except KeyError:
data = "https://github.com/pioarduino/platformio-core/archive/refs/tags/v6.1.16.zip"
print(
"Could not download actual pioarduino core. Try to install v6.1.16 instead."
)
PIO_CORE_RELEASE_URL = data
PIO_CORE_DEVELOP_URL = (
"https://github.com/pioarduino/platformio-core/"
"archive/pio_github.zip"
)
PIO_CORE_RELEASE_URL = (
"https://github.com/pioarduino/platformio-core/"
"archive/refs/tags/v6.1.16+test.zip"
)
UPDATE_INTERVAL = 60 * 60 * 24 * 3 # 3 days
UPDATE_INTERVAL = 60 * 60 * 24 * 31 # 31 days


def get_core_dir(force_to_root=False):
Expand Down Expand Up @@ -111,10 +121,10 @@ def _install_platformio_core(shutdown_piohome=True, develop=False, ignore_python
)
command = [python_exe, "-m", "pip", "install", "-U"]
if develop:
click.echo("Installing a development version of PlatformIO Core")
click.echo("Installing a development version of pioarduino Core")
command.append(PIO_CORE_DEVELOP_URL)
else:
click.echo("Installing PlatformIO Core")
click.echo("Installing pioarduino Core")
command.append(PIO_CORE_RELEASE_URL)
try:
subprocess.check_call(command)
Expand All @@ -126,15 +136,15 @@ def _install_platformio_core(shutdown_piohome=True, develop=False, ignore_python
" try to disable it for a while.\n %s" % error
)
raise exception.PIOInstallerException(
"Could not install PlatformIO Core: %s" % error
"Could not install pioarduino Core: %s" % error
)
platformio_exe = os.path.join(
penv.get_penv_bin_dir(penv_dir),
"platformio.exe" if util.IS_WINDOWS else "platformio",
)

click.secho(
"\nPlatformIO Core has been successfully installed into an isolated environment `%s`!\n"
"\npioarduino Core has been successfully installed into an isolated environment `%s`!\n"
% penv_dir,
fg="green",
)
Expand All @@ -143,9 +153,7 @@ def _install_platformio_core(shutdown_piohome=True, develop=False, ignore_python
click.secho(
"""
If you need an access to `platformio.exe` from other applications, please install Shell Commands
(add PlatformIO Core binary directory `%s` to the system environment PATH variable):
See https://docs.platformio.org/page/installation.html#install-shell-commands
(add pioarduino Core binary directory `%s` to the system environment PATH variable).
"""
% penv.get_penv_bin_dir(penv_dir),
fg="cyan",
Expand Down Expand Up @@ -173,7 +181,7 @@ def check(develop=False, global_=False, auto_upgrade=False, version_spec=None):
)
if not os.path.isfile(platformio_exe):
raise exception.InvalidPlatformIOCore(
"PlatformIO executable not found in `%s`" % penv.get_penv_bin_dir()
"pioarduino executable not found in `%s`" % penv.get_penv_bin_dir()
)
try:
subprocess.check_output([platformio_exe, "--help"], stderr=subprocess.STDOUT)
Expand All @@ -189,7 +197,7 @@ def check(develop=False, global_=False, auto_upgrade=False, version_spec=None):
except subprocess.CalledProcessError as e:
error = e.output.decode()
raise exception.InvalidPlatformIOCore(
"Could not import PlatformIO module. Error: %s" % error
"Could not import pioarduino module. Error: %s" % error
)
piocore_version = convert_version(result.get("core_version"))
develop = develop or bool(piocore_version.prerelease if piocore_version else False)
Expand Down Expand Up @@ -220,7 +228,7 @@ def check(develop=False, global_=False, auto_upgrade=False, version_spec=None):
try:
result.update(fetch_python_state(python_exe))
except: # pylint:disable=bare-except
raise exception.InvalidPlatformIOCore("Could not import PlatformIO module")
raise exception.InvalidPlatformIOCore("Could not import pioarduino module")

return result

Expand All @@ -229,7 +237,7 @@ def _check_core_version(piocore_version, version_spec):
try:
if piocore_version not in semantic_version.Spec(version_spec):
raise exception.InvalidPlatformIOCore(
"PlatformIO Core version %s does not match version requirements %s."
"pioarduino Core version %s does not match version requirements %s."
% (str(piocore_version), version_spec)
)
except ValueError:
Expand All @@ -254,7 +262,7 @@ def _check_platform_version():
):
return True
raise exception.InvalidPlatformIOCore(
"PlatformIO Core was installed using another platform `%s`. "
"pioarduino Core was installed using another platform `%s`. "
"Your current platform: %s"
% (platform_state.get("platform"), platform.platform(terse=True))
)
Expand Down Expand Up @@ -327,7 +335,7 @@ def auto_upgrade_core(platformio_exe, develop=False):
return True
except Exception as e: # pylint:disable=broad-except
raise exception.PIOInstallerException(
"Could not upgrade PlatformIO Core: %s" % str(e)
"Could not upgrade pioarduino Core: %s" % str(e)
)
return False

Expand Down
2 changes: 1 addition & 1 deletion pioinstaller/penv.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def create_core_penv(penv_dir=None, ignore_pythons=None):
if not result_dir:
raise exception.PIOInstallerException(
"Could not create PIO Core Virtual Environment. Please report to "
"https://github.com/platformio/platformio-core-installer/issues"
"https://github.com/pioarduino/pioarduino-core-installer/issues"
)

python_exe = os.path.join(
Expand Down
13 changes: 6 additions & 7 deletions pioinstaller/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ def fetch_portable_python(dst):
def get_portable_python_url():
systype = util.get_systype()
result = requests.get(
"https://api.registry.platformio.org/v3/packages/"
"platformio/tool/python-portable",
"https://github.com/pioarduino/python-portable/"
"releases/download/v3.11.7/python-portable.json",
timeout=10,
).json()
versions = [
Expand Down Expand Up @@ -129,7 +129,7 @@ def check():
if sys.version_info < (3, 6):
raise exception.IncompatiblePythonError(
"Unsupported Python version: %s. "
"Minimum supported Python version is 3.6 or above."
"Minimum supported Python version is 3.7 or above."
% platform.python_version(),
)

Expand Down Expand Up @@ -239,7 +239,7 @@ def find_compatible_pythons(
if missed_venv_module:
# pylint:disable=line-too-long
raise click.ClickException(
"""Can not install PlatformIO Core due to a missed `venv` module in your Python installation.
"""Can not install pioarduino Core due to a missed `venv` module in your Python installation.
Please install this package manually using the OS package manager. For example:
$ apt-get install python3.%d-venv
Expand All @@ -249,9 +249,8 @@ def find_compatible_pythons(
)

raise exception.IncompatiblePythonError(
"Could not find compatible Python 3.6 or above in your system."
"Please install the latest official Python 3 and restart installation:\n"
"https://docs.platformio.org/page/faq.html#install-python-interpreter"
"Could not find compatible Python 3.7 or above in your system."
"Please install the latest official Python 3 and restart installation."
)

return result

0 comments on commit 2dba218

Please sign in to comment.