Added version
All checks were successful
Test before pr merge / test-lint (pull_request) Successful in 7s
All checks were successful
Test before pr merge / test-lint (pull_request) Successful in 7s
This commit is contained in:
@@ -36,6 +36,12 @@ jobs:
|
|||||||
echo "Set version to $(cat /workspace/sh-edraft.de/cpl/version.txt)"
|
echo "Set version to $(cat /workspace/sh-edraft.de/cpl/version.txt)"
|
||||||
cat pyproject.toml
|
cat pyproject.toml
|
||||||
|
|
||||||
|
- name: Set package version
|
||||||
|
run: |
|
||||||
|
sed -i -E "s/^__version__ = \".*\"/__version__ = \"$(cat /workspace/sh-edraft.de/cpl/version.txt)\"/" cpl/*/__init__.py
|
||||||
|
echo "Set version to $(cat /workspace/sh-edraft.de/cpl/version.txt)"
|
||||||
|
cat cpl/*/__init__.py
|
||||||
|
|
||||||
- name: Set pip conf
|
- name: Set pip conf
|
||||||
run: |
|
run: |
|
||||||
cat > .pip.conf <<'EOF'
|
cat > .pip.conf <<'EOF'
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
__version__ = "1.0.0"
|
||||||
|
|||||||
27
src/cpl-cli/cpl/cli/command/version.py
Normal file
27
src/cpl-cli/cpl/cli/command/version.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import platform
|
||||||
|
|
||||||
|
import cpl
|
||||||
|
from cpl.cli.cli import cli
|
||||||
|
from cpl.cli.utils.pip import Pip
|
||||||
|
from cpl.core.console import Console, ForegroundColorEnum
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command("version", aliases=["v"])
|
||||||
|
def version():
|
||||||
|
Console.set_foreground_color(ForegroundColorEnum.yellow)
|
||||||
|
Console.banner("CPL CLI")
|
||||||
|
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||||
|
|
||||||
|
Console.write_line()
|
||||||
|
Console.write_line(f"CPL CLI: {getattr(cpl.cli, '__version__', "1.0")}")
|
||||||
|
Console.write_line(f"Python: {platform.python_version()}")
|
||||||
|
Console.write_line(f"PIP: {Pip.get_pip_version()}")
|
||||||
|
Console.write_line(f"OS: {platform.system()} {platform.release()}")
|
||||||
|
|
||||||
|
Console.write_line("\nCPL Packages:\n")
|
||||||
|
cpl_packages = {n: v for n, v in Pip.get_packages().items() if n.startswith("cpl-")}
|
||||||
|
if len(cpl_packages) == 0:
|
||||||
|
Console.write_line("No CPL packages installed")
|
||||||
|
return
|
||||||
|
|
||||||
|
Console.table(["Package", "Version"], [[n, v] for n, v in cpl_packages.items()])
|
||||||
@@ -6,6 +6,7 @@ from cpl.cli.command.init import init
|
|||||||
from cpl.cli.command.install import install
|
from cpl.cli.command.install import install
|
||||||
from cpl.cli.command.uninstall import uninstall
|
from cpl.cli.command.uninstall import uninstall
|
||||||
from cpl.cli.command.update import update
|
from cpl.cli.command.update import update
|
||||||
|
from cpl.cli.command.version import version
|
||||||
from cpl.cli.model.workspace import Workspace
|
from cpl.cli.model.workspace import Workspace
|
||||||
from cpl.cli.utils.custom_command import script_command
|
from cpl.cli.utils.custom_command import script_command
|
||||||
from cpl.core.configuration import Configuration
|
from cpl.core.configuration import Configuration
|
||||||
@@ -42,10 +43,23 @@ def prepare():
|
|||||||
|
|
||||||
|
|
||||||
def configure():
|
def configure():
|
||||||
|
# cli
|
||||||
|
cli.add_command(version)
|
||||||
|
|
||||||
|
# structure
|
||||||
cli.add_command(init)
|
cli.add_command(init)
|
||||||
|
# cli.add_command(new)
|
||||||
|
|
||||||
|
# packaging
|
||||||
cli.add_command(install)
|
cli.add_command(install)
|
||||||
cli.add_command(uninstall)
|
cli.add_command(uninstall)
|
||||||
cli.add_command(update)
|
cli.add_command(update)
|
||||||
|
# cli.add_command(add)
|
||||||
|
# cli.add_command(remove)
|
||||||
|
|
||||||
|
# run
|
||||||
|
# cli.add_command(run)
|
||||||
|
# cli.add_command(start)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class Pip:
|
|||||||
for prefix, pip_op in table.items():
|
for prefix, pip_op in table.items():
|
||||||
if raw.startswith(prefix):
|
if raw.startswith(prefix):
|
||||||
op = pip_op
|
op = pip_op
|
||||||
raw = raw[len(prefix):]
|
raw = raw[len(prefix) :]
|
||||||
break
|
break
|
||||||
|
|
||||||
return f"{name}{op}{raw}"
|
return f"{name}{op}{raw}"
|
||||||
@@ -48,7 +48,7 @@ class Pip:
|
|||||||
return f"~{installed}"
|
return f"~{installed}"
|
||||||
|
|
||||||
op = m.group(1)
|
op = m.group(1)
|
||||||
rest = s[m.end():].strip()
|
rest = s[m.end() :].strip()
|
||||||
if "," in rest:
|
if "," in rest:
|
||||||
rest = rest.split(",", 1)[0].strip()
|
rest = rest.split(",", 1)[0].strip()
|
||||||
if " " in rest:
|
if " " in rest:
|
||||||
@@ -59,7 +59,7 @@ class Pip:
|
|||||||
installed_parts = [p for p in installed.split(".") if p != ""]
|
installed_parts = [p for p in installed.split(".") if p != ""]
|
||||||
if orig_version:
|
if orig_version:
|
||||||
orig_parts = [p for p in orig_version.split(".") if p != ""]
|
orig_parts = [p for p in orig_version.split(".") if p != ""]
|
||||||
trimmed_installed = ".".join(installed_parts[:len(orig_parts)]) or installed
|
trimmed_installed = ".".join(installed_parts[: len(orig_parts)]) or installed
|
||||||
else:
|
else:
|
||||||
trimmed_installed = installed
|
trimmed_installed = installed
|
||||||
|
|
||||||
@@ -96,8 +96,8 @@ class Pip:
|
|||||||
return spec.replace(package_name, "").strip() or None
|
return spec.replace(package_name, "").strip() or None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def command(command: str, *args,verbose:bool=False, path: str=None):
|
def command(command: str, *args, verbose: bool = False, path: str = None):
|
||||||
venv_path = ensure_venv(Path(path or './'))
|
venv_path = ensure_venv(Path(path or "./"))
|
||||||
pip = get_venv_pip(venv_path)
|
pip = get_venv_pip(venv_path)
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
@@ -113,8 +113,8 @@ class Pip:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_package_version(package: str, path: str=None) -> str | None:
|
def get_package_version(package: str, path: str = None) -> str | None:
|
||||||
venv_path = ensure_venv(Path(path or './'))
|
venv_path = ensure_venv(Path(path or "./"))
|
||||||
pip = get_venv_pip(venv_path)
|
pip = get_venv_pip(venv_path)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -132,4 +132,45 @@ class Pip:
|
|||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_packages(path: str = None):
|
||||||
|
venv_path = ensure_venv(Path(path or "./"))
|
||||||
|
pip = get_venv_pip(venv_path)
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
f"{pip} list --format=freeze",
|
||||||
|
shell=True,
|
||||||
|
check=True,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
stdin=subprocess.DEVNULL,
|
||||||
|
)
|
||||||
|
packages = {}
|
||||||
|
for line in result.stdout.splitlines():
|
||||||
|
if "==" in line:
|
||||||
|
name, version = line.split("==", 1)
|
||||||
|
packages[name] = version
|
||||||
|
return packages
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return {}
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_pip_version(path: str = None) -> str | None:
|
||||||
|
venv_path = ensure_venv(Path(path or "./"))
|
||||||
|
pip = get_venv_pip(venv_path)
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
f"{pip} --version",
|
||||||
|
shell=True,
|
||||||
|
check=True,
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
stdin=subprocess.DEVNULL,
|
||||||
|
)
|
||||||
|
version = result.stdout.split()[1]
|
||||||
|
return version
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return None
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
__version__ = "1.0.0"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import time
|
import time
|
||||||
@@ -56,9 +57,8 @@ class Spinner(Process):
|
|||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
columns = os.get_terminal_size().columns
|
columns = os.get_terminal_size().columns
|
||||||
else:
|
else:
|
||||||
values = os.popen("stty size", "r").read().split()
|
size = shutil.get_terminal_size(fallback=(80, 24))
|
||||||
term_rows, term_columns = values if len(values) == 2 else (0, 0)
|
columns = max(1, size.columns)
|
||||||
columns = int(term_columns)
|
|
||||||
|
|
||||||
end_msg = "done"
|
end_msg = "done"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
@@ -251,6 +252,25 @@ class Console:
|
|||||||
Console.read()
|
Console.read()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def divider(cls, char: str = "-"):
|
||||||
|
r"""Prints a divider line
|
||||||
|
|
||||||
|
Parameter:
|
||||||
|
char: :class:`str`
|
||||||
|
Character to use for the divider
|
||||||
|
"""
|
||||||
|
if cls._disabled:
|
||||||
|
return
|
||||||
|
|
||||||
|
if cls._hold_back:
|
||||||
|
cls._hold_back_calls.append(ConsoleCall(cls.divider, char))
|
||||||
|
return
|
||||||
|
|
||||||
|
size = shutil.get_terminal_size(fallback=(80, 24))
|
||||||
|
columns = max(1, size.columns)
|
||||||
|
cls.write_line(char * columns)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def disable(cls):
|
def disable(cls):
|
||||||
r"""Disables console interaction"""
|
r"""Disables console interaction"""
|
||||||
|
|||||||
Reference in New Issue
Block a user