kraken.std.python
kraken.std.python
BlackTask
Bases: EnvironmentAwareDispatchTask
A task to run the black
formatter to either check for necessary changes or apply changes.
Source code in kraken/std/python/tasks/black_task.py
Flake8Task
Bases: EnvironmentAwareDispatchTask
Lint Python source files with Flake8.
Source code in kraken/std/python/tasks/flake8_task.py
InfoTask
Bases: Task
Source code in kraken/std/python/tasks/info_task.py
execute
execute() -> TaskStatus
Displays metadata about the Kraken-managed environment.
Source code in kraken/std/python/tasks/info_task.py
get_python_path
Returns the path of the Python interpreter of the Kraken-managed environment.
get_python_version
Returns the version of the Python interpreter of the Kraken-managed environment.
Source code in kraken/std/python/tasks/info_task.py
get_virtual_env_path
PublishTask
Bases: Task
Publishes Python distributions to one or more indexes using :mod:twine
.
Source code in kraken/std/python/tasks/publish_task.py
PyclnTask
Bases: EnvironmentAwareDispatchTask
A task to run the pycln
formatter to either check for necessary changes or apply changes.
Source code in kraken/std/python/tasks/pycln_task.py
PythonSettings
dataclass
Project-global settings for Python tasks.
Source code in kraken/std/python/settings.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
add_package_index
add_package_index(
alias: str,
*,
index_url: str | None = None,
upload_url: str | None = None,
credentials: tuple[str, str] | None = None,
is_package_source: bool = True,
priority: (
Priority | str
) = PackageIndex.Priority.supplemental,
publish: bool = False
) -> PythonSettings
Adds an index to consume Python packages from or publish packages to.
:param alias: An alias for the package index.
:param index_url: The URL of the package index (with the trailing /simple
bit if applicable).
If not specified, alias must be a known package index (pypi
or testpypi
).
:param upload_url: If the upload url deviates from the registry URL. Otherwise, the upload URL will
be the same as the url,
:param credentials: Optional credentials to read from the index.
:param is_package_source: If set to False
, the index will not be used to source packages from, but
can be used to publish to.
:param publish: Whether publishing to this index should be enabled.
Source code in kraken/std/python/settings.py
get_tests_directory
Returns :attr:tests_directory
if it is set. If not, it will look for the following directories and
return the first that exists: test/
, tests/
, src/test/
, src/tests/
. The determined path will be
relative to the project directory.
Source code in kraken/std/python/settings.py
get_tests_directory_as_args
Returns a list with a single item that is the test directory, or an empty list. This is convenient when constructing command-line arguments where you want to pass the test directory if it exists.
Source code in kraken/std/python/settings.py
RuffTask
Bases: EnvironmentAwareDispatchTask
A task to run ruff
in either format, fix, or check mode.
Source code in kraken/std/python/tasks/ruff_task.py
black
black(
*,
name: str = "python.black",
project: Project | None = None,
config_file: Path | Supplier[Path] | None = None,
additional_args: (
Sequence[str] | Supplier[Sequence[str]]
) = (),
additional_files: (
Sequence[Path] | Supplier[Sequence[Path]]
) = (),
version_spec: str | None = None
) -> BlackTasks
Creates two black tasks, one to check and another to format. The check task will be grouped under "lint"
whereas the format task will be grouped under "fmt"
.
:param version_spec: If specified, the Black tool will be installed as a PEX and does not need to be installed into the Python project's virtual env.
Source code in kraken/std/python/tasks/black_task.py
build
build(
*,
name: str = "python.build",
group: str | None = "build",
as_version: str | None = None,
project: Project | None = None
) -> BuildTask
Creates a build task for the given project.
The build task relies on the build system configured in the Python project settings.
Source code in kraken/std/python/tasks/build_task.py
flake8
flake8(
*,
name: str = "python.flake8",
project: Project | None = None,
config_file: Path | Supplier[Path] | None = None,
version_spec: str | None = None,
additional_requirements: Sequence[str] = ()
) -> Flake8Task
Creates a task for linting your Python project with Flake8.
:param version_spec: If specified, the Flake8 tool will be installed as a PEX and does not need to be installed into the Python project's virtual env.
Source code in kraken/std/python/tasks/flake8_task.py
git_version_to_python_version
git_version_to_python_version(
value: str | GitVersion, include_sha: bool
) -> str
Converts a Git version to a Python version.
:param value: The Git version to convert. :param sha: Include the SHA of the commit distance if it exists.
Source code in kraken/std/python/version.py
info
info(
*,
project: Project | None = None,
build_system: PythonBuildSystem | None = None
) -> InfoTask
This task displays a list of useful info on current Python and virtual environment settings.
Source code in kraken/std/python/tasks/info_task.py
install
install(
*,
name: str = "python.install",
project: Project | None = None
) -> InstallTask
Get or create the python.install
task for the given project.
The install task relies on the build system configured in the Python project settings.
Source code in kraken/std/python/tasks/install_task.py
isort
isort(
*,
name: str = "python.isort",
project: Project | None = None,
config_file: Path | Supplier[Path] | None = None,
additional_files: (
Sequence[Path] | Supplier[Sequence[Path]]
) = (),
version_spec: str | None = None
) -> IsortTasks
:param version_spec: If specified, the isort tool will be installed as a PEX and does not need to be installed into the Python project's virtual env.
Source code in kraken/std/python/tasks/isort_task.py
mypy
mypy(
*,
name: str = "python.mypy",
project: Project | None = None,
config_file: Path | Supplier[Path] | None = None,
additional_args: (
Sequence[str] | Supplier[Sequence[str]]
) = (),
check_tests: bool = True,
use_daemon: bool = True,
python_version: str | Supplier[str] | None = None,
version_spec: str | None = None
) -> MypyTask
:param version_spec: If specified, the Mypy tool will be installed as a PEX and does not need to be installed into the Python project's virtual env.
Source code in kraken/std/python/tasks/mypy_task.py
mypy_stubtest
mypy_stubtest(
*,
name: str = "python.mypy.stubtest",
project: Project | None = None,
package: str,
ignore_missing_stubs: bool = False,
ignore_positional_only: bool = False,
allowlist: Path | None = None,
mypy_config_file: Path | None = None,
mypy_pex_bin: Path | Property[Path] | None = None
) -> MypyStubtestTask
:param version_spec: If specified, the isort tool will be installed as a PEX and does not need to be installed into the Python project's virtual env.
Source code in kraken/std/python/tasks/mypy_stubtest_task.py
publish
publish(
*,
package_index: str,
distributions: list[Path] | Property[list[Path]],
skip_existing: bool = False,
interactive: bool = True,
name: str = "python.publish",
group: str | None = "publish",
project: Project | None = None,
after: list[Task] | None = None,
twine_version: str = ">=5.0.0,<6.0.0"
) -> PublishTask
Create a publish task for the specified registry.
Source code in kraken/std/python/tasks/publish_task.py
pycln
pycln(
*,
name: str = "python.pycln",
project: Project | None = None,
version_spec: str | None = None
) -> PyclnTasks
Creates two pycln tasks, one to check and another to format. The check task will be grouped under "lint"
whereas the format task will be grouped under "fmt"
.
:param version_spec: If specified, the pycln tool will be installed as a PEX and does not need to be installed into the Python project's virtual env.
Source code in kraken/std/python/tasks/pycln_task.py
pylint
pylint(
*,
name: str = "python.pylint",
project: Project | None = None,
config_file: Path | Supplier[Path] | None = None,
additional_args: (
Sequence[str] | Property[Sequence[str]]
) = (),
version_spec: str | None = None
) -> PylintTask
:param version_spec: If specified, the pylint tool will be installed as a PEX and does not need to be installed into the Python project's virtual env.
Source code in kraken/std/python/tasks/pylint_task.py
python_settings
python_settings(
project: Project | None = None,
build_system: PythonBuildSystem | None = None,
source_directory: str | Path | None = None,
tests_directory: str | Path | None = None,
lint_enforced_directories: (
list[str | Path] | None
) = None,
always_use_managed_env: bool | None = None,
skip_install_if_venv_exists: bool | None = None,
) -> PythonSettings
Read the Python settings for the given or current project and optionally update attributes.
:param project: The project to get the settings for. If not specified, the current project will be used.
:environment_handler: If specified, set the :attr:PythonSettings.environment_handler
. If a string is specified,
the following values are currently supported: "poetry"
.
:param source_directory: The source directory. Defaults to "src"
.
:param tests_directory: The tests directory. Automatically determined if left empty.
:param lint_enforced_directories: Any extra directories containing Python files, e.g. bin/, scripts/, and
examples/, to be linted alongside the source and tests directories.
Source code in kraken/std/python/settings.py
pyupgrade
pyupgrade(
*,
name: str = "python.pyupgrade",
project: Project | None = None,
exclude: Collection[Path] = (),
exclude_patterns: Collection[str] = (),
keep_runtime_typing: bool = False,
python_version: str = "3",
additional_files: Sequence[Path] = (),
version_spec: str | None = None
) -> PyUpgradeTasks
:param version_spec: If specified, the pyupgrade tool will be installed as a PEX and does not need to be installed into the Python project's virtual env.
Source code in kraken/std/python/tasks/pyupgrade_task.py
ruff
ruff(
*,
name: str = "python.ruff",
project: Project | None = None,
config_file: Path | Supplier[Path] | None = None,
additional_args: (
Sequence[str] | Supplier[Sequence[str]]
) = (),
additional_requirements: Sequence[str] = (),
version_spec: str | None = ">=0.5.0,<0.6.0"
) -> RuffTasks
Creates three tasks for formatting and linting your Python project with Ruff.
:param name: Prefix name for the ruff tasks.
:param project: Project used for the generated ruff tasks. If not specified will consider Project.current()
.
:param config_file: Configuration file to consider.
:param additional_args: Additional arguments to pass to all ruff tasks.
:param additional_requirements: Additional requirements to pass to pex_build.
:param version_spec: If specified, the Ruff tool will be installed as a PEX and does not need to be installed
into the Python project's virtual env.
Source code in kraken/std/python/tasks/ruff_task.py
update_lockfile_task
update_lockfile_task(
*,
name: str = "python.update",
group: str | None = "update",
project: Project | None = None
) -> UpdateLockfileTask
Creates an update task for the given project.
The update task relies on the build system configured in the Python project settings.