-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix commands with an argv0 of "python" on Windows.
Also add support for argv0 being a Python script.
- Loading branch information
Showing
8 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
name: CI | ||
on: [push, pull_request] | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
defaults: | ||
run: | ||
shell: bash | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2024 John Sirois. | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
__version__ = "0.10.4" | ||
__version__ = "0.11.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ include = ["dev_cmd*"] | |
|
||
[dependency-groups] | ||
dev = [ | ||
"ansicolors", | ||
"mypy", | ||
"pytest", | ||
"ruff", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
# Copyright 2025 John Sirois. | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
import subprocess | ||
from pathlib import Path, PurePath | ||
from textwrap import dedent | ||
|
||
import colors | ||
import pytest | ||
from pytest import MonkeyPatch | ||
|
||
|
||
@pytest.fixture | ||
def project_dir() -> PurePath: | ||
return PurePath( | ||
subprocess.run( | ||
args=["git", "rev-parse", "--show-toplevel"], | ||
cwd=PurePath(__file__).parent, | ||
stdout=subprocess.PIPE, | ||
text=True, | ||
check=True, | ||
).stdout.strip() | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def pyproject_toml(monkeypatch: MonkeyPatch, tmp_path: Path, project_dir: PurePath) -> Path: | ||
monkeypatch.chdir(tmp_path) | ||
pyproject_toml_file = tmp_path / "pyproject.toml" | ||
pyproject_toml_file.write_text( | ||
dedent( | ||
f""" | ||
[project] | ||
name = "script-test" | ||
version = "0.1.0" | ||
[dependency-groups] | ||
dev = [ | ||
"ansicolors", | ||
"dev-cmd @ {project_dir.as_posix()}", | ||
] | ||
""" | ||
) | ||
) | ||
return pyproject_toml_file | ||
|
||
|
||
@pytest.fixture | ||
def script(tmp_path: Path) -> PurePath: | ||
script = tmp_path / "script.py" | ||
script.write_text( | ||
dedent( | ||
"""\ | ||
import sys | ||
import colors | ||
if sys.argv[1].endswith(":"): | ||
color = sys.argv[1][:-1] | ||
args = sys.argv[2:] | ||
else: | ||
color = "cyan" | ||
args = sys.argv[1:] | ||
print(colors.color(" ".join(args), fg=color)) | ||
""" | ||
) | ||
) | ||
return script | ||
|
||
|
||
def test_exec_python(script: PurePath, pyproject_toml: Path) -> None: | ||
with pyproject_toml.open("a") as fp: | ||
fp.write( | ||
dedent( | ||
f""" | ||
[tool.dev-cmd.commands.test] | ||
args = ["python", "{script.as_posix()}"] | ||
accepts-extra-args = true | ||
""" | ||
) | ||
) | ||
|
||
assert ( | ||
colors.cyan("Slartibartfast 42") | ||
== subprocess.run( | ||
args=["uv", "run", "dev-cmd", "test", "--", "Slartibartfast", "42"], | ||
stdout=subprocess.PIPE, | ||
text=True, | ||
check=True, | ||
).stdout.strip() | ||
) | ||
|
||
|
||
def test_exec_script(script: PurePath, pyproject_toml: Path) -> None: | ||
with pyproject_toml.open("a") as fp: | ||
fp.write( | ||
dedent( | ||
f""" | ||
[tool.dev-cmd.commands.test] | ||
args = ["{script.as_posix()}"] | ||
accepts-extra-args = true | ||
""" | ||
) | ||
) | ||
|
||
assert ( | ||
colors.magenta("Ford Marvin") | ||
== subprocess.run( | ||
args=["uv", "run", "dev-cmd", "test", "--", "magenta:", "Ford", "Marvin"], | ||
stdout=subprocess.PIPE, | ||
text=True, | ||
check=True, | ||
).stdout.strip() | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.