Skip to content

Commit

Permalink
Restructure scripting project and add skeleton project.
Browse files Browse the repository at this point in the history
  • Loading branch information
stevewgr committed Jan 24, 2023
1 parent 226382d commit 4befee9
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 10 deletions.
2 changes: 1 addition & 1 deletion script/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ venv/
build/
ko.egg-info/
__pycache__/
*.pyc
*.pyc
2 changes: 1 addition & 1 deletion script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pip install .
ko --help

# or
python kocmd/ko.py --help
python ko/main.py --help

# add `--editable` if you want to run the shorter `ko` command whilst editing the scripts:
pip install --editable .
Expand Down
3 changes: 3 additions & 0 deletions script/ko/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

def util_entry(**args):
print(f"Using clang-format to format code in the following directory: {args['dir']}")
4 changes: 4 additions & 0 deletions script/ko/build/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .project import build_project

def build_entry(**args):
build_project(**args)
4 changes: 4 additions & 0 deletions script/ko/build/project.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

def build_project(**args):
print(f"Building {args['config']} projects (cores: {args['cores']}): {list(args['project'])}")
print(args)
3 changes: 3 additions & 0 deletions script/ko/db/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

def db_entry(**args):
print(f"Database action: {args['action']}")
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 9 additions & 7 deletions script/kocmd/ko.py → script/ko/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
import click

from ko.build import build_entry
from ko.db import db_entry
from ko.util import util_entry

class CaseInsensitiveChoice(click.Choice):
def convert(self, value, param, ctx):
Expand All @@ -17,20 +20,19 @@ def cli():
@click.option('--project', '-p', type=CaseInsensitiveChoice(['all', 'game', 'server', 'tool']),
default=['all'], multiple=True, help='Multiple projects to build')
@click.option('--cores', '-j', type=click.INT, default=os.cpu_count(), help='CPU cores count for building')
def build(project, config, cores):
print(f"Building {config} projects (cores: {cores}): {list(project)}")

def build(**args):
build_entry(**args)

@cli.command()
@click.option('--action', '-a', type=CaseInsensitiveChoice(['import', 'export']), required=True, help='Import or export database')
def db(action):
print(f"Database action: {action}")
def db(**args):
db_entry(**args)


@cli.command()
@click.option('--dir', '-d', type=click.STRING, help='Path to a directory to apply code formatting')
def format(dir):
print(f"Using clang-format to format code in the following directory: {dir}")
def format(**args):
util_entry(**args)


if __name__ == '__main__':
Expand Down
3 changes: 3 additions & 0 deletions script/ko/util/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

def util_entry(**args):
print(f"Using clang-format to format code in the following directory: {args['dir']}")
File renamed without changes.
2 changes: 1 addition & 1 deletion script/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
install_requires=['click'],
entry_points={
'console_scripts': [
'ko = kocmd.ko:cli',
'ko = ko.main:cli',
],
},
)

0 comments on commit 4befee9

Please sign in to comment.