From b328cf215df564c395a2aaad7e1165ae133b4ec7 Mon Sep 17 00:00:00 2001 From: Dexoron Date: Wed, 11 Feb 2026 18:50:32 +0800 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D1=8C=D0=BD=D1=83=D1=8E?= =?UTF-8?q?=20=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D1=83=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=B0=20=D1=81=20=D0=BE?= =?UTF-8?q?=D1=81=D0=BD=D0=BE=D0=B2=D0=BD=D1=8B=D0=BC=D0=B8=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=B0=D0=BC=D0=B8=20=D0=B8=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=84=D0=B8=D0=B3=D1=83=D1=80=D0=B0=D1=86=D0=B8=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 7 +++++++ .python-version | 1 + .vscode/settings.json | 3 +++ README.md | 0 pyproject.toml | 17 +++++++++++++++++ src/__init__.py | 0 src/dcr/__init__.py | 0 src/dcr/cli/__init__.py | 13 +++++++++++++ src/dcr/cli/build.py | 34 ++++++++++++++++++++++++++++++++++ src/dcr/cli/help.py | 3 +++ src/dcr/cli/init.py | 32 ++++++++++++++++++++++++++++++++ src/dcr/cli/new.py | 34 ++++++++++++++++++++++++++++++++++ src/dcr/cli/run.py | 30 ++++++++++++++++++++++++++++++ src/dcr/config.py | 1 + src/dcr/main.py | 25 +++++++++++++++++++++++++ src/dcr/utils/__init__.py | 0 src/test/__init__.py | 0 uv.lock | 8 ++++++++ 18 files changed, 208 insertions(+) create mode 100644 .gitignore create mode 100644 .python-version create mode 100644 .vscode/settings.json create mode 100644 README.md create mode 100644 pyproject.toml create mode 100644 src/__init__.py create mode 100644 src/dcr/__init__.py create mode 100644 src/dcr/cli/__init__.py create mode 100644 src/dcr/cli/build.py create mode 100644 src/dcr/cli/help.py create mode 100644 src/dcr/cli/init.py create mode 100644 src/dcr/cli/new.py create mode 100644 src/dcr/cli/run.py create mode 100644 src/dcr/config.py create mode 100644 src/dcr/main.py create mode 100644 src/dcr/utils/__init__.py create mode 100644 src/test/__init__.py create mode 100644 uv.lock diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c007186 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +__pycache__/ +build/ +dist/ +wheels/ +*.egg-info +.venv +sandbox/* \ No newline at end of file diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..95ed564 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.14.2 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..5480842 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "kiroAgent.configureMCP": "Disabled" +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..486cb84 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,17 @@ +[project] +name = "dcr" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +authors = [ + { name = "Dexoron", email = "probrovova1@gmail.com" } +] +requires-python = ">=3.14.2" +dependencies = [] + +[project.scripts] +run = "dcr.main:main" + +[build-system] +requires = ["uv_build>=0.10.0,<0.11.0"] +build-backend = "uv_build" diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/dcr/__init__.py b/src/dcr/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/dcr/cli/__init__.py b/src/dcr/cli/__init__.py new file mode 100644 index 0000000..95a7cb0 --- /dev/null +++ b/src/dcr/cli/__init__.py @@ -0,0 +1,13 @@ +from .help import help +from .init import init +from .new import new +from .run import run +from .build import build + +__all__ = [ + "help", + "init", + "new", + "run", + "build", +] diff --git a/src/dcr/cli/build.py b/src/dcr/cli/build.py new file mode 100644 index 0000000..249699b --- /dev/null +++ b/src/dcr/cli/build.py @@ -0,0 +1,34 @@ +import os +import subprocess +from dcr.config import flags + + +def check_dir(dir: str | None = None) -> list[str]: + if dir in (None, ".", "./"): + return os.listdir(os.getcwd()) + else: + return os.listdir(os.getcwd() + "/" + dir) + + +def build(args: list[str] | str) -> int: + if "dcr.toml" not in check_dir(): + print("error: Not font dcr.toml") + return 1 + if "target" not in check_dir(): + os.mkdir("./target") + + if len(args) == 1 and args[0] in flags: + profile: str = args[0][2:] + else: + print("error: Unkown flags") + return 1 + if len(args) == 0: + profile: str = "debug" + + if profile not in check_dir("target"): + os.mkdir(f"./target/{profile}") + if "main.c" in check_dir("src"): + print(f"Run build project as profiles {profile}") + subprocess.run(["gcc", "./src/main.c", "-o", f"./target/{profile}/main"]) + print("Build complite") + return 0 diff --git a/src/dcr/cli/help.py b/src/dcr/cli/help.py new file mode 100644 index 0000000..ffe211d --- /dev/null +++ b/src/dcr/cli/help.py @@ -0,0 +1,3 @@ +def help() -> int: + print("Help") + return 0 diff --git a/src/dcr/cli/init.py b/src/dcr/cli/init.py new file mode 100644 index 0000000..9bb2605 --- /dev/null +++ b/src/dcr/cli/init.py @@ -0,0 +1,32 @@ +import os + + +def init(args) -> int: + items = os.listdir(os.getcwd()) + project_name = os.path.basename(os.getcwd()) + + if items: + print("ERROR: directory is not empty") + return 1 + + os.mkdir("src") + + with open("./src/main.c", "w") as file: + file.write( + "#include \n\n" + "int main(void) {\n" + ' printf("Hello World!\\n");\n' + " return 0;\n" + "}\n" + ) + + with open("./dcr.toml", "w") as file: + file.write( + "[package]\n" + f'name = "{project_name}"\n' + 'version = "0.1.0"\n' + 'edition = "2026"\n\n' + "[dependencies]\n" + ) + + return 0 diff --git a/src/dcr/cli/new.py b/src/dcr/cli/new.py new file mode 100644 index 0000000..a516b18 --- /dev/null +++ b/src/dcr/cli/new.py @@ -0,0 +1,34 @@ +import os + + +def new(args: list[str]) -> int: + items: list[str] = os.listdir(os.getcwd()) + if len(args) == 0 or len(args) > 1: + print("ERROR") + return 1 + project_name: str = args[0] + if project_name in items: + print("ERROR") + return 1 + + os.makedirs(f"./{project_name}/src") + + with open(f"./{project_name}/src/main.c", "w") as file: + file.write( + "#include \n\n" + "int main(void) {\n" + ' printf("Hello World!\\n");\n' + " return 0;\n" + "}\n" + ) + + with open(f"./{project_name}/dcr.toml", "w") as file: + file.write( + "[package]\n" + f'name = "{project_name}"\n' + 'version = "0.1.0"\n' + 'edition = "2026"\n\n' + "[dependencies]\n" + ) + + return 0 diff --git a/src/dcr/cli/run.py b/src/dcr/cli/run.py new file mode 100644 index 0000000..59e11b4 --- /dev/null +++ b/src/dcr/cli/run.py @@ -0,0 +1,30 @@ +import os +import subprocess + +from dcr.config import flags +from .build import build + + +def check_dir(dir: str | None = None) -> list[str]: + if dir in (None, ".", "./"): + return os.listdir(os.getcwd()) + else: + return os.listdir(os.getcwd() + "/" + dir) + + +def run(args: list[str]) -> int: + if "dcr.toml" not in os.listdir(os.getcwd()): + print("error: Not fond dcr.toml") + return 1 + + if len(args) == 0: + profile: str = "debug" + elif len(args) == 1 and args[0] in flags: + profile = args[0][2:] + else: + print("error: Unkown flags") + return 1 + + build(args) + print("Run project") + return subprocess.run([f"./target/{profile}/main"]).returncode diff --git a/src/dcr/config.py b/src/dcr/config.py new file mode 100644 index 0000000..5ac511e --- /dev/null +++ b/src/dcr/config.py @@ -0,0 +1 @@ +flags: list[str] = ["--release", "--debug"] \ No newline at end of file diff --git a/src/dcr/main.py b/src/dcr/main.py new file mode 100644 index 0000000..80184dc --- /dev/null +++ b/src/dcr/main.py @@ -0,0 +1,25 @@ +import dcr.cli as cli +import sys + + +def main() -> int: + if len(sys.argv) < 2 or sys.argv[1] == "--help": + cli.help() + return 0 + + cmd: str = sys.argv[1] + args: str | list[str] = sys.argv[2:] + + match cmd: + case "new": + cli.new(args) + case "init": + cli.init(args) + case "build": + cli.build(args) + case "run": + cli.run(args) + case _: + print("Unknown command") + + return 0 diff --git a/src/dcr/utils/__init__.py b/src/dcr/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/test/__init__.py b/src/test/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/uv.lock b/uv.lock new file mode 100644 index 0000000..716c93f --- /dev/null +++ b/uv.lock @@ -0,0 +1,8 @@ +version = 1 +revision = 3 +requires-python = ">=3.14.2" + +[[package]] +name = "dcr" +version = "0.1.0" +source = { editable = "." }