Skip to content

Commit

Permalink
feat(api): support data keep when force reinit
Browse files Browse the repository at this point in the history
  • Loading branch information
fu050409 committed Mar 29, 2024
1 parent 238dd37 commit 4e053ae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 27 deletions.
56 changes: 32 additions & 24 deletions src/ipm/project/toml_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,25 @@ def init_infini(
entry_file: str,
default_entries: List[str],
) -> None:
toml_path = target_path.joinpath("pyproject.toml")
if toml_path.exists():
toml_data = tomlkit.loads(toml_path.read_text(encoding="utf-8"))
else:
toml_data = tomlkit.document()
toml_file = toml_path.open("w", encoding="utf-8")
toml_data = tomlkit.document()
project = tomlkit.table()
project.add("name", name)
project.add("version", version)
project.add("description", description)
project = toml_data.get("project", tomlkit.table())
project["name"] = name
project["version"] = version
project["description"] = description
author = tomlkit.array()
author.add_line({"name": author_name, "email": author_email})
author.multiline(True)
project.add("authors", author)
project.add("license", license)
project.add("readme", "README.md")
toml_data.add("project", project)
toml_data.add("requirements", tomlkit.table())
toml_data.add("dependencies", tomlkit.table())
project["authors"] = author
project["license"] = license
project["readme"] = "README.md"
toml_data["project"] = project
toml_data["requirements"] = tomlkit.table()
toml_data["dependencies"] = tomlkit.table()
tomlkit.dump(toml_data, toml_file)
toml_file.close()

Expand Down Expand Up @@ -130,22 +134,26 @@ def init_pyproject(
license: str,
standalone: bool,
):
toml_file = target_path.joinpath("pyproject.toml").open("w", encoding="utf-8")
toml_data = tomlkit.document()
project = tomlkit.table()
project.add("name", name)
project.add("version", version)
project.add("description", description)
toml_path = target_path.joinpath("pyproject.toml")
if toml_path.exists():
toml_data = tomlkit.loads(toml_path.read_text(encoding="utf-8"))
else:
toml_data = tomlkit.document()
toml_file = toml_path.open("w", encoding="utf-8")
project = toml_data.get("project", tomlkit.table())
project["name"] = name
project["version"] = version
project["description"] = description
author = tomlkit.array()
author.add_line({"name": author_name, "email": author_email})
author.multiline(True)
project.add("authors", author)
project["authors"] = author
license_table = tomlkit.inline_table()
license_table.update({"text": license})
project.add("license", license_table)
project.add("dependencies", tomlkit.array('["infini>2.1.0"]'))
project.add("requires-python", ">=3.8")
project.add("readme", "README.md")
project["license"] = license_table
project["dependencies"] = tomlkit.array('["infini>2.1.0"]')
project["requires-python"] = ">=3.8"
project["readme"] = "README.md"

tool = tomlkit.table(True)
pdm = tomlkit.table(True)
Expand All @@ -156,7 +164,7 @@ def init_pyproject(
pdm.append("dev-dependencies", dev_dependencies)
tool.append("pdm", pdm)

toml_data.add("project", project)
toml_data.add("tool", tool)
toml_data["project"] = project
toml_data["tool"] = tool
tomlkit.dump(toml_data, toml_file)
toml_file.close()
5 changes: 2 additions & 3 deletions src/ipm/utils/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

def build_ipk(ipk: InfiniProject, echo: bool = False) -> InfiniFrozenPackage:
update("构建开发环境...", echo)
project = InfiniProject()

arcname = f"{project.name}-{project.version}"
arcname = f"{ipk.name}-{ipk.version}"
build_dir = ipk._source_path.joinpath(".ipm-build")
arc_dir = build_dir.joinpath(arcname)
src_path = ipk._source_path / "src"
Expand Down Expand Up @@ -58,7 +57,7 @@ def build_ipk(ipk: InfiniProject, echo: bool = False) -> InfiniFrozenPackage:
echo,
)

return InfiniFrozenPackage(ifp_path, ipk.name, version=project.version)
return InfiniFrozenPackage(ifp_path, ipk.name, version=ipk.version)


def extract_ipk(
Expand Down

0 comments on commit 4e053ae

Please sign in to comment.