mirror of
https://github.com/dexoron/dcr.git
synced 2026-10-21 17:19:37 +00:00
Обновлен README.md с инструкциями по установке и улучшить скрипт установки. Исправлены импорты в модулях и улучшить обработку сборки в run.py/build.py.
This commit is contained in:
17
README.md
17
README.md
@@ -18,10 +18,21 @@ DCR — это утилита для управления проектами н
|
|||||||
|
|
||||||
## Установка
|
## Установка
|
||||||
|
|
||||||
```
|
### Автоматическая установка(Рекомендуется)
|
||||||
|
|
||||||
|
**GNU/Linux**
|
||||||
|
```sh
|
||||||
curl -L dcr.zov.tatar | bash
|
curl -L dcr.zov.tatar | bash
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Самостоятельная установка
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone https://github.com/dexoron/dcr.git "~/.local/share/dcr"
|
||||||
|
chmod +x "~/.local/share/dcr/dcr"
|
||||||
|
ln -sf ~/.local/share/dcr/dcr ~/.local/bin
|
||||||
|
```
|
||||||
|
|
||||||
## Быстрый старт
|
## Быстрый старт
|
||||||
Создать новый проект:
|
Создать новый проект:
|
||||||
`dcr new hello`
|
`dcr new hello`
|
||||||
@@ -37,6 +48,10 @@ hello/
|
|||||||
- dcr.toml
|
- dcr.toml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Сборка и запуск проекта:
|
||||||
|
`dcr run` или `dcr run --release` - для сбрки с оптимизацией
|
||||||
|
|
||||||
|
|
||||||
## Команды
|
## Команды
|
||||||
|
|
||||||
### `dcr new <name>`
|
### `dcr new <name>`
|
||||||
|
|||||||
120
install.sh
120
install.sh
@@ -1,12 +1,12 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -Eeuo pipefail
|
set -Eeuo pipefail
|
||||||
|
|
||||||
|
# ===== CONFIG =====
|
||||||
TMPDIR="/tmp/dcr-temp"
|
TMPDIR="/tmp/dcr-temp"
|
||||||
INSTALL_PATH="$HOME/.local/share/dcr"
|
INSTALL_PATH="$HOME/.local/share/dcr"
|
||||||
PYTHON_DIR="$INSTALL_PATH/Python"
|
PYTHON_DIR="$INSTALL_PATH/Python"
|
||||||
BINPATH="$HOME/.local/bin"
|
BINPATH="$HOME/.local/bin"
|
||||||
LOGFILE="$PWD/dcr-install.log"
|
LOGFILE="$HOME/.cache/dcr-install.log"
|
||||||
|
|
||||||
PYTHON_DOWNLOAD_URL="https://github.com/astral-sh/python-build-standalone/releases/download/20260203/cpython-3.10.19+20260203-x86_64-unknown-linux-gnu-install_only.tar.gz"
|
PYTHON_DOWNLOAD_URL="https://github.com/astral-sh/python-build-standalone/releases/download/20260203/cpython-3.10.19+20260203-x86_64-unknown-linux-gnu-install_only.tar.gz"
|
||||||
GITHUB_API="https://api.github.com/repos/dexoron/dcr/releases/latest"
|
GITHUB_API="https://api.github.com/repos/dexoron/dcr/releases/latest"
|
||||||
@@ -17,68 +17,49 @@ YELLOW='\033[1;33m'
|
|||||||
BLUE='\033[0;34m'
|
BLUE='\033[0;34m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
|
|
||||||
|
mkdir -p "$(dirname "$LOGFILE")"
|
||||||
exec > >(tee -a "$LOGFILE") 2>&1
|
exec > >(tee -a "$LOGFILE") 2>&1
|
||||||
|
|
||||||
log() {
|
log() { echo -e "${BLUE}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $1"; }
|
||||||
echo -e "${BLUE}[$(date '+%Y-%m-%d %H:%M:%S')]${NC} $1"
|
success() { echo -e "${GREEN}✔ $1${NC}"; }
|
||||||
}
|
warn() { echo -e "${YELLOW}⚠ $1${NC}"; }
|
||||||
|
error() { echo -e "${RED}✖ $1${NC}"; }
|
||||||
success() {
|
|
||||||
echo -e "${GREEN}✔ $1${NC}"
|
|
||||||
}
|
|
||||||
|
|
||||||
warn() {
|
|
||||||
echo -e "${YELLOW}⚠ $1${NC}"
|
|
||||||
}
|
|
||||||
|
|
||||||
error() {
|
|
||||||
echo -e "${RED}✖ $1${NC}"
|
|
||||||
}
|
|
||||||
|
|
||||||
trap 'error "Ошибка на строке $LINENO"; exit 1' ERR
|
trap 'error "Ошибка на строке $LINENO"; exit 1' ERR
|
||||||
|
|
||||||
check_dependencies() {
|
check_dependencies() {
|
||||||
log "Проверка зависимостей..."
|
log "Проверка зависимостей..."
|
||||||
|
|
||||||
command -v curl >/dev/null 2>&1 || {
|
command -v curl >/dev/null 2>&1 || { error "curl не установлен"; exit 1; }
|
||||||
error "curl не установлен"
|
command -v tar >/dev/null 2>&1 || { error "tar не установлен"; exit 1; }
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
command -v tar >/dev/null 2>&1 || {
|
|
||||||
error "tar не установлен"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
success "Зависимости в порядке"
|
success "Зависимости в порядке"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_os() {
|
||||||
|
if [[ "$(uname -s)" != "Linux" ]]; then
|
||||||
|
error "Поддерживается только Linux"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
install_python() {
|
install_python() {
|
||||||
log "Установка встроенного Python..."
|
log "Python не найден, установка встроенного Python..."
|
||||||
|
|
||||||
mkdir -p "$PYTHON_DIR"
|
mkdir -p "$PYTHON_DIR"
|
||||||
|
mkdir -p "$TMPDIR"
|
||||||
|
|
||||||
curl -L "$PYTHON_DOWNLOAD_URL" -o "$TMPDIR/python.tar.gz"
|
curl -fsSL "$PYTHON_DOWNLOAD_URL" -o "$TMPDIR/python.tar.gz"
|
||||||
tar -xf "$TMPDIR/python.tar.gz" -C "$PYTHON_DIR" --strip-components=1
|
tar -xf "$TMPDIR/python.tar.gz" -C "$PYTHON_DIR" --strip-components=1
|
||||||
rm -f "$TMPDIR/python.tar.gz"
|
rm -f "$TMPDIR/python.tar.gz"
|
||||||
|
|
||||||
cat > "$INSTALL_PATH/dcr" <<'EOF'
|
success "Встроенный Python установлен"
|
||||||
#!/usr/bin/env bash
|
|
||||||
BASE_DIR="$(dirname "$(readlink -f "$0")")"
|
|
||||||
SRC_DIR="$BASE_DIR/src"
|
|
||||||
PYTHON_BIN="$BASE_DIR/Python/bin/python3"
|
|
||||||
PYTHONPATH="$SRC_DIR" exec "$PYTHON_BIN" -m dcr.main "$@"
|
|
||||||
EOF
|
|
||||||
|
|
||||||
chmod +x "$INSTALL_PATH/dcr"
|
|
||||||
|
|
||||||
success "Python установлен"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
install_app() {
|
install_app() {
|
||||||
log "Получение последнего релиза..."
|
log "Получение последнего релиза..."
|
||||||
|
|
||||||
TAG=$(curl -s "$GITHUB_API" | grep '"tag_name":' | cut -d'"' -f4)
|
TAG=$(curl -fsSL "$GITHUB_API" | sed -n 's/.*"tag_name": "\(.*\)".*/\1/p')
|
||||||
|
|
||||||
if [[ -z "$TAG" ]]; then
|
if [[ -z "$TAG" ]]; then
|
||||||
error "Не удалось определить версию релиза"
|
error "Не удалось определить версию релиза"
|
||||||
@@ -87,7 +68,8 @@ install_app() {
|
|||||||
|
|
||||||
log "Найдена версия: $TAG"
|
log "Найдена версия: $TAG"
|
||||||
|
|
||||||
curl -L -o "$TMPDIR/sources.tar.gz" \
|
mkdir -p "$TMPDIR"
|
||||||
|
curl -fsSL -o "$TMPDIR/sources.tar.gz" \
|
||||||
"https://github.com/dexoron/dcr/archive/refs/tags/$TAG.tar.gz"
|
"https://github.com/dexoron/dcr/archive/refs/tags/$TAG.tar.gz"
|
||||||
|
|
||||||
mkdir -p "$INSTALL_PATH"
|
mkdir -p "$INSTALL_PATH"
|
||||||
@@ -97,6 +79,29 @@ install_app() {
|
|||||||
success "Приложение установлено"
|
success "Приложение установлено"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install_wrapper() {
|
||||||
|
log "Создание launcher..."
|
||||||
|
|
||||||
|
mkdir -p "$INSTALL_PATH"
|
||||||
|
|
||||||
|
cat > "$INSTALL_PATH/dcr" <<'EOF'
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
|
||||||
|
if command -v python3 >/dev/null 2>&1; then
|
||||||
|
PYTHON_BIN="python3"
|
||||||
|
else
|
||||||
|
PYTHON_BIN="$BASE_DIR/Python/bin/python3"
|
||||||
|
fi
|
||||||
|
|
||||||
|
PYTHONPATH="$BASE_DIR/src" exec "$PYTHON_BIN" -m dcr.main "$@"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chmod +x "$INSTALL_PATH/dcr"
|
||||||
|
|
||||||
|
success "Launcher создан"
|
||||||
|
}
|
||||||
|
|
||||||
install_link() {
|
install_link() {
|
||||||
log "Создание симлинка..."
|
log "Создание симлинка..."
|
||||||
|
|
||||||
@@ -106,23 +111,38 @@ install_link() {
|
|||||||
success "Команда 'dcr' добавлена в $BINPATH"
|
success "Команда 'dcr' добавлена в $BINPATH"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_path() {
|
||||||
|
if ! echo "$PATH" | grep -q "$BINPATH"; then
|
||||||
|
warn "Каталог $BINPATH не найден в PATH"
|
||||||
|
echo "Добавь в ~/.bashrc или ~/.zshrc:"
|
||||||
|
echo "export PATH=\"$BINPATH:\$PATH\""
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
rm -rf "$TMPDIR" 2>/dev/null || true
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
log "Запуск установки DCR"
|
log "Запуск установки DCR"
|
||||||
|
|
||||||
|
check_os
|
||||||
check_dependencies
|
check_dependencies
|
||||||
|
|
||||||
mkdir -p "$TMPDIR"
|
cleanup
|
||||||
rm -rf "$TMPDIR"/*
|
|
||||||
|
|
||||||
install_app
|
install_app
|
||||||
log "проверка наличия Python"
|
|
||||||
command -v curl >/dev/null 2>&1 || {
|
|
||||||
error "Python не установлен"
|
|
||||||
install_python
|
|
||||||
}
|
|
||||||
install_link
|
|
||||||
|
|
||||||
rm -rf "$TMPDIR"
|
if ! command -v python3 >/dev/null 2>&1; then
|
||||||
|
install_python
|
||||||
|
else
|
||||||
|
success "Найден системный Python"
|
||||||
|
fi
|
||||||
|
|
||||||
|
install_wrapper
|
||||||
|
install_link
|
||||||
|
check_path
|
||||||
|
cleanup
|
||||||
|
|
||||||
success "Установка завершена успешно"
|
success "Установка завершена успешно"
|
||||||
log "Лог сохранён в $LOGFILE"
|
log "Лог сохранён в $LOGFILE"
|
||||||
|
|||||||
@@ -1,17 +1,11 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "dcr"
|
name = "dcr"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = "Add your description here"
|
description = "Утилита для управления проектами для C/C++"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
license = "LICENSE"
|
||||||
authors = [
|
authors = [
|
||||||
{ name = "Dexoron", email = "probrovova1@gmail.com" }
|
{ name = "Dexoron" },
|
||||||
|
{ name = "F1F1FISHKA" }
|
||||||
]
|
]
|
||||||
requires-python = ">=3.14.2"
|
requires-python = ">=3.10"
|
||||||
dependencies = []
|
|
||||||
|
|
||||||
[project.scripts]
|
|
||||||
run = "dcr.main:main"
|
|
||||||
|
|
||||||
[build-system]
|
|
||||||
requires = ["uv_build>=0.10.0,<0.11.0"]
|
|
||||||
build-backend = "uv_build"
|
|
||||||
@@ -2,7 +2,7 @@ import time
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
from ..config import flags, profile, c_comp
|
from ..config import flags, profile, c_comp
|
||||||
from dcr.utils.fs import check_dir
|
from ..utils.fs import check_dir
|
||||||
|
|
||||||
|
|
||||||
def build(args: list[str] | None = None) -> int:
|
def build(args: list[str] | None = None) -> int:
|
||||||
@@ -31,6 +31,7 @@ def build(args: list[str] | None = None) -> int:
|
|||||||
print(f"Запуск сборки с профилем {active_profile}")
|
print(f"Запуск сборки с профилем {active_profile}")
|
||||||
compile_flags = flags[active_profile]
|
compile_flags = flags[active_profile]
|
||||||
start_time: float = time.time()
|
start_time: float = time.time()
|
||||||
|
try:
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
[
|
[
|
||||||
c_comp,
|
c_comp,
|
||||||
@@ -46,3 +47,8 @@ def build(args: list[str] | None = None) -> int:
|
|||||||
times: float = int(times * 100) / 100
|
times: float = int(times * 100) / 100
|
||||||
print(f"Сборка завершена, за {times} секунд")
|
print(f"Сборка завершена, за {times} секунд")
|
||||||
return 0
|
return 0
|
||||||
|
except:
|
||||||
|
print("Ошибка сборки")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from dcr.utils.fs import check_dir
|
from ..utils.fs import check_dir
|
||||||
import os
|
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from dcr.config import (
|
from ..config import (
|
||||||
file_dcr_toml,
|
file_dcr_toml,
|
||||||
file_main_c,
|
file_main_c,
|
||||||
project_version,
|
project_version,
|
||||||
@@ -6,13 +6,14 @@ from dcr.config import (
|
|||||||
project_compiler,
|
project_compiler,
|
||||||
)
|
)
|
||||||
import os
|
import os
|
||||||
from dcr.utils.fs import check_dir
|
from ..utils.fs import check_dir
|
||||||
|
|
||||||
|
|
||||||
def init(args: list[str] | None = None) -> int:
|
def init(args: list[str] | None = None) -> int:
|
||||||
if args:
|
if args:
|
||||||
print("Ошибка: команда init не поддерживает аргументы")
|
print("Ошибка: команда init не поддерживает аргументы")
|
||||||
return 1
|
return 1
|
||||||
items = check_dir()
|
items: list[str] = check_dir()
|
||||||
project_name = os.path.basename(os.getcwd())
|
project_name = os.path.basename(os.getcwd())
|
||||||
|
|
||||||
if items:
|
if items:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from dcr.config import (
|
from ..config import (
|
||||||
file_dcr_toml,
|
file_dcr_toml,
|
||||||
file_main_c,
|
file_main_c,
|
||||||
project_version,
|
project_version,
|
||||||
@@ -6,7 +6,7 @@ from dcr.config import (
|
|||||||
project_compiler,
|
project_compiler,
|
||||||
)
|
)
|
||||||
import os
|
import os
|
||||||
from dcr.utils.fs import check_dir
|
from ..utils.fs import check_dir
|
||||||
|
|
||||||
|
|
||||||
def new(args: list[str]) -> int:
|
def new(args: list[str]) -> int:
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import os
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from dcr.utils.fs import check_dir
|
from ..utils.fs import check_dir
|
||||||
from ..config import flags, profile
|
from ..config import flags, profile
|
||||||
from .build import build
|
from .build import build
|
||||||
|
|
||||||
@@ -24,6 +23,14 @@ def run(args: list[str] | None = None) -> int:
|
|||||||
print("Ошибка: флаг сборки не найден")
|
print("Ошибка: флаг сборки не найден")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
build(args)
|
build_status: int = build(args)
|
||||||
|
if build_status == 0:
|
||||||
print("Запуск проекта")
|
print("Запуск проекта")
|
||||||
return subprocess.run([f"./target/{active_profile}/main"]).returncode
|
return subprocess.run([f"./target/{active_profile}/main"]).returncode
|
||||||
|
else:
|
||||||
|
if active_profile in check_dir("target/" + active_profile):
|
||||||
|
print("Запуск последнего релиза")
|
||||||
|
return subprocess.run([f"./target/{active_profile}/main"]).returncode
|
||||||
|
else:
|
||||||
|
print("Исправьте ошибки в коде для запуска проекта")
|
||||||
|
return 0
|
||||||
|
|||||||
@@ -26,5 +26,6 @@ def main() -> int:
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
raise SystemExit(main())
|
raise SystemExit(main())
|
||||||
Reference in New Issue
Block a user