pyqwe 0.1.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.
pyqwe-0.1.0/.gitignore ADDED
@@ -0,0 +1,68 @@
1
+ .idea/
2
+
3
+ # Byte-compiled / optimized / DLL files
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+
8
+ # C extensions
9
+ *.so
10
+
11
+ # Distribution / packaging
12
+ .Python
13
+ build/
14
+ develop-eggs/
15
+ dist/
16
+ downloads/
17
+ eggs/
18
+ .eggs/
19
+ lib/
20
+ lib64/
21
+ parts/
22
+ sdist/
23
+ var/
24
+ wheels/
25
+ share/python-wheels/
26
+ *.egg-info/
27
+ .installed.cfg
28
+ *.egg
29
+ MANIFEST
30
+
31
+ # Installer logs
32
+ pip-log.txt
33
+ pip-delete-this-directory.txt
34
+
35
+ # Unit test / coverage reports
36
+ htmlcov/
37
+ .tox/
38
+ .nox/
39
+ .coverage
40
+ .coverage.*
41
+ .cache
42
+ nosetests.xml
43
+ coverage.xml
44
+ *.cover
45
+ *.py,cover
46
+ .hypothesis/
47
+ .pytest_cache/
48
+ cover/
49
+
50
+ # Translations
51
+ *.mo
52
+ *.pot
53
+
54
+ # pyenv
55
+ # For a library or package, you might want to ignore these files since the code is
56
+ # intended to run in multiple environments; otherwise, check them in:
57
+ # .python-version
58
+
59
+ # pipenv
60
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
61
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
62
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
63
+ # install all needed dependencies.
64
+ #Pipfile.lock
65
+
66
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow
67
+ __pypackages__/
68
+ /venv/
pyqwe-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 David Carmichael
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
pyqwe-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyqwe
3
+ Version: 0.1.0
4
+ Summary: Run commands set in the pyproject.toml file
5
+ Author-email: David Carmichael <david@uilix.com>
6
+ Requires-Python: >=3.11
7
+ Description-Content-Type: text/markdown
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Project-URL: Source, https://github.com/CheeseCake87/qwe
10
+
11
+ # 🏎️💨 pyqwe
12
+
13
+ The Quick Work Environment for Python.
14
+
15
+ Run commands quickly from the pyproject.toml file.
16
+
17
+ `pip install pyqwe`
18
+
19
+ ## Usage
20
+
21
+ Add commands to the pyproject.toml file.
22
+
23
+ ```toml
24
+ [tool.pyqwe]
25
+ flask = "flask_app:run"
26
+ say_hello = "*cmd:echo Hello World"
27
+ ```
28
+
29
+ ### Python commands:
30
+
31
+ For Python, the commands are structured like (package:module):function
32
+
33
+ #### Package example:
34
+
35
+ ```text
36
+ project/
37
+ flask_app/
38
+ __init__.py
39
+ ```
40
+
41
+ The following command will run the function
42
+ `run` from the `__init__.py` file in the `flask_app` package.
43
+
44
+ `flask = "flask_app:run"`
45
+
46
+ #### Module example:
47
+
48
+ ```text
49
+ project/
50
+ app.py
51
+ ```
52
+
53
+ The following command will run the function
54
+ `run` from the `app.py` file.
55
+
56
+ `flask = "app:run"`
57
+
58
+ Now run the qwe command:
59
+
60
+ `qwe flask`
61
+
62
+ and this will start the Flask app.
63
+
64
+ ### CMD labeled commands:
65
+
66
+ And command that is labeled with `*cmd` will be ran using subprocess.
67
+
68
+ `say_hello = "*cmd:echo Hello World"`
69
+
70
+ Now run the qwe command:
71
+
72
+ `qwe say_hello`
73
+
74
+ and this will print `Hello World`.
75
+
76
+ #### Run as shell
77
+
78
+ To run the command as a subprocess shell command, add the `shell` key to the command.
79
+
80
+ `say_hello = "*cmd-shell:echo Hello World"`
81
+
82
+ ### Other commands
83
+
84
+ `-h` or `--help` will display all the commands set in the pyproject.toml file.
85
+ `__version__` will display the version of qwe.
86
+
pyqwe-0.1.0/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # 🏎️💨 pyqwe
2
+
3
+ The Quick Work Environment for Python.
4
+
5
+ Run commands quickly from the pyproject.toml file.
6
+
7
+ `pip install pyqwe`
8
+
9
+ ## Usage
10
+
11
+ Add commands to the pyproject.toml file.
12
+
13
+ ```toml
14
+ [tool.pyqwe]
15
+ flask = "flask_app:run"
16
+ say_hello = "*cmd:echo Hello World"
17
+ ```
18
+
19
+ ### Python commands:
20
+
21
+ For Python, the commands are structured like (package:module):function
22
+
23
+ #### Package example:
24
+
25
+ ```text
26
+ project/
27
+ flask_app/
28
+ __init__.py
29
+ ```
30
+
31
+ The following command will run the function
32
+ `run` from the `__init__.py` file in the `flask_app` package.
33
+
34
+ `flask = "flask_app:run"`
35
+
36
+ #### Module example:
37
+
38
+ ```text
39
+ project/
40
+ app.py
41
+ ```
42
+
43
+ The following command will run the function
44
+ `run` from the `app.py` file.
45
+
46
+ `flask = "app:run"`
47
+
48
+ Now run the qwe command:
49
+
50
+ `qwe flask`
51
+
52
+ and this will start the Flask app.
53
+
54
+ ### CMD labeled commands:
55
+
56
+ And command that is labeled with `*cmd` will be ran using subprocess.
57
+
58
+ `say_hello = "*cmd:echo Hello World"`
59
+
60
+ Now run the qwe command:
61
+
62
+ `qwe say_hello`
63
+
64
+ and this will print `Hello World`.
65
+
66
+ #### Run as shell
67
+
68
+ To run the command as a subprocess shell command, add the `shell` key to the command.
69
+
70
+ `say_hello = "*cmd-shell:echo Hello World"`
71
+
72
+ ### Other commands
73
+
74
+ `-h` or `--help` will display all the commands set in the pyproject.toml file.
75
+ `__version__` will display the version of qwe.
@@ -0,0 +1,19 @@
1
+ [build-system]
2
+ requires = ["flit_core >=3.2,<4"]
3
+ build-backend = "flit_core.buildapi"
4
+
5
+ [project]
6
+ name = "pyqwe"
7
+ description = 'Run commands set in the pyproject.toml file'
8
+ authors = [{ name = "David Carmichael", email = "david@uilix.com" }]
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = { file = "LICENSE" }
12
+ classifiers = ["License :: OSI Approved :: MIT License"]
13
+ dynamic = ["version"]
14
+
15
+ [project.scripts]
16
+ pyqwe = "pyqwe:main"
17
+
18
+ [project.urls]
19
+ Source = "https://github.com/CheeseCake87/qwe"
@@ -0,0 +1,105 @@
1
+ import argparse
2
+ import importlib
3
+ import importlib.util
4
+ import shlex
5
+ import subprocess
6
+ import sys
7
+ import tomllib
8
+ from pathlib import Path
9
+
10
+ __version__ = "0.1.0"
11
+
12
+
13
+ class NotAPythonPackageError(Exception):
14
+ pass
15
+
16
+
17
+ def _no_traceback_eh(exc_type, exc_val, traceback):
18
+ pass
19
+
20
+
21
+ _cwd = Path().cwd()
22
+ _pyproject_file = _cwd / "pyproject.toml"
23
+
24
+ if not _pyproject_file.exists():
25
+ raise FileNotFoundError("pyproject.toml not found")
26
+
27
+ _pyproject = tomllib.loads(_pyproject_file.read_text())
28
+ _qwe = _pyproject.get("tool", {}).get("pyqwe")
29
+
30
+ if not _qwe or not isinstance(_qwe, dict):
31
+ raise ValueError("tool.qwe not found in pyproject.toml")
32
+
33
+
34
+ def _split_runner(runner_: str) -> tuple:
35
+ r = runner_.split(":")
36
+ sr = r[0] # start or runner
37
+ er = r[1].lower() # end of runner
38
+ return sr, er
39
+
40
+
41
+ def _path_to_module(path: Path) -> str:
42
+ file = path.stem
43
+ path = path.parent
44
+ return f"{path.name}.{file}"
45
+
46
+
47
+ def _run(sr: str, er: str):
48
+ try:
49
+
50
+ if "*" in sr:
51
+ if "cmd" in sr:
52
+ if "shell" in sr:
53
+ subprocess.run(er, shell=True)
54
+ else:
55
+ subprocess.run(shlex.split(er))
56
+
57
+ else:
58
+ package = _cwd / sr
59
+ init_module = package / "__init__.py"
60
+
61
+ if not init_module.exists():
62
+ module = _cwd / f"{sr}.py"
63
+
64
+ if not module.exists():
65
+ raise FileNotFoundError(f"File {module} not found")
66
+
67
+ sys.path.append(str(_cwd))
68
+ module = importlib.import_module(sr)
69
+ getattr(module, er)()
70
+
71
+ else:
72
+ sys.path.append(str(package))
73
+ module = importlib.import_module("__init__")
74
+ getattr(module, er)()
75
+
76
+ except KeyboardInterrupt:
77
+ if sys.excepthook is sys.__excepthook__:
78
+ sys.excepthook = _no_traceback_eh
79
+ raise
80
+
81
+
82
+ def main():
83
+ parser = argparse.ArgumentParser(
84
+ prog="qwe",
85
+ description="Run commands set in the pyproject.toml file",
86
+ )
87
+
88
+ parser.add_argument(
89
+ "--version",
90
+ action="version",
91
+ version=f"qwe {__version__}"
92
+ )
93
+
94
+ subparser = parser.add_subparsers()
95
+
96
+ for entry, runner in _qwe.items():
97
+ _ = subparser.add_parser(entry, help=runner)
98
+ _.set_defaults(entry=entry, runner=runner)
99
+
100
+ args = parser.parse_args()
101
+ _run(*_split_runner(args.runner))
102
+
103
+
104
+ if __name__ == "__main__":
105
+ main()