Skip to content

Commit

Permalink
rename: _DS_CURRENT_FILE to DS_INTERNAL__FILE (closes #81)
Browse files Browse the repository at this point in the history
  • Loading branch information
metaist committed Aug 23, 2024
1 parent 394517f commit b6c6ab5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/formats/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"will_fail": "exit 1",
"keep_going": "ds +will_fail",
"working": "ds --cwd test basic1",
"inside": "echo $_DS_CURRENT_FILE",
"inside": "echo $DS_INTERNAL__FILE",
"outside": "ds -f pyproject-ds.toml outside"
}
}
2 changes: 1 addition & 1 deletion examples/formats/pyproject-ds.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ release = """
"""

# This task is called from package.json in the same directory.
outside = "echo $_DS_CURRENT_FILE"
outside = "echo $DS_INTERNAL__FILE"
10 changes: 4 additions & 6 deletions src/ds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
from .tasks import print_tasks
from .tasks import Task

# from .runner import Runner

__version__ = "1.2.0post"
__pubdate__ = "unpublished"

Expand Down Expand Up @@ -71,8 +69,8 @@ def load_config(args: Args) -> Config:
"""Load configuration file."""
try:
if not args.file:
if path := ENV.get("_DS_CURRENT_FILE"):
log.debug(f"Setting --file to $_DS_CURRENT_FILE = {path}")
if path := ENV.get("DS_INTERNAL__FILE"):
log.debug(f"Setting --file to $DS_INTERNAL__FILE = {path}")
args.file = Path(path)

require_workspace = bool(args.workspace)
Expand Down Expand Up @@ -121,7 +119,7 @@ def run_workspace(args: Args, config: Config) -> None:
member_args.file = None

try:
with TempEnv(_DS_CURRENT_FILE=None):
with TempEnv(DS_INTERNAL__FILE=None):
with pushd(member):
cli_args = member_args.as_argv()
print(f"$ pushd {member}")
Expand Down Expand Up @@ -180,7 +178,7 @@ def main(argv: Optional[List[str]] = None) -> None:
runner.tasks = config.tasks

try:
with TempEnv(_DS_CURRENT_FILE=str(args.file)):
with TempEnv(DS_INTERNAL__FILE=str(args.file)):
with pushd(args.cwd or Path()):
runner.run(args.task, Task())
except KeyboardInterrupt: # pragma: no cover
Expand Down
12 changes: 6 additions & 6 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,32 @@ def test_stay_in_file() -> None:
def test_get_file_from_env() -> None:
"""Get config file from environment variable."""
path = str(Path("examples") / "formats" / "package.json")
with TempEnv(_DS_CURRENT_FILE=path):
with TempEnv(DS_INTERNAL__FILE=path):
main(split("ds"))

with TempEnv(_DS_CURRENT_FILE=path):
with TempEnv(DS_INTERNAL__FILE=path):
main(split("ds --debug"))

with TempEnv(_DS_CURRENT_FILE=None):
with TempEnv(DS_INTERNAL__FILE=None):
main(split("ds"))


def test_run_workspace() -> None:
"""Run a workspace."""
with TempEnv(_DS_CURRENT_FILE=None):
with TempEnv(DS_INTERNAL__FILE=None):
with pushd(PATH_WK):
main(split("ds --debug -w*"))


def test_run_some_workspaces() -> None:
"""Run in only one workspace."""
with TempEnv(_DS_CURRENT_FILE=None):
with TempEnv(DS_INTERNAL__FILE=None):
with pushd(PATH_WK):
main(split("ds -w '*/a'"))


def test_workspace_same_name() -> None:
"""Run files with same name."""
with TempEnv(_DS_CURRENT_FILE=None):
with TempEnv(DS_INTERNAL__FILE=None):
with pushd(PATH_WK):
main(split("ds --file 'package.json' -w*"))

0 comments on commit b6c6ab5

Please sign in to comment.