@@ -53,6 +53,7 @@ class Task(NamedTuple):
|
||||
|
||||
|
||||
class Entry:
|
||||
DEFAULT_EXECUTOR: type[CommandExecutor] = CommandExecutor
|
||||
_logger = logger
|
||||
|
||||
def __init__(
|
||||
@@ -61,11 +62,13 @@ class Entry:
|
||||
variables: Variables,
|
||||
basepath: Path,
|
||||
rootpath: Path,
|
||||
executor: type[CommandExecutor] | None = None,
|
||||
):
|
||||
self._tasks = tasks
|
||||
self._variables = variables
|
||||
self._basepath = basepath
|
||||
self._roopath = rootpath
|
||||
self._executor = executor or self.DEFAULT_EXECUTOR
|
||||
|
||||
@property
|
||||
def sensentive_data(self):
|
||||
@@ -103,7 +106,7 @@ class Entry:
|
||||
if key == task.key:
|
||||
self._logger.info("🔵 %s %s", task.key, self)
|
||||
for command in task.commands:
|
||||
CommandExecutor(command).run(
|
||||
self._executor(command).run(
|
||||
(task.cwd and Path(task.cwd)) or self._basepath
|
||||
)
|
||||
c += 1
|
||||
|
||||
@@ -5,7 +5,7 @@ variables.python_poetry = "{{ 'pyproject.toml' | read | get('build-system.build-
|
||||
# setup
|
||||
[presets.python.tasks.setup.poetry]
|
||||
conditions = ["{{ python_poetry }}"]
|
||||
variables.python_version = "{{ 'pyproject.toml' | read | get('project.requires-python') | search('(\\d+.\\d+)') }}"
|
||||
variables.python_version = "{{ 'pyproject.toml' | read | get('project.requires-python') | search('(\\\\d+.\\\\d+)') }}"
|
||||
commands = ["poetry env use {{ python_version }}", "poetry install --all-extras"]
|
||||
|
||||
# playwright
|
||||
|
||||
@@ -3,7 +3,10 @@
|
||||
"version": "0.1.0",
|
||||
"description": "",
|
||||
"scripts": {
|
||||
"build": "echo build"
|
||||
"build": "echo build",
|
||||
"test": "echo test",
|
||||
"format": "echo format",
|
||||
"lint": "echo lint"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jest": "^29.2.2"
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
[tool.poetry]
|
||||
name = "example"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = []
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.8"
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
black = "^23.1.0"
|
||||
pytest = "^7.2.2"
|
||||
isort = "^5.12.0"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
+23
-2
@@ -4,6 +4,7 @@ from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from project_manager.common.command import CommandExecutor
|
||||
from project_manager.entry.detector import EntryDetector
|
||||
from project_manager.entry.entry import Entry, PartialTaskKey
|
||||
from project_manager.preset.detector import PresetEntryDetector
|
||||
@@ -29,6 +30,24 @@ def entry(entry_detector: EntryDetector, entry_path: Path, tmp_path: Path):
|
||||
return entry_detector.detect_entry(destination, destination)
|
||||
|
||||
|
||||
class FakeCommandExecutor(CommandExecutor):
|
||||
def run(self, basepath: Path) -> dict | None:
|
||||
if self._command == "npm install":
|
||||
(basepath / "node_modules").mkdir(exist_ok=True)
|
||||
elif self._command == "poetry install --all-extras":
|
||||
bin_dir = basepath / ".venv/bin"
|
||||
bin_dir.mkdir(parents=True, exist_ok=True)
|
||||
(bin_dir / "pytest").write_text("")
|
||||
(bin_dir / "pylint").write_text("")
|
||||
(bin_dir / "isort").write_text("")
|
||||
(bin_dir / "black").write_text("")
|
||||
|
||||
|
||||
@pytest.fixture(scope="module", autouse=True)
|
||||
def entry_command_executor():
|
||||
Entry.DEFAULT_EXECUTOR = FakeCommandExecutor
|
||||
|
||||
|
||||
@pytest.mark.parametrize("entry_path", [Path(__file__).parent / "python"])
|
||||
def test_python_entry(entry: Entry | None, entry_detector: EntryDetector):
|
||||
assert entry is not None
|
||||
@@ -44,10 +63,12 @@ def test_python_entry(entry: Entry | None, entry_detector: EntryDetector):
|
||||
@pytest.mark.parametrize("entry_path", [Path(__file__).parent / "nodejs"])
|
||||
def test_nodejs_entry(entry: Entry | None, entry_detector: EntryDetector):
|
||||
assert entry is not None
|
||||
assert {"setup", "build"} == {task.key.name for task in entry._tasks}
|
||||
assert {"setup", "build", "lint", "format", "test"} == {
|
||||
task.key.name for task in entry._tasks
|
||||
}
|
||||
entry.run_task(PartialTaskKey.from_str("setup"))
|
||||
entry = entry_detector.detect_entry(entry._basepath, entry._basepath)
|
||||
assert entry is not None
|
||||
assert {"setup", "build", "test", "clean"} == {
|
||||
assert {"setup", "build", "lint", "format", "test", "clean"} == {
|
||||
task.key.name for task in entry._tasks
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user