Skip to content

Commit

Permalink
#minor nexus is herbarium now. Added git package urls
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-rusakevich committed Jan 16, 2025
1 parent f88a835 commit 000ab87
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/ramonak/__about__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.3"
__version__ = "0.5.0"
2 changes: 1 addition & 1 deletion src/ramonak/packages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

from pathlib import Path

NEXUS_PATH = Path(Path(__file__).parent, "nexus")
HERBARIUM_PATH = Path(Path(__file__).parent, "herbarium")
6 changes: 3 additions & 3 deletions src/ramonak/packages/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from ramonak import PACKAGES_PATH
from ramonak.exceptions import RamonakPackageManagerError
from ramonak.packages import NEXUS_PATH
from ramonak.packages import HERBARIUM_PATH


def _fetch_unzip(zip_file_url: str, destination_dir: Path | str) -> Path:
Expand Down Expand Up @@ -66,14 +66,14 @@ def _get_package_id_parts(package: str) -> tuple[str, str, str]:


def _get_package_versions(package_author, package_name) -> list:
package_file = str(Path(NEXUS_PATH, package_author, package_name)) + ".toml"
package_file = str(Path(HERBARIUM_PATH, package_author, package_name)) + ".toml"
package_dict = tomllib.loads(Path(package_file).read_text(encoding="utf8"))

return package_dict["versions"]


def _retrieve_package_url(package_author, package_name, package_version) -> str:
package_file = str(Path(NEXUS_PATH, package_author, package_name)) + ".toml"
package_file = str(Path(HERBARIUM_PATH, package_author, package_name)) + ".toml"
package_dict = tomllib.loads(Path(package_file).read_text(encoding="utf8"))

for version in package_dict["versions"]:
Expand Down
68 changes: 54 additions & 14 deletions src/ramonak/packages/actions.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""Фунцыі кіравання пакетамі."""

import shutil
import subprocess
import sys
import tomllib
from pathlib import Path
from typing import cast

from ramonak import PACKAGES_PATH
from ramonak.exceptions import RamonakPackageManagerError
from ramonak.packages import NEXUS_PATH
from ramonak.packages import HERBARIUM_PATH
from ramonak.packages._utils import (
_fetch_unzip,
_get_package_id_parts,
Expand Down Expand Up @@ -50,23 +53,60 @@ def require(package_id: str) -> Path:
else:
print(f"Required package '{package_id}'...", end=" ")

package_path = Path(PACKAGES_PATH, package_author, package_name, str(package_version))

if _local_package_exists(package_id if "==" in package_id else package_id + "==" + package_version):
print("Already satisfied")
return package_path.resolve()
print("Downloading...")
sys.stdout.flush()

package_path = Path(PACKAGES_PATH, package_author, package_name, str(package_version)).resolve()

if package_version == "git":
git_path = shutil.which("git")

if _local_package_exists(package_id if "==" in package_id else package_id + "==" + package_version):
if (
subprocess.run(
[cast(str, git_path), "-C", str(package_path), "pull"],
stdout=sys.stdout,
stderr=sys.stderr,
check=False,
).returncode
!= 0
):
msg = "Git failed with an error"
raise RamonakPackageManagerError(msg)

return package_path

print("Downloading...")

file_url = _retrieve_package_url(package_author, package_name, package_version)
package_path.mkdir(parents=True, exist_ok=True)

if (
subprocess.run(
[cast(str, git_path), "clone", file_url, str(package_path)],
stdout=sys.stdout,
stderr=sys.stderr,
check=False,
).returncode
!= 0
):
msg = "Git failed with an error"
raise RamonakPackageManagerError(msg)
else:
if _local_package_exists(package_id if "==" in package_id else package_id + "==" + package_version):
print("Already satisfied")
return package_path.resolve()
print("Downloading...")

file_url = _retrieve_package_url(package_author, package_name, package_version)
file_url = _retrieve_package_url(package_author, package_name, package_version)

_fetch_unzip(
file_url,
package_path,
)
_fetch_unzip(
file_url,
package_path,
)

print(f"The package '{package_author}/{package_name}=={package_version}' has been installed successfully")

return package_path.resolve()
return package_path


def remove(package_id: str):
Expand Down Expand Up @@ -139,7 +179,7 @@ def info(package_id: str):
або ``@author/package==version``
"""
author, name, version = _get_package_id_parts(package_id)
package_file = str(Path(NEXUS_PATH, author, name)) + ".toml"
package_file = str(Path(HERBARIUM_PATH, author, name)) + ".toml"
descriptor_text = Path(package_file).read_text(encoding="utf8")
descriptor_data = tomllib.loads(descriptor_text)

Expand Down
16 changes: 16 additions & 0 deletions src/ramonak/packages/herbarium/@poritski/yabc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package_info]
id = "@poritski/yabc"
name = "ЭКБМ"
author = "Аксана Ваўчок, Уладзіслаў Парыцкі"
maintainer = "Аляксандр Русакевіч (mr.alexander.rusakevich@gmail.com)"
homepage = "https://github.com/poritski/YABC"
description = """
«Эксперыментальны корпус беларускай мовы». У версіі ад 5 студзеня 2014 г. аб'ём корпуса склаў
звыш 7.5 млн токенаў газетных і мастацкіх тэкстаў. Для марфалагічнага анатавання выкарыстоўваўся
лематызатар ЭКБМ, аманімія не здымалася. Корпус суправаджаецца пошукавай праграмай для офлайнавага выкарыстання
(патрабуецца Perl 5.10 або навей).
"""

[[versions]]
id = "git"
url = "https://github.com/poritski/YABC.git"

0 comments on commit 000ab87

Please sign in to comment.