Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def pioplus_call(args, **kwargs):
if WINDOWS and sys.version_info < (2, 7, 6):
raise exception.PlatformioException(
"PlatformIO Core Plus v%s does not run under Python version %s.\n"
"Minimum supported version is 2.7.6, please upgrade Python.\n"
"Python 3 is not yet supported.\n" % (__version__, sys.version)
)
pioplus_path = join(get_core_package_dir("tool-pioplus"), "pioplus")
pythonexe_path = get_pythonexe_path()
os.environ["PYTHONEXEPATH"] = pythonexe_path
os.environ["PYTHONPYSITEDIR"] = get_core_package_dir("contrib-pysite")
os.environ["PIOCOREPYSITEDIR"] = dirname(fs.get_source_dir() or "")
if dirname(pythonexe_path) not in os.environ["PATH"].split(os.pathsep):
os.environ["PATH"] = (os.pathsep).join(
[dirname(pythonexe_path), os.environ["PATH"]]
)
copy_pythonpath_to_osenv()
code = subprocess.call([pioplus_path] + args, **kwargs)
def new(tool, project_dir, config, envname, options):
cls = None
if tool == "cppcheck":
cls = CppcheckCheckTool
elif tool == "clangtidy":
cls = ClangtidyCheckTool
else:
raise exception.PlatformioException("Unknown check tool `%s`" % tool)
return cls(project_dir, config, envname, options)
def configure_default_packages(self, envoptions, targets):
if (envoptions.get("framework") == "wiringpi" and
"linux_arm" not in util.get_systype()):
raise exception.PlatformioException(
"PlatformIO does not support temporary cross-compilation "
"for WiringPi framework. Please run PlatformIO directly on "
"Raspberry Pi"
)
return BasePlatform.configure_default_packages(
self, envoptions, targets)
https://docs.platformio.org/page/installation.html
"""
class HomeDirPermissionsError(UserSideException):
MESSAGE = (
"The directory `{0}` or its parent directory is not owned by the "
"current user and PlatformIO can not store configuration data.\n"
"Please check the permissions and owner of that directory.\n"
"Otherwise, please remove manually `{0}` directory and PlatformIO "
"will create new from the current user."
)
class CygwinEnvDetected(PlatformioException):
MESSAGE = (
"PlatformIO does not work within Cygwin environment. "
"Use native Terminal instead."
)
class TestDirNotExists(PlatformioException):
MESSAGE = (
"A test folder '{0}' does not exist.\nPlease create 'test' "
"directory in project's root and put a test set.\n"
#
# Development Platform
#
class UnknownPlatform(PlatformioException):
MESSAGE = "Unknown development platform '{0}'"
class IncompatiblePlatform(PlatformioException):
MESSAGE = "Development platform '{0}' is not compatible with PIO Core v{1}"
class PlatformNotInstalledYet(PlatformioException):
MESSAGE = (
"The platform '{0}' has not been installed yet. "
"Use `platformio platform install {0}` command"
)
class UnknownBoard(PlatformioException):
MESSAGE = "Unknown board ID '{0}'"
class InvalidBoardManifest(PlatformioException):
MESSAGE = "Invalid board JSON manifest '{0}'"
# pylint: disable=not-an-iterable
return self.MESSAGE.format(*self.args)
return super(PlatformioException, self).__str__()
class ReturnErrorCode(PlatformioException):
MESSAGE = "{0}"
class LockFileTimeoutError(PlatformioException):
pass
class MinitermException(PlatformioException):
pass
class UserSideException(PlatformioException):
pass
class AbortedByUser(UserSideException):
MESSAGE = "Aborted by user"
#
# Development Platform
#
MESSAGE = None
def __str__(self): # pragma: no cover
if self.MESSAGE:
# pylint: disable=not-an-iterable
return self.MESSAGE.format(*self.args)
return super(PlatformioException, self).__str__()
class ReturnErrorCode(PlatformioException):
MESSAGE = "{0}"
class LockFileTimeoutError(PlatformioException):
pass
class MinitermException(PlatformioException):
pass
class UserSideException(PlatformioException):
pass
class AbortedByUser(UserSideException):
MESSAGE = "Aborted by user"
def __init__(self, manifest_path):
self._id = basename(manifest_path)[:-5]
assert isfile(manifest_path)
self.manifest_path = manifest_path
try:
self._manifest = util.load_json(manifest_path)
except ValueError:
raise exception.InvalidBoardManifest(manifest_path)
if not set(["name", "url", "vendor"]) <= set(self._manifest):
raise exception.PlatformioException(
"Please specify name, url and vendor fields for " +
manifest_path)
"If you build a project first time, we need Internet connection "
"to install all dependencies and toolchains."
)
class BuildScriptNotFound(PlatformioException):
MESSAGE = "Invalid path '{0}' to build script"
class InvalidSettingName(PlatformioException):
MESSAGE = "Invalid setting with the name '{0}'"
class InvalidSettingValue(PlatformioException):
MESSAGE = "Invalid value '{0}' for the setting '{1}'"
class InvalidJSONFile(PlatformioException):
MESSAGE = "Could not load broken JSON: {0}"
class CIBuildEnvsEmpty(PlatformioException):
MESSAGE = (
"Can't find PlatformIO build environments.\n"
"Please specify `--board` or path to `platformio.ini` with "
"predefined environments using `--project-conf` option"
)
def get_project_build_data(self):
data = {
"defines": [],
"includes": [],
"cxx_path": None
}
envdata = self.get_project_env()
if "env_name" not in envdata:
return data
result = util.exec_command(
["platformio", "-f", "run", "-t", "idedata",
"-e", envdata['env_name'], "-d", self.project_dir]
)
if result['returncode'] != 0 or '"includes":' not in result['out']:
raise exception.PlatformioException(
"\n".join([result['out'], result['err']]))
output = result['out']
start_index = output.index('\n{"')
stop_index = output.rindex('}')
data = json.loads(output[start_index + 1:stop_index + 1])
return data