Skip to content

Commit ede02cd

Browse files
committed
CLI. Added style command.
1 parent 798037a commit ede02cd

File tree

8 files changed

+48
-1
lines changed

8 files changed

+48
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* ++ Add 'ma' alias for 'makeapp' command.
77
* ++ Added virtual environment creation on project rollout.
88
* ++ CLI. Add 'publish' command.
9+
* ++ CLI. Added 'style' command.
910
* ++ CLI. Added 'tools' command.
1011
* ++ CLI. Added 'up' command.
1112
* ++ CLI. Descriptions passed to 'change' command all go into a commit messages.

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ https://github.com/idlesign/makeapp
1919
* Easily add entries to your changelog.
2020
* Publish your application to remotes (VCS, PyPI) with a single command.
2121
* Easily bootstrap your development environment.
22+
* Run code styling/linting.
2223

2324
## Application scaffolding
2425

@@ -85,6 +86,14 @@ ma tools
8586
ma up
8687
```
8788

89+
## Code style
90+
91+
Apply code style with `style` command:
92+
93+
``` bash
94+
ma style
95+
```
96+
8897
## Documentation
8998

9099
https://makeapp.readthedocs.io/

docs/040_development.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,11 @@ to drop the old one altogether and create a new one. Use the following command:
3030
ma up -r
3131
# or ma up --reset
3232
```
33+
34+
## Style code
35+
36+
To style/lint your code use the following command:
37+
38+
```bash
39+
ma style
40+
```

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Easily add entries to your changelog.
1515
* Publish your application to remotes (VCS, PyPI) with single command.
1616
* Easily bootstrap your development environment.
17+
* Run code styling/linting.
1718

1819

1920
## Requirements

ruff.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
target-version = "py310"
22
line-length = 120
3+
exclude = [
4+
"**/*.toml",
5+
]
36

47
[format]
58
quote-style = "single"

src/makeapp/apptools.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .helpers.files import FileHelper
99
from .helpers.vcs import VcsHelper
1010
from .helpers.venvs import VenvHelper
11-
from .utils import chdir, configure_logging, Uv
11+
from .utils import chdir, configure_logging, Uv, Ruff
1212

1313
LOG = logging.getLogger(__name__)
1414

@@ -506,6 +506,10 @@ def publish(self):
506506
self.vcs.push()
507507
DistHelper.upload()
508508

509+
def style(self):
510+
LOG.info('Styling ...')
511+
Ruff.check()
512+
509513
def venv_init(self, *, reset: bool = False, register_tool: bool = False):
510514
self.venv.initialize(reset=reset)
511515

src/makeapp/cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,15 @@ def tools(debug, upgrade):
225225
click.secho('Done', fg='green')
226226

227227

228+
@entry_point.command()
229+
@option_debug
230+
def style(debug):
231+
"""Apply code style."""
232+
project = Project(log_level=logging.DEBUG if debug else logging.INFO)
233+
project.style()
234+
click.secho('Done', fg='green')
235+
236+
228237
def main():
229238
try:
230239
entry_point(obj={})

src/makeapp/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,18 @@ def run_command(command: str, *, err_msg: str = '', env: dict | None = None, cap
151151
return data
152152

153153

154+
class Ruff:
155+
"""Ruff wrapper."""
156+
157+
@classmethod
158+
def _run(cls, cmd: str) -> list[str]:
159+
return run_command(f'ruff {cmd}', capture=False)
160+
161+
@classmethod
162+
def check(cls, fix: bool = True) -> list[str]:
163+
return cls._run(f'check{" --fix" if fix else ""}')
164+
165+
154166
class Uv:
155167
"""Uv wrapper."""
156168

0 commit comments

Comments
 (0)