aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2024-03-11 22:50:33 +0800
committer简律纯 <i@jyunko.cn>2024-03-11 22:50:33 +0800
commit7f3d06c0b93707cfe40b458120f87e9fd891247d (patch)
treec6665788a6fad7a16836e767d77dea888b5b92a2
parent7f40fa184e8e948a2742d72267de72e6d33405cb (diff)
downloadipm-7f3d06c0b93707cfe40b458120f87e9fd891247d.tar.gz
ipm-7f3d06c0b93707cfe40b458120f87e9fd891247d.zip
feat(api): add xml_file generate method for build command
-rw-r--r--src/ipm/api.py38
-rw-r--r--src/ipm/models/ipk.py14
-rw-r--r--src/ipm/project/toml_file.py18
-rw-r--r--src/ipm/utils/_freeze.py31
-rw-r--r--src/ipm/utils/freeze.py4
5 files changed, 80 insertions, 25 deletions
diff --git a/src/ipm/api.py b/src/ipm/api.py
index 5d52e00..ff1ca0c 100644
--- a/src/ipm/api.py
+++ b/src/ipm/api.py
@@ -117,25 +117,29 @@ def init(target_path: StrPath, force: bool = False, echo: bool = False) -> bool:
status.start()
init_infini(
- toml_path,
- target_path,
- name,
- version,
- description,
- author_name,
- author_email,
- license,
- entry_file,
- default_entries,
+ toml_path=toml_path,
+ target_path=target_path,
+ name=name,
+ version=version,
+ description=description,
+ author_name=author_name,
+ author_email=author_email,
+ webpage='',
+ unzip=1,
+ license=license,
+ entry_file=entry_file,
+ default_entries=default_entries,
)
init_pyproject(
- target_path,
- name,
- version,
- description,
- author_name,
- author_email,
- license,
+ target_path=target_path,
+ name=name,
+ version=version,
+ description=description,
+ author_name=author_name,
+ author_email=author_email,
+ license=license,
+ webpage='',
+ unzip=1
)
new_virtualenv(target_path)
return True
diff --git a/src/ipm/models/ipk.py b/src/ipm/models/ipk.py
index 7229484..9cf21b8 100644
--- a/src/ipm/models/ipk.py
+++ b/src/ipm/models/ipk.py
@@ -192,6 +192,14 @@ class InfiniProject(InfiniPackage):
return Authors(self._data["project"]["authors"]) # type: ignore
@property
+ def webpage(self) -> str:
+ return self._data["project"]["webpage"] # type: ignore
+
+ @property
+ def unzip(self) -> str | int:
+ return self._data["project"]["unzip"] # type: ignore
+
+ @property
def license(self) -> str:
return self._data["project"]["license"] # type: ignore
@@ -201,11 +209,13 @@ class InfiniProject(InfiniPackage):
@property
def requirements(self) -> Requirements:
- return Requirements(self._data.get("requirements") or {}, yggdrasils=self.yggdrasils) # type: ignore
+ # type: ignore
+ return Requirements(self._data.get("requirements") or {}, yggdrasils=self.yggdrasils)
@property
def yggdrasils(self) -> List[Yggdrasil]:
- return [Yggdrasil(index) for _, index in self._data.get("yggdrasils", {}).items()] or [] # type: ignore
+ # type: ignore
+ return [Yggdrasil(index) for _, index in self._data.get("yggdrasils", {}).items()] or []
class InfiniFrozenPackage(InfiniPackage):
diff --git a/src/ipm/project/toml_file.py b/src/ipm/project/toml_file.py
index e0738c8..510a75e 100644
--- a/src/ipm/project/toml_file.py
+++ b/src/ipm/project/toml_file.py
@@ -17,6 +17,8 @@ def init_infini(
author_name: str,
author_email: str,
license: str,
+ webpage: str,
+ unzip: str|int,
entry_file: str,
default_entries: List[str],
) -> None:
@@ -31,6 +33,8 @@ def init_infini(
author.multiline(True)
project.add("authors", author)
project.add("license", license)
+ project.add("webpage", webpage)
+ project.add("unzip", unzip)
toml_data.add("project", project)
toml_data.add("requirements", tomlkit.table())
toml_data.add("dependencies", tomlkit.table())
@@ -53,7 +57,7 @@ def init_infini(
init_filepath.write_text(
"# Initialized `events.py` generated by ipm.\n"
"# Regists your text events and regist global variables here.\n"
- "# Documents at https://ipm.hydroroll.team/\n\n"
+ "# Documents at https://docs.hydroroll.team/ipm\n\n"
"from infini.register import Register\n\n\n"
"register = Register()\n"
)
@@ -61,7 +65,7 @@ def init_infini(
events_filepath.write_text(
"# Initialized `events.py` generated by ipm.\n"
"# Regists your text events and regist global variables here.\n"
- "# Documents at https://ipm.hydroroll.team/\n\n"
+ "# Documents at https://docs.hydroroll.team/ipm\n\n"
"from infini.register import Register\n\n\n"
"register = Register()\n"
)
@@ -69,7 +73,7 @@ def init_infini(
handlers_filepath.write_text(
"# Initialized `handlers.py` generated by ipm.\n"
"# Regists your handlers here.\n"
- "# Documents at https://ipm.hydroroll.team/\n\n"
+ "# Documents at https://docs.hydroroll.team/ipm\n\n"
"from infini.register import Register\n\n\n"
"register = Register()\n"
)
@@ -77,7 +81,7 @@ def init_infini(
interceptors_filepath.write_text(
"# Initialized `interceptors.py` generated by ipm.\n"
"# Regists your pre-interceptors and interceptors here.\n"
- "# Documents at https://ipm.hydroroll.team/\n\n"
+ "# Documents at https://docs.hydroroll.team/ipm\n\n"
"from infini.register import Register\n\n\n"
"register = Register()\n"
)
@@ -86,7 +90,7 @@ def init_infini(
if not entry_filepath.exists():
entry_filepath.write_text(
f"# Initialized `{source_path.name}` generated by ipm.\n"
- "# Documents at https://ipm.hydroroll.team/\n\n"
+ "# Documents at https://docs.hydroroll.team/ipm\n\n"
"from infini.register import Register\n\n\n"
"register = Register()\n"
)
@@ -111,6 +115,8 @@ def init_pyproject(
description: str,
author_name: str,
author_email: str,
+ webpage: str,
+ unzip: int|str,
license: str,
):
toml_file = target_path.joinpath("pyproject.toml").open("w", encoding="utf-8")
@@ -126,6 +132,8 @@ def init_pyproject(
license_table = tomlkit.inline_table()
license_table.update({"text": license})
project.add("license", license_table)
+ project.add("webpage", webpage)
+ project.add("unzip", unzip)
project.add("dependencies", tomlkit.array('["infini"]'))
project.add("requires-python", ">=3.8")
project.add("readme", "README.md")
diff --git a/src/ipm/utils/_freeze.py b/src/ipm/utils/_freeze.py
index e1d19db..d054fe9 100644
--- a/src/ipm/utils/_freeze.py
+++ b/src/ipm/utils/_freeze.py
@@ -1,10 +1,18 @@
+from curses import meta
+from importlib import metadata
+from pathlib import Path
+from struct import pack
import tarfile
import shutil
+import os.path as path
+
+from ipm.models.ipk import InfiniProject
def create_tar_gz(source_folder: str, output_filepath: str) -> None:
shutil.move(
- shutil.make_archive(output_filepath + ".build", "gztar", source_folder),
+ shutil.make_archive(output_filepath + ".build",
+ "gztar", source_folder),
output_filepath,
shutil.copy2,
)
@@ -13,3 +21,24 @@ def create_tar_gz(source_folder: str, output_filepath: str) -> None:
def extract_tar_gz(input_filename: str, output_folder: str) -> None:
with tarfile.open(input_filename, "r:gz") as tar:
tar.extractall(output_folder, filter=tarfile.fully_trusted_filter)
+
+
+def create_xml_file(meta_data: InfiniProject, output_folder: str | Path) -> None:
+ package = {}
+ package['_id'] = meta_data.name
+ package['version'] = meta_data.version
+ package['description'] = meta_data.description
+ authors = meta_data.authors
+ if authors is not None:
+ package['author'] = authors.first
+ package['_license'] = meta_data.license
+ package['webpage'] = meta_data.webpage
+ package['unzip'] = meta_data.unzip
+
+ with open(path.join(output_folder, package["_id"], ".xml"), mode='w', encoding='utf8') as xml_file:
+ xml_file.write(f"""<package id="{_id}"
+ name="{_id}: {description}"
+ webpage="{webpage}"
+ author="{author}"
+ license="{_license}"
+ unzip="{unzip}"/>""".format(**package))
diff --git a/src/ipm/utils/freeze.py b/src/ipm/utils/freeze.py
index 0972308..cee76f6 100644
--- a/src/ipm/utils/freeze.py
+++ b/src/ipm/utils/freeze.py
@@ -52,6 +52,10 @@ def build_ipk(ipk: InfiniProject, echo: bool = False) -> InfiniFrozenPackage:
update("创建 SHA256 验证文件...", echo)
hash_bytes = ifp_hash(ifp_path)
info(f"文件 SHA256 值为 [purple]{hash_bytes.hex()}[/purple].", echo)
+
+ update("正在生成 id.xml 文件...", echo)
+ _freeze.create_xml_file(project, dist_path)
+ success("xml 索引文件生成完毕.", echo)
(dist_path / ipk.hash_name).write_bytes(hash_bytes)
success(