Allow specifying a name for the package

Default to repo name
This commit is contained in:
IamTheFij 2024-11-06 16:16:27 -08:00
parent bb0b82ab72
commit 7380fa99ec

View File

@ -18,11 +18,10 @@ from wheel.wheelfile import WheelFile
import release_gitter as rg import release_gitter as rg
from release_gitter import removeprefix from release_gitter import removeprefix
PACKAGE_NAME = "pseudo"
@dataclass @dataclass
class Config: class Config:
name: str
format: str format: str
git_url: str git_url: str
hostname: str hostname: str
@ -64,34 +63,36 @@ def download(config: Config, wheel_scripts: Path) -> list[Path]:
def read_metadata() -> Config: def read_metadata() -> Config:
config = toml.load("pyproject.toml").get("tool", {}).get("release-gitter") """Read configuration from pyproject.toml"""
if not config: pyproject = toml.load("pyproject.toml").get("tool", {}).get("release-gitter")
if not pyproject:
raise ValueError("Must have configuration in [tool.release-gitter]") raise ValueError("Must have configuration in [tool.release-gitter]")
git_url = config.pop("git-url", None) git_url = pyproject.pop("git-url", None)
remote_info = rg.parse_git_remote(git_url) remote_info = rg.parse_git_remote(git_url)
args = Config( config = Config(
format=config.pop("format"), name=pyproject.pop("name", remote_info.repo),
format=pyproject.pop("format"),
git_url=git_url, git_url=git_url,
hostname=config.pop("hostname", remote_info.hostname), hostname=pyproject.pop("hostname", remote_info.hostname),
owner=config.pop("owner", remote_info.owner), owner=pyproject.pop("owner", remote_info.owner),
repo=config.pop("repo", remote_info.repo), repo=pyproject.pop("repo", remote_info.repo),
) )
for key, value in config.items(): for key, value in pyproject.items():
setattr(args, str(key).replace("-", "_"), value) setattr(config, str(key).replace("-", "_"), value)
if args.version is None: if config.version is None:
args.version = rg.read_version( config.version = rg.read_version(
args.version_git_tag, config.version_git_tag,
not args.version_git_no_fetch, not config.version_git_no_fetch,
) )
if args.extract_all: if config.extract_all:
args.extract_files = [] config.extract_files = []
return args return config
class _PseudoBuildBackend: class _PseudoBuildBackend:
@ -108,7 +109,7 @@ class _PseudoBuildBackend:
version = removeprefix(metadata.version, "v") if metadata.version else "0.0.0" version = removeprefix(metadata.version, "v") if metadata.version else "0.0.0"
# Returns distinfo dir? # Returns distinfo dir?
dist_info = Path(metadata_directory) / f"{PACKAGE_NAME}-{version}.dist-info" dist_info = Path(metadata_directory) / f"{metadata.name}-{version}.dist-info"
dist_info.mkdir() dist_info.mkdir()
# Write metadata # Write metadata
@ -117,7 +118,7 @@ class _PseudoBuildBackend:
"\n".join( "\n".join(
[ [
"Metadata-Version: 2.1", "Metadata-Version: 2.1",
f"Name: {PACKAGE_NAME}", f"Name: {metadata.name}",
f"Version: {version}", f"Version: {version}",
] ]
) )
@ -149,6 +150,8 @@ class _PseudoBuildBackend:
def build_wheel( def build_wheel(
self, wheel_directory, config_settings=None, metadata_directory=None self, wheel_directory, config_settings=None, metadata_directory=None
): ):
if metadata_directory is None:
raise ValueError("Cannot build wheel without metadata_directory")
metadata_directory = Path(metadata_directory) metadata_directory = Path(metadata_directory)
metadata = read_metadata() metadata = read_metadata()
@ -157,7 +160,7 @@ class _PseudoBuildBackend:
wheel_directory = Path(wheel_directory) wheel_directory = Path(wheel_directory)
wheel_directory.mkdir(exist_ok=True) wheel_directory.mkdir(exist_ok=True)
wheel_scripts = wheel_directory / f"{PACKAGE_NAME}-{version}.data/scripts" wheel_scripts = wheel_directory / f"{metadata.name}-{version}.data/scripts"
wheel_scripts.mkdir(parents=True, exist_ok=True) wheel_scripts.mkdir(parents=True, exist_ok=True)
copytree(metadata_directory, wheel_directory / metadata_directory.name) copytree(metadata_directory, wheel_directory / metadata_directory.name)
@ -176,11 +179,11 @@ class _PseudoBuildBackend:
print(f"ls {wheel_directory}: {list(wheel_directory.rglob('*'))}") print(f"ls {wheel_directory}: {list(wheel_directory.rglob('*'))}")
wheel_filename = f"{PACKAGE_NAME}-{version}-py2.py3-none-any.whl" wheel_filename = f"{metadata.name}-{version}-py2.py3-none-any.whl"
with WheelFile(wheel_directory / wheel_filename, "w") as wf: with WheelFile(wheel_directory / wheel_filename, "w") as wf:
print("Repacking wheel as {}...".format(wheel_filename), end="") print("Repacking wheel as {}...".format(wheel_filename), end="")
# sys.stdout.flush() # sys.stdout.flush()
wf.write_files(wheel_directory) wf.write_files(str(wheel_directory))
return wheel_filename return wheel_filename