Name | ninjar JSON |
Version |
1.0.2
JSON |
| download |
home_page | None |
Summary | A small ninjar build script generator framework. |
upload_time | 2024-08-16 14:30:15 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11 |
license | The Clear BSD License Copyright (c) 2024, XiangYang <hinata.hoshino@foxmail.com> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of [Owner Organization] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
keywords |
ninjar
generator
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
Ninjar
======
A small ninjar build script generator framework.
```python
import ninjar
from typing import List, Dict
class SimpleStage(ninjar.ninja.Stage):
def __init__(self, ninja: ninjar.NinjaGenerator, name: str) -> None:
super().__init__(ninja, name)
self._add_option('example')
self._add_option('command')
def inherit(self) -> "SimpleStage":
"""
inherit this object
"""
new_obj = SimpleStage(self.ninja, self.name)
new_obj.cmd = self.cmd .copy()
return new_obj
def input_type(self) -> List[str]:
"""
input: `any`
"""
return [':any']
def generate_rule(self) -> None:
"""
Generate the ninja rule statement
"""
cmd_str = self._get_command()
self.ninja.add_rule(self.name, cmd_str, 'CC: $in', '$in.d')
def generate_build(self, input: List[str]) -> str:
"""
Generate the ninja build statement and return the output file
"""
# dot't forget need check the len(input) in your project
inp_file = input[0]
out_file = f'build/{inp_file}.out'
self.ninja.add_build(self.name, out_file, input)
return out_file
@ninjar.action(default=True)
def ninja(opts: Dict[str, str], args: Dict[str, str]):
"""
Generate the build.ninja file
"""
# At least one action, called ninja is required.
# The `action` is a function,
# `py build.py -t action_name` will execute the action `action_name`
# This action is the default one
# `py build.py` will execute this action
with ninjar.NinjaGenerator() as ninja:
# let's create a stage
stage_1 = SimpleStage(ninja, 'simple')
# the unit stage will return the input
stage_unit = ninjar.UnitStage(ninja, 'unit')
# input files, now it's `*.py`
inp_file = ninjar.select('./*.py')
# and then, apply the `stage_1` to `inp_file`
# assume the `*.py` -> [['build.py']]
# see the `generate_build` method in the `SimpleStage`
# so the result, the `mid_file`, = [['build.py.out']]
#
# inp_file([['build.py']]) -- stage_1 --> build.py.out
#
mid_file = inp_file.apply(stage_1)
# `apply` method can apply more than one stage for the same inputs
twice_files = mid_file.apply(stage_1, stage_unit)
# the result is [['build.py.out.out'], ['build.py.out']]
#
# mid_file([['build.py.out']]) +- stage_1 --> build.py.out.out
# +- stage_unit --> build.py.out
#
# the unit stage return the first input file and do nothing.
# let's fold the output
fold_file = twice_files.fold()
# now the result is [['build.py.out', 'build.py.out']]
result = fold_file.collect_files()
# we can use `colorful_print` to print a colorful output
ninjar.colorful_print(ninjar.Color.Cyan, f'result = `{result}`')
# let's generate `build.ninja`
# build.py -- stage_1 --> build.py.out +- stage_1 --> build.py.out.out
# +- unit --> build.py.out
#
ninja.add_defaults(result)
@ninjar.action()
def not_default(opts: Dict[str, str], args: Dict[str, str]):
"""
This is not a default action, run it `py build.py -t not_default`
"""
print('hello, action `not_default`')
@ninjar.action(['ninja'])
def deps_other(opts: Dict[str, str], args: Dict[str, str]):
"""
An action dependent on `ninja`, run it `py build.py -t deps_other`
"""
print('hello, action `deps_other`')
if __name__ == '__main__':
# try the following commands
# run the default actions
# py build.py
# run specific actions
# py build.py -t not_default
# py build.py -t deps_other
# run the build script
ninjar.BuildScript(__import__(__name__)).run()
```
Raw data
{
"_id": null,
"home_page": null,
"name": "ninjar",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": null,
"keywords": "ninjar generator",
"author": null,
"author_email": "XiangYang <hinata.hoshino@foxmail.com>",
"download_url": "https://files.pythonhosted.org/packages/b9/e7/9c6b7ac68dbe17d1fcb28f5ecdb6790e966760bc6ee300a2f48bc312fc7b/ninjar-1.0.2.tar.gz",
"platform": null,
"description": "Ninjar\n======\n\nA small ninjar build script generator framework.\n\n```python\nimport ninjar\nfrom typing import List, Dict\n\n\nclass SimpleStage(ninjar.ninja.Stage):\n def __init__(self, ninja: ninjar.NinjaGenerator, name: str) -> None:\n super().__init__(ninja, name)\n\n self._add_option('example')\n self._add_option('command')\n\n def inherit(self) -> \"SimpleStage\":\n \"\"\"\n inherit this object\n \"\"\"\n new_obj = SimpleStage(self.ninja, self.name)\n new_obj.cmd = self.cmd .copy()\n return new_obj\n\n def input_type(self) -> List[str]:\n \"\"\"\n input: `any`\n \"\"\"\n return [':any']\n\n def generate_rule(self) -> None:\n \"\"\"\n Generate the ninja rule statement\n \"\"\"\n cmd_str = self._get_command()\n self.ninja.add_rule(self.name, cmd_str, 'CC: $in', '$in.d')\n\n def generate_build(self, input: List[str]) -> str:\n \"\"\"\n Generate the ninja build statement and return the output file\n \"\"\"\n # dot't forget need check the len(input) in your project\n inp_file = input[0]\n out_file = f'build/{inp_file}.out'\n\n self.ninja.add_build(self.name, out_file, input)\n\n return out_file\n\n\n@ninjar.action(default=True)\ndef ninja(opts: Dict[str, str], args: Dict[str, str]):\n \"\"\"\n Generate the build.ninja file\n \"\"\"\n # At least one action, called ninja is required.\n # The `action` is a function,\n # `py build.py -t action_name` will execute the action `action_name`\n\n # This action is the default one\n # `py build.py` will execute this action\n\n with ninjar.NinjaGenerator() as ninja:\n # let's create a stage\n stage_1 = SimpleStage(ninja, 'simple')\n\n # the unit stage will return the input\n stage_unit = ninjar.UnitStage(ninja, 'unit')\n\n # input files, now it's `*.py`\n inp_file = ninjar.select('./*.py')\n\n # and then, apply the `stage_1` to `inp_file`\n # assume the `*.py` -> [['build.py']]\n # see the `generate_build` method in the `SimpleStage`\n # so the result, the `mid_file`, = [['build.py.out']]\n #\n # inp_file([['build.py']]) -- stage_1 --> build.py.out\n #\n mid_file = inp_file.apply(stage_1)\n\n # `apply` method can apply more than one stage for the same inputs\n twice_files = mid_file.apply(stage_1, stage_unit)\n\n # the result is [['build.py.out.out'], ['build.py.out']]\n #\n # mid_file([['build.py.out']]) +- stage_1 --> build.py.out.out\n # +- stage_unit --> build.py.out\n #\n # the unit stage return the first input file and do nothing.\n # let's fold the output\n fold_file = twice_files.fold()\n\n # now the result is [['build.py.out', 'build.py.out']]\n result = fold_file.collect_files()\n\n # we can use `colorful_print` to print a colorful output\n ninjar.colorful_print(ninjar.Color.Cyan, f'result = `{result}`')\n\n # let's generate `build.ninja`\n # build.py -- stage_1 --> build.py.out +- stage_1 --> build.py.out.out\n # +- unit --> build.py.out\n #\n ninja.add_defaults(result)\n\n\n@ninjar.action()\ndef not_default(opts: Dict[str, str], args: Dict[str, str]):\n \"\"\"\n This is not a default action, run it `py build.py -t not_default`\n \"\"\"\n print('hello, action `not_default`')\n\n\n@ninjar.action(['ninja'])\ndef deps_other(opts: Dict[str, str], args: Dict[str, str]):\n \"\"\"\n An action dependent on `ninja`, run it `py build.py -t deps_other`\n \"\"\"\n print('hello, action `deps_other`')\n\n\nif __name__ == '__main__':\n # try the following commands\n\n # run the default actions\n # py build.py\n\n # run specific actions\n # py build.py -t not_default\n # py build.py -t deps_other\n\n # run the build script\n ninjar.BuildScript(__import__(__name__)).run()\n\n```\n",
"bugtrack_url": null,
"license": "The Clear BSD License Copyright (c) 2024, XiangYang <hinata.hoshino@foxmail.com> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of [Owner Organization] nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
"summary": "A small ninjar build script generator framework.",
"version": "1.0.2",
"project_urls": {
"Repository": "https://github.com/XiangYyang/ninjar.git"
},
"split_keywords": [
"ninjar",
"generator"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5cc318c80458e6162bd2e6445b45fddb7c4613ef3a6e1eff722c92cb3588595a",
"md5": "6dbd8c6985943c7ba120f573e1d4693b",
"sha256": "aabb36241394f1ba94708a7f71acdc53c8acb2c91106ddd0b4a91f8f9f8c4d86"
},
"downloads": -1,
"filename": "ninjar-1.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6dbd8c6985943c7ba120f573e1d4693b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 17364,
"upload_time": "2024-08-16T14:30:13",
"upload_time_iso_8601": "2024-08-16T14:30:13.799190Z",
"url": "https://files.pythonhosted.org/packages/5c/c3/18c80458e6162bd2e6445b45fddb7c4613ef3a6e1eff722c92cb3588595a/ninjar-1.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b9e79c6b7ac68dbe17d1fcb28f5ecdb6790e966760bc6ee300a2f48bc312fc7b",
"md5": "b76023c4cac1c165feeda392007a17f0",
"sha256": "9e9df50bb9a51a7898fcf5d55b82801ab0b7e74c60248b8b9155201f7370a522"
},
"downloads": -1,
"filename": "ninjar-1.0.2.tar.gz",
"has_sig": false,
"md5_digest": "b76023c4cac1c165feeda392007a17f0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 14388,
"upload_time": "2024-08-16T14:30:15",
"upload_time_iso_8601": "2024-08-16T14:30:15.357013Z",
"url": "https://files.pythonhosted.org/packages/b9/e7/9c6b7ac68dbe17d1fcb28f5ecdb6790e966760bc6ee300a2f48bc312fc7b/ninjar-1.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-16 14:30:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "XiangYyang",
"github_project": "ninjar",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "ninjar"
}