ppqs 2.6.1__tar.gz → 3.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5
+
6
+ version: 2
7
+ updates:
8
+
9
+ - package-ecosystem: "pip"
10
+ directory: "/"
11
+ schedule:
12
+ interval: "monthly"
13
+ groups:
14
+ pip-updates:
15
+ patterns:
16
+ - "*"
17
+
18
+ - package-ecosystem: "github-actions"
19
+ directory: "/"
20
+ schedule:
21
+ interval: "monthly"
22
+ groups:
23
+ action-updates:
24
+ patterns:
25
+ - "*"
26
+
27
+ - package-ecosystem: "pre-commit"
28
+ directory: "/"
29
+ schedule:
30
+ interval: "monthly"
31
+ groups:
32
+ pre-commit-updates:
33
+ patterns:
34
+ - "*"
@@ -0,0 +1,72 @@
1
+ name: Publish package
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - 'v*'
7
+ workflow_dispatch: null
8
+
9
+ jobs:
10
+ test:
11
+ uses: ./.github/workflows/test.yml
12
+
13
+ publish:
14
+ needs: test
15
+ runs-on: ubuntu-latest
16
+
17
+ environment: ${{ github.event_name == 'workflow_dispatch' && 'testpypi' || 'pypi' }}
18
+
19
+ permissions:
20
+ id-token: write
21
+ attestations: write
22
+ contents: read
23
+
24
+ env:
25
+ SETUPTOOLS_SCM_OVERRIDES_FOR_PPQS: '{local_scheme="no-local-version"}'
26
+
27
+ steps:
28
+ - name: Checkout source code
29
+ uses: actions/checkout@v7
30
+ with:
31
+ fetch-depth: 0
32
+
33
+ - name: Set up Python
34
+ uses: actions/setup-python@v7
35
+ with:
36
+ python-version: '3.11'
37
+
38
+ - name: Initialise project
39
+ uses: nick-fields/retry@v4
40
+ with:
41
+ timeout_minutes: 5
42
+ max_attempts: 3
43
+ retry_wait_seconds: 30
44
+ command: |
45
+ python -m pip install --upgrade pip
46
+ python -m pip install .
47
+ ppqs init
48
+ ppqs version
49
+
50
+ - name: Build project
51
+ run: |
52
+ ppqs build
53
+
54
+ - name: Validate metadata
55
+ run: |
56
+ twine check dist/*
57
+
58
+ - name: Attest build
59
+ uses: actions/attest-build-provenance@v4
60
+ with:
61
+ subject-path: "dist/*"
62
+
63
+ - name: Publish to PyPI
64
+ uses: pypa/gh-action-pypi-publish@release/v1
65
+ if: ${{ github.event_name == 'push' }}
66
+
67
+ - name: Publish to TestPyPI
68
+ uses: pypa/gh-action-pypi-publish@release/v1
69
+ if: ${{ github.event_name == 'workflow_dispatch' }}
70
+ with:
71
+ repository-url: https://test.pypi.org/legacy/
72
+ skip-existing: true
@@ -0,0 +1,81 @@
1
+ name: Test package
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - "*"
7
+ pull_request:
8
+ branches:
9
+ - "*"
10
+ workflow_call: null
11
+ workflow_dispatch: null
12
+
13
+ jobs:
14
+ test:
15
+ runs-on: ubuntu-latest
16
+
17
+ strategy:
18
+ fail-fast: false
19
+ matrix:
20
+ python-version:
21
+ - "3.11"
22
+ - "3.12"
23
+ - "3.13"
24
+ - "3.14"
25
+ - "3.15"
26
+
27
+ steps:
28
+ - name: Checkout
29
+ uses: actions/checkout@v7
30
+ with:
31
+ fetch-depth: 0
32
+
33
+ - name: Set up Python ${{ matrix.python-version }}
34
+ uses: actions/setup-python@v7
35
+ with:
36
+ python-version: ${{ matrix.python-version }}
37
+
38
+ - name: Initialise project
39
+ uses: nick-fields/retry@v4
40
+ with:
41
+ timeout_minutes: 5
42
+ max_attempts: 3
43
+ retry_wait_seconds: 30
44
+ command: |
45
+ python -m pip install --upgrade pip
46
+ python -m pip install .
47
+ ppqs init
48
+ python -m venv $RUNNER_TEMP/venv
49
+ source $RUNNER_TEMP/venv/bin/activate
50
+ python -m pip install --upgrade pip
51
+ python -m pip install .
52
+ ppqs init
53
+ ppqs version
54
+
55
+ - name: Perform linting checks
56
+ run: |
57
+ ppqs lint
58
+
59
+ - name: Build project
60
+ run: |
61
+ ppqs build
62
+
63
+ - name: Run tests
64
+ run: |
65
+ ppqs test --no-cov
66
+ source $RUNNER_TEMP/venv/bin/activate
67
+ ppqs test
68
+
69
+ - name: Clean up build files
70
+ run: |
71
+ ppqs clean
72
+
73
+ all-done:
74
+ runs-on: ubuntu-latest
75
+
76
+ needs: test
77
+
78
+ steps:
79
+ - name: All done
80
+ run: |
81
+ echo All done
ppqs-3.0.0/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .coverage
2
+ /build
3
+ /dist
4
+ /src/*.egg-info
5
+ __pycache__
@@ -0,0 +1,33 @@
1
+ default_install_hook_types: [pre-commit, post-commit]
2
+
3
+ repos:
4
+
5
+ - repo: https://github.com/pre-commit/pre-commit-hooks
6
+ rev: v6.0.0
7
+ hooks:
8
+ - id: mixed-line-ending
9
+ args: [--fix=lf]
10
+ - id: trailing-whitespace
11
+ - id: end-of-file-fixer
12
+ - id: check-added-large-files
13
+ - id: check-toml
14
+ - id: check-yaml
15
+ - id: file-contents-sorter
16
+ args: [--unique]
17
+ files: ^\.gitattributes$|^\.gitignore$|^requirements-dev\.txt$
18
+
19
+ - repo: https://github.com/astral-sh/ruff-pre-commit
20
+ rev: v0.17.4
21
+ hooks:
22
+ - id: ruff-check
23
+
24
+ - repo: https://github.com/assorted-pre-commit-hooks/copyright
25
+ rev: v0.12
26
+ hooks:
27
+ - id: copyright
28
+
29
+ - repo: https://github.com/psf/black
30
+ rev: 26.10.1
31
+ hooks:
32
+ - id: black
33
+ args: [--target-version=py311]
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Karl Wette
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
16
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ppqs
3
- Version: 2.6.1
3
+ Version: 3.0.0
4
4
  Summary: Python project quick scripts
5
5
  Author-email: Karl Wette <karl.wette@anu.edu.au>
6
6
  License-Expression: MIT
@@ -8,7 +8,9 @@ Project-URL: Homepage, https://github.com/kwwette/ppqs
8
8
  Project-URL: Issues, https://github.com/kwwette/ppqs/issues
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.10
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Topic :: Software Development
13
+ Requires-Python: >=3.11
12
14
  Description-Content-Type: text/markdown
13
15
  License-File: LICENSES/MIT.txt
14
16
  License-File: LICENSES/CC0-1.0.txt
@@ -57,8 +59,11 @@ command errors, the remainder of the script is aborted.
57
59
 
58
60
  Scripts are defined in `pyproject.toml` under the `[tool.ppqs.scripts]`
59
61
  section. Script names may contain only lowercase letters (`[a-z]`) and dashes
60
- (`-`). Scripts may be single or multi-line strings: commands are separated by
61
- newlines, and command arguments are separated by spaces.
62
+ (`-`).
63
+
64
+ Scripts may be single or multi-line strings. Command arguments are separated by
65
+ spaces, but quotes may be used for arguments containing whitespace, similar to
66
+ the Unix shell. In multi-line strings, commands are separated by newlines.
62
67
 
63
68
  ```toml
64
69
  [tool.ppqs.scripts]
@@ -68,7 +73,7 @@ command
68
73
  """
69
74
  build = """
70
75
  command1 -v
71
- command2 -q
76
+ command2 -q 'a string with whitespace'
72
77
  """
73
78
  ```
74
79
 
@@ -86,19 +91,22 @@ clean = [
86
91
  ]
87
92
  ```
88
93
 
89
- If a script contains an ellipsis (`...`) it is replaced with any additional
90
- arguments passed to `ppqs`. For example, the following script:
94
+ If a script argument contains a number inside curly brackets (`{1}`, `{2}`,
95
+ etc.) it is replaced with the corresponding argument passed to `ppqs`. If a
96
+ script contains an ellipsis (`...`) it is replaced with any remaining arguments
97
+ (i.e. not used by a curly-bracket replacement). For example, the following
98
+ script:
91
99
 
92
100
  ```toml
93
101
  [tool.ppqs.scripts]
94
- print-something = "echo ..."
102
+ print-something = "echo {1}, and ..."
95
103
  ```
96
104
 
97
105
  may be run as
98
106
 
99
107
  ```
100
- $ ppqs print-something Hi
101
- Hi
108
+ $ ppqs print-something Hello goodbye again
109
+ Hello, and goodbye again
102
110
  ```
103
111
 
104
112
  `ppqs` can recursively run its own scripts, however it will only run any script
@@ -40,8 +40,11 @@ command errors, the remainder of the script is aborted.
40
40
 
41
41
  Scripts are defined in `pyproject.toml` under the `[tool.ppqs.scripts]`
42
42
  section. Script names may contain only lowercase letters (`[a-z]`) and dashes
43
- (`-`). Scripts may be single or multi-line strings: commands are separated by
44
- newlines, and command arguments are separated by spaces.
43
+ (`-`).
44
+
45
+ Scripts may be single or multi-line strings. Command arguments are separated by
46
+ spaces, but quotes may be used for arguments containing whitespace, similar to
47
+ the Unix shell. In multi-line strings, commands are separated by newlines.
45
48
 
46
49
  ```toml
47
50
  [tool.ppqs.scripts]
@@ -51,7 +54,7 @@ command
51
54
  """
52
55
  build = """
53
56
  command1 -v
54
- command2 -q
57
+ command2 -q 'a string with whitespace'
55
58
  """
56
59
  ```
57
60
 
@@ -69,19 +72,22 @@ clean = [
69
72
  ]
70
73
  ```
71
74
 
72
- If a script contains an ellipsis (`...`) it is replaced with any additional
73
- arguments passed to `ppqs`. For example, the following script:
75
+ If a script argument contains a number inside curly brackets (`{1}`, `{2}`,
76
+ etc.) it is replaced with the corresponding argument passed to `ppqs`. If a
77
+ script contains an ellipsis (`...`) it is replaced with any remaining arguments
78
+ (i.e. not used by a curly-bracket replacement). For example, the following
79
+ script:
74
80
 
75
81
  ```toml
76
82
  [tool.ppqs.scripts]
77
- print-something = "echo ..."
83
+ print-something = "echo {1}, and ..."
78
84
  ```
79
85
 
80
86
  may be run as
81
87
 
82
88
  ```
83
- $ ppqs print-something Hi
84
- Hi
89
+ $ ppqs print-something Hello goodbye again
90
+ Hello, and goodbye again
85
91
  ```
86
92
 
87
93
  `ppqs` can recursively run its own scripts, however it will only run any script
ppqs-3.0.0/REUSE.toml ADDED
@@ -0,0 +1,20 @@
1
+ version = 1
2
+
3
+ [[annotations]]
4
+ path = [
5
+ ".github/**",
6
+ ".gitignore",
7
+ ".pre-commit-config.yaml",
8
+ "README.md",
9
+ "pyproject.toml",
10
+ "requirements-dev.txt",
11
+ ]
12
+ SPDX-FileCopyrightText = "NONE"
13
+ SPDX-License-Identifier = "CC0-1.0"
14
+
15
+ [[annotations]]
16
+ path = [
17
+ "src/**/*.py",
18
+ "test/**/*.py",
19
+ ]
20
+ SPDX-License-Identifier = "MIT"
@@ -1,5 +1,5 @@
1
1
  [build-system]
2
- requires = ["setuptools>=64.0"]
2
+ requires = ["setuptools>=80", "setuptools-scm>=8"]
3
3
  build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
@@ -8,16 +8,21 @@ description = "Python project quick scripts"
8
8
  authors = [
9
9
  { name = "Karl Wette", email = "karl.wette@anu.edu.au" },
10
10
  ]
11
- requires-python = ">=3.10"
11
+ requires-python = ">=3.11"
12
12
  dependencies = [
13
13
  "tomli>=1.1.0; python_version<'3.11'"
14
14
  ]
15
15
  readme = "README.md"
16
16
  license = "MIT"
17
- license-files = ["LICENSES/MIT.txt", "LICENSES/CC0-1.0.txt"]
17
+ license-files = [
18
+ 'LICENSES/MIT.txt',
19
+ 'LICENSES/CC0-1.0.txt',
20
+ ]
18
21
  classifiers = [
19
22
  "Programming Language :: Python :: 3",
20
23
  "Operating System :: OS Independent",
24
+ "Intended Audience :: Developers",
25
+ "Topic :: Software Development",
21
26
  ]
22
27
  dynamic = ["version"]
23
28
 
@@ -28,8 +33,9 @@ Issues = "https://github.com/kwwette/ppqs/issues"
28
33
  [project.scripts]
29
34
  ppqs = "py_proj_quick_scripts:cli"
30
35
 
31
- [tool.setuptools.dynamic]
32
- version = {attr = "py_proj_quick_scripts.__version__"}
36
+ [tool.setuptools_scm]
37
+ scm.git.pre_parse = "fail_on_shallow"
38
+ local_scheme = "node-and-timestamp"
33
39
 
34
40
  [tool.ruff]
35
41
  fix = true
@@ -86,12 +92,28 @@ script = """
86
92
  python -m pytest ...
87
93
  """
88
94
 
95
+ [tool.ppqs.scripts.version]
96
+ description = "Print the current package version"
97
+ script = "python -m setuptools_scm"
98
+
99
+ [tool.ppqs.scripts.tag]
100
+ description = "Tag a release"
101
+ script = [
102
+ ["git", "status"],
103
+ ["git", "diff", "--quiet", "--exit-code"],
104
+ ["ppqs", "lint"],
105
+ ["ppqs", "build"],
106
+ ["ppqs", "test"],
107
+ ["git", "commit", "--allow-empty", "-m", "Version {1}.{2}.{3}"],
108
+ ["git", "tag", "-a", "-m", "Version {1}.{2}.{3}", "v{1}.{2}.{3}"],
109
+ ]
110
+
89
111
  [tool.ppqs.scripts.upload]
90
112
  description = "Upload package"
91
113
  script = [
92
- ["ppqs", "test"],
114
+ ["ppqs", "lint"],
93
115
  ["ppqs", "build"],
94
- ["twine", "upload", ["dist", "*"]],
116
+ ["ppqs", "test"],
95
117
  ["git", "push", "origin"],
96
118
  ["git", "push", "origin", "--tags"],
97
119
  ]
@@ -0,0 +1,8 @@
1
+ build>=1.6.1
2
+ coverage>=7.17.1
3
+ pre-commit>=4.7.0
4
+ pytest-cov>=7.1.0
5
+ pytest>=9.2.0
6
+ setuptools-scm>=8
7
+ setuptools>=80
8
+ twine>=7.0.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ppqs
3
- Version: 2.6.1
3
+ Version: 3.0.0
4
4
  Summary: Python project quick scripts
5
5
  Author-email: Karl Wette <karl.wette@anu.edu.au>
6
6
  License-Expression: MIT
@@ -8,7 +8,9 @@ Project-URL: Homepage, https://github.com/kwwette/ppqs
8
8
  Project-URL: Issues, https://github.com/kwwette/ppqs/issues
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.10
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Topic :: Software Development
13
+ Requires-Python: >=3.11
12
14
  Description-Content-Type: text/markdown
13
15
  License-File: LICENSES/MIT.txt
14
16
  License-File: LICENSES/CC0-1.0.txt
@@ -57,8 +59,11 @@ command errors, the remainder of the script is aborted.
57
59
 
58
60
  Scripts are defined in `pyproject.toml` under the `[tool.ppqs.scripts]`
59
61
  section. Script names may contain only lowercase letters (`[a-z]`) and dashes
60
- (`-`). Scripts may be single or multi-line strings: commands are separated by
61
- newlines, and command arguments are separated by spaces.
62
+ (`-`).
63
+
64
+ Scripts may be single or multi-line strings. Command arguments are separated by
65
+ spaces, but quotes may be used for arguments containing whitespace, similar to
66
+ the Unix shell. In multi-line strings, commands are separated by newlines.
62
67
 
63
68
  ```toml
64
69
  [tool.ppqs.scripts]
@@ -68,7 +73,7 @@ command
68
73
  """
69
74
  build = """
70
75
  command1 -v
71
- command2 -q
76
+ command2 -q 'a string with whitespace'
72
77
  """
73
78
  ```
74
79
 
@@ -86,19 +91,22 @@ clean = [
86
91
  ]
87
92
  ```
88
93
 
89
- If a script contains an ellipsis (`...`) it is replaced with any additional
90
- arguments passed to `ppqs`. For example, the following script:
94
+ If a script argument contains a number inside curly brackets (`{1}`, `{2}`,
95
+ etc.) it is replaced with the corresponding argument passed to `ppqs`. If a
96
+ script contains an ellipsis (`...`) it is replaced with any remaining arguments
97
+ (i.e. not used by a curly-bracket replacement). For example, the following
98
+ script:
91
99
 
92
100
  ```toml
93
101
  [tool.ppqs.scripts]
94
- print-something = "echo ..."
102
+ print-something = "echo {1}, and ..."
95
103
  ```
96
104
 
97
105
  may be run as
98
106
 
99
107
  ```
100
- $ ppqs print-something Hi
101
- Hi
108
+ $ ppqs print-something Hello goodbye again
109
+ Hello, and goodbye again
102
110
  ```
103
111
 
104
112
  `ppqs` can recursively run its own scripts, however it will only run any script
@@ -1,5 +1,13 @@
1
+ .gitignore
2
+ .pre-commit-config.yaml
3
+ LICENSE
1
4
  README.md
5
+ REUSE.toml
2
6
  pyproject.toml
7
+ requirements-dev.txt
8
+ .github/dependabot.yml
9
+ .github/workflows/publish.yml
10
+ .github/workflows/test.yml
3
11
  LICENSES/CC0-1.0.txt
4
12
  LICENSES/MIT.txt
5
13
  src/ppqs.egg-info/PKG-INFO
@@ -7,8 +15,11 @@ src/ppqs.egg-info/SOURCES.txt
7
15
  src/ppqs.egg-info/dependency_links.txt
8
16
  src/ppqs.egg-info/entry_points.txt
9
17
  src/ppqs.egg-info/requires.txt
18
+ src/ppqs.egg-info/scm_file_list.json
19
+ src/ppqs.egg-info/scm_version.json
10
20
  src/ppqs.egg-info/top_level.txt
11
21
  src/py_proj_quick_scripts/__init__.py
22
+ test/__init__.py
12
23
  test/test_cli.py
13
24
  test/test_find_pyproject.py
14
25
  test/test_parse_scripts.py
@@ -0,0 +1,21 @@
1
+ {
2
+ "files": [
3
+ ".github/dependabot.yml",
4
+ ".github/workflows/publish.yml",
5
+ ".github/workflows/test.yml",
6
+ ".gitignore",
7
+ ".pre-commit-config.yaml",
8
+ "LICENSE",
9
+ "LICENSES/CC0-1.0.txt",
10
+ "LICENSES/MIT.txt",
11
+ "README.md",
12
+ "REUSE.toml",
13
+ "pyproject.toml",
14
+ "requirements-dev.txt",
15
+ "src/py_proj_quick_scripts/__init__.py",
16
+ "test/__init__.py",
17
+ "test/test_cli.py",
18
+ "test/test_find_pyproject.py",
19
+ "test/test_parse_scripts.py"
20
+ ]
21
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "3.0.0",
3
+ "distance": 0,
4
+ "node": "g7aafe7aeb426efa3523c442b51493c6b15747723",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-11-08"
8
+ }
@@ -7,19 +7,21 @@
7
7
  import glob
8
8
  import os
9
9
  import re
10
+ import shlex
10
11
  import shutil
11
12
  import subprocess
12
13
  import sys
13
14
  import textwrap
15
+ import tomllib
16
+ from importlib.metadata import PackageNotFoundError, version
14
17
  from pathlib import Path
15
18
 
16
- if sys.version_info >= (3, 11): # pragma: no cover
17
- import tomllib
18
- else: # pragma: no cover
19
- import tomli as tomllib
20
-
21
19
  __author__ = "Karl Wette"
22
- __version__ = "2.6.1"
20
+
21
+ try:
22
+ __version__ = version("ppqs")
23
+ except PackageNotFoundError: # pragma: no cover
24
+ __version__ = "0.0.0.dev0"
23
25
 
24
26
 
25
27
  class MissingPyProjectError(Exception):
@@ -153,7 +155,7 @@ def parse_scripts(pyproject_path):
153
155
 
154
156
  # Parse a script as a string
155
157
  script_commands = [
156
- line.split()
158
+ shlex.split(line)
157
159
  for line in script_commands_toml.splitlines()
158
160
  if len(line.strip()) > 0
159
161
  ]
@@ -241,22 +243,78 @@ def run_script(pyproject_path, scripts, script_name, argv, cwd, has_been_run):
241
243
  # Get script
242
244
  script = scripts[script_name]
243
245
 
244
- # Check that script was correctly passed arguments
245
- script_takes_argv = any("..." in command for command in script["commands"])
246
- if not script_takes_argv and len(argv) > 0:
247
- msg = "script '{}' does not take arguments ('{}')".format(
248
- script_name, "', '".join(argv)
246
+ # First pass of commands
247
+ argv_remaining = argv.copy()
248
+ commands = script["commands"]
249
+ cmds = []
250
+ for command in commands:
251
+ cmd = []
252
+ for arg in command:
253
+
254
+ # Convert to string
255
+ arg_type = type(arg)
256
+ arg_str = str(arg)
257
+
258
+ # Replace positional arguments from command
259
+ for arg_match in re.finditer(r"{(\d+)}", arg_str):
260
+ arg_i = int(arg_match.group(1))
261
+ if arg_i < 1:
262
+ msg = (
263
+ "script '{}' arguments must be {{1}}, {{2}}, etc.,"
264
+ + " instead found {{{}}}"
265
+ ).format(script_name, arg_i)
266
+ raise InvalidScriptCallError(pyproject_path, msg)
267
+ if arg_i > len(argv):
268
+ msg = (
269
+ "script '{}' takes at least {} argument(s), "
270
+ + "but only {} argument(s) were given"
271
+ ).format(script_name, arg_i, len(argv))
272
+ raise InvalidScriptCallError(pyproject_path, msg)
273
+ arg_str = arg_str.replace(arg_match.group(0), argv[arg_i - 1])
274
+ argv_remaining[arg_i - 1] = None
275
+
276
+ cmd.append(arg_type(arg_str))
277
+
278
+ cmds.append(cmd)
279
+
280
+ # Second pass of command
281
+ commands = cmds
282
+ cmds = []
283
+ for command in commands:
284
+ cmd = []
285
+ for arg in command:
286
+
287
+ # Replace "..." with remaining command-line arguments
288
+ if arg == "...":
289
+ cmd.extend([argr for argr in argv_remaining if argr is not None])
290
+ argv_remaining = [None] * len(argv_remaining)
291
+
292
+ continue
293
+
294
+ cmd.append(arg)
295
+
296
+ cmds.append(cmd)
297
+
298
+ # Check for any remaining arguments
299
+ argv_used = sum(argr is None for argr in argv_remaining)
300
+ if argv_used != len(argv):
301
+ msg = "script '{}' takes {} argument(s), but {} argument(s) were given".format(
302
+ script_name, argv_used, len(argv)
249
303
  )
250
304
  raise InvalidScriptCallError(pyproject_path, msg)
251
305
 
252
- for command in script["commands"]:
253
- cmd = []
306
+ # Execute commands
307
+ for command in cmds:
254
308
 
309
+ # Final pass of commands
310
+ cmd = []
255
311
  for arg in command:
312
+
313
+ # Only process path arguments
256
314
  if isinstance(arg, Path):
257
- if "*" in arg.parts[-1]:
258
315
 
259
- # Expand wildcards in last path element
316
+ # Expand wildcards in last path element
317
+ if "*" in arg.parts[-1]:
260
318
  cmd.extend(
261
319
  sorted(glob.glob(str(arg), root_dir=cwd, recursive=False))
262
320
  )
@@ -264,13 +322,9 @@ def run_script(pyproject_path, scripts, script_name, argv, cwd, has_been_run):
264
322
  else:
265
323
  cmd.append(str(arg))
266
324
 
267
- elif arg == "...":
268
-
269
- # Replace "..." in command with arguments
270
- cmd.extend(argv)
325
+ continue
271
326
 
272
- else:
273
- cmd.append(arg)
327
+ cmd.append(arg)
274
328
 
275
329
  if cmd[0] == "ppqs":
276
330
 
@@ -0,0 +1,27 @@
1
+ # SPDX-FileCopyrightText: 2025 Karl Wette
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """Utility functions for tests."""
6
+
7
+ import os
8
+ import textwrap
9
+ from contextlib import contextmanager
10
+ from pathlib import Path
11
+
12
+
13
+ def write_file(path, contents):
14
+ """Write `contents` to a text file `path`."""
15
+ path.write_text(textwrap.dedent(contents).strip())
16
+
17
+
18
+ @contextmanager
19
+ def in_dir(path):
20
+ """Temporarily change working directory to `path`, creating as needed."""
21
+ path.mkdir(parents=True, exist_ok=True)
22
+ cwd = Path.cwd()
23
+ os.chdir(path)
24
+ try:
25
+ yield path
26
+ finally:
27
+ os.chdir(cwd)
@@ -39,13 +39,20 @@ def pyproject_path(tmp_path):
39
39
  ["python", "-c", "import sys; print(*sys.argv[1:])", ["subdir", "*.txt"]],
40
40
  ]
41
41
  [tool.ppqs.scripts.greeting]
42
- script = "echo Hello ..."
42
+ script = "echo Hello {1}!"
43
+ [tool.ppqs.scripts.zero-greeting]
44
+ script = "echo Hello {0}!"
43
45
  [tool.ppqs.scripts.farewell]
44
46
  script = '''
45
- ppqs greeting friend!
46
- ppqs greeting comrade!
47
+ ppqs greeting friend
48
+ ppqs greeting comrade
47
49
  echo Goodbye
48
50
  '''
51
+ [tool.ppqs.scripts.makefile]
52
+ script = [
53
+ ["python", "-c", "from pathlib import Path; Path('{1}/{2}').write_text('{3}')"],
54
+ ["cat", ["{1}", "*"]],
55
+ ]
49
56
  """
50
57
 
51
58
  write_file(pyproject_path, pyproject_toml)
@@ -111,6 +118,25 @@ def test_echo_wildcard(pyproject_path, capfd):
111
118
  assert captured.err == ""
112
119
 
113
120
 
121
+ def test_args(pyproject_path, capfd):
122
+ """Test argument parsing."""
123
+
124
+ with in_dir(pyproject_path.parent):
125
+ cli("greeting", "friend")
126
+ captured = capfd.readouterr()
127
+ assert captured.out == "Hello friend!\n"
128
+ assert captured.err == ""
129
+
130
+ with pytest.raises(InvalidScriptError):
131
+ cli("greeting")
132
+
133
+ with pytest.raises(InvalidScriptError):
134
+ cli("greeting", "magnificent", "friend")
135
+
136
+ with pytest.raises(InvalidScriptError):
137
+ cli("zero-greeting", "nothing")
138
+
139
+
114
140
  def test_recursion(pyproject_path, capfd):
115
141
  """Test recursive script running."""
116
142
 
@@ -125,3 +151,16 @@ def test_recursion(pyproject_path, capfd):
125
151
 
126
152
  with pytest.raises(InvalidScriptError):
127
153
  cli("no-script")
154
+
155
+
156
+ def test_makefile(pyproject_path, capfd, tmp_path):
157
+ """Test making a file and then finding it with wildcards."""
158
+
159
+ with in_dir(pyproject_path.parent):
160
+ makefile_path = tmp_path / "makefile"
161
+ makefile_path.mkdir(parents=True, exist_ok=True)
162
+
163
+ cli("makefile", str(makefile_path), "test.txt", "Good morning!")
164
+ captured = capfd.readouterr()
165
+ assert captured.out == "Good morning!"
166
+ assert captured.err == ""
File without changes
File without changes
File without changes
File without changes
File without changes