plesty.sdk.commands.init
CLI command for initializing a new Plesty project from a template.
Attributes
Functions
|
Return |
|
Return the newest |
|
Return version parsed, or |
|
Return the version specifier to write after |
|
Initialize a new Plesty project from a template. |
|
Run ruff format on generated Python files so the initial commit is already clean. |
|
Stage all generated files and create an initial commit. |
|
Write a .gitlab-ci.yml that uses the plesty-standard-ci CI component. |
|
Echo the concrete next steps for a freshly scaffolded project. |
|
Write a pre-push git hook that runs plesty check. |
|
Copy type-specific extra files into the generated module directory. |
Module Contents
- plesty.sdk.commands.init.MODULE_NAME_PATTERN
- plesty.sdk.commands.init._STANDARD_CI_STAGES = ('check', 'security', 'deploy', 'release')
- plesty.sdk.commands.init.PLESTY_LIB_VERSION = '0.5.1'
- plesty.sdk.commands.init._own_line_floor() str
Return
major.minor.0of the installedplesty-sdk.A scaffold is written against the gates and the
plesty init field-testinterview of the SDK generating it, so the pin names that SDK’s own line. A hand-kept constant went stale: 0.4 and 0.5 still pinned 0.3.4, which lacks the gates their scaffolds rely on.- Return type:
str
- plesty.sdk.commands.init.PLESTY_SDK_VERSION
- plesty.sdk.commands.init.PYPI_LIB_URL = 'https://pypi.org/pypi/plesty-lib/json'
- plesty.sdk.commands.init.PYPI_TIMEOUT_S = 3.0
- plesty.sdk.commands.init.resolve_lib_version(url: str = PYPI_LIB_URL, timeout: float = PYPI_TIMEOUT_S) str
Return the newest
plesty-libon PyPI, orPLESTY_LIB_VERSION.A scaffold should start on the library that exists today, not on the one that existed when this SDK was released — the pin is what a new module lives with until someone edits it. Pre-releases count: the development line is where the features the templates use land first, and a pin naming a
.devNis what makes them resolvable at all.Anything the network does wrong — no route, a proxy, a timeout, a body that is not the JSON expected — falls back to the built-in floor rather than failing the scaffold. The answer is never older than that floor.
- Parameters:
url (str) – PyPI JSON endpoint for the package.
timeout (float) – Seconds to wait for it.
- Returns:
The version string to pin with
>=.- Return type:
str
- plesty.sdk.commands.init._parse_version(version: str) packaging.version.Version | None
Return version parsed, or
Nonewhen PyPI lists something unreadable.- Parameters:
version (str)
- Return type:
packaging.version.Version | None
- plesty.sdk.commands.init.lib_specifier(requested: str | None = None) str
Return the version specifier to write after
plesty-libin pyproject.Without requested the pin follows PyPI (
resolve_lib_version()). With it, the caller decides and no lookup happens — a tutorial pins the library its lesson text was written against, so the page and the file the reader ends up with keep saying the same thing however far the library has moved since; an air-gapped machine gets the same determinism.- Parameters:
requested (str | None) – A bare version (
"0.3.5.dev3"→">=0.3.5.dev3") or a complete specifier, which is taken as written ("==0.4.0",">=0.3.5.dev3,<0.4").- Returns:
The specifier, leading operator included.
- Raises:
click.ClickException – If requested is neither a version nor a specifier PEP 440 can read.
- Return type:
str
- plesty.sdk.commands.init.init_command(context: plesty.sdk.context.ApplicationContext, project_type: str, module_name: str | None, author: str | None, email: str | None, standard: str, lib_version: str | None, no_ci: bool, force: bool) None
Initialize a new Plesty project from a template.
PROJECT_TYPE is one of: default, device, analyzer, experiment. Defaults to ‘default’.
Two project types add to an existing device module rather than creating a project.
plesty init field-testreads what the device declares and asks the developer to classify what no inspection can answer — which operations are safe unattended, which parameters survive being written back their own value, what is slow enough to interrupt — then writestests/field_test.pywith the answers and the reasons recorded as comments.plesty init mock-testasks nothing: it probes the module for a construction that runs without hardware, verifies it against the gates it will have to pass, and writes the hardware-free test gate d1 requires.- Conventions:
Project folder: plesty-foo-bar
Src code folder: foo_bar
Build target: plesty-foo-bar
Import: plesty.foo_bar
The project is created in the directory set via the global –project-dir option (defaults to the current working directory). If the directory does not yet exist it is created; if it already exists it must be empty (hidden entries such as .git are ignored).
The –name option sets the Python module name (snake_case). When omitted, the name is inferred from the project directory name: the ‘plesty-’ prefix is stripped and remaining hyphens are converted to underscores (e.g. ‘plesty-foo-bar’ → ‘foo_bar’).
- Parameters:
context (plesty.sdk.context.ApplicationContext)
project_type (str)
module_name (str | None)
author (str | None)
email (str | None)
standard (str)
lib_version (str | None)
no_ci (bool)
force (bool)
- Return type:
None
- plesty.sdk.commands.init._format_generated_files(project_dir: pathlib.Path) None
Run ruff format on generated Python files so the initial commit is already clean.
Failures are silently ignored — formatting is best-effort at scaffold time.
- Parameters:
project_dir (pathlib.Path)
- Return type:
None
- plesty.sdk.commands.init._git_initial_commit(project_dir: pathlib.Path) None
Stage all generated files and create an initial commit.
versioningit needs at least one commit to resolve a version from git history. Always initialises a git repo in project_dir so we never accidentally operate on a parent repo when the project lives inside a workspace.
- Parameters:
project_dir (pathlib.Path)
- Return type:
None
- plesty.sdk.commands.init.generate_gitlab_ci(project_dir: pathlib.Path, standard: str = 'quantum') None
Write a .gitlab-ci.yml that uses the plesty-standard-ci CI component.
- Parameters:
project_dir (pathlib.Path)
standard (str)
- Return type:
None
- plesty.sdk.commands.init._echo_next_steps(project_type: str, module_name: str) None
Echo the concrete next steps for a freshly scaffolded project.
The step text lives in the packaged
assets/init/next-steps.yaml:setupsteps first, then the project-type-specific ones, thenverify.{module_name}placeholders are substituted here.- Parameters:
project_type (str) – The scaffolded project type (default/device/experiment).
module_name (str) – The Python module name of the new project.
- Return type:
None
- plesty.sdk.commands.init._LEAKING_GIT_VARS = ('GIT_DIR', 'GIT_WORK_TREE', 'GIT_INDEX_FILE', 'GIT_PREFIX', 'GIT_COMMON_DIR')
- plesty.sdk.commands.init._install_pre_push_hook(project_dir: pathlib.Path, quiet: bool = False) None
Write a pre-push git hook that runs plesty check.
The standard is read from [tool.plesty] standard in pyproject.toml; when unset it is derived from the release version (<0.1 pixel, <1.0 nebula, >=1.0 quantum), so a module’s pre-push enforcement ramps up with its releases.
The hook clears the git variables the hook environment carries; see
_LEAKING_GIT_VARSfor what they break.- Parameters:
project_dir (pathlib.Path)
quiet (bool)
- Return type:
None
- plesty.sdk.commands.init._copy_extras(extras_src: pathlib.Path, dest: pathlib.Path) None
Copy type-specific extra files into the generated module directory.
- Parameters:
extras_src (pathlib.Path)
dest (pathlib.Path)
- Return type:
None