Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use package name from metadata file as package name #4

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/monas/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def bump(
info(f"Will bump version for [primary]{len(packages)}[/] package(s)")
for pkg in packages:
console.print(
f" [primary]{pkg.path.name}[/] [succ]{pkg.version}[/] -> "
f" [primary]{pkg.name}[/] [succ]{pkg.version}[/] -> "
f"[succ]{version}[/]"
)
if not Confirm.ask("Continue?", console=console, default=True):
Expand Down
4 changes: 2 additions & 2 deletions src/monas/commands/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def list_packages(
"""List the packages."""
if json:
data = [
{"name": pkg.path.name, "version": pkg.version, "path": pkg.path.as_posix()}
{"name": pkg.name, "version": pkg.version, "path": pkg.path.as_posix()}
for pkg in packages
]
console.print_json(data=data)
Expand All @@ -76,7 +76,7 @@ def list_packages(
table.add_column("Version")
table.add_column("Path", overflow="fold")
for pkg in packages:
row = [f"[primary]{pkg.path.name}[/]"]
row = [f"[primary]{pkg.name}[/]"]
if long:
row.append(f"[succ]{pkg.version}[/]")
row.append(f"[info]{pkg.path.relative_to(pkg.config.path).as_posix()}[/]")
Expand Down
4 changes: 2 additions & 2 deletions src/monas/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def install(config: Config, *, concurrency: int, root: bool, **kwargs: Any) -> N
def _on_complete(project: PyPackage, future: Future) -> None:
if future.exception():
console.print(
f" [red bold]FAIL[/] {project.path.name} {future.exception()}"
f" [red bold]FAIL[/] {project.name} {future.exception()}"
)
errors.append(future.exception())
else:
console.print(f" [succ]SUCC[/] {project.path.name}")
console.print(f" [succ]SUCC[/] {project.name}")

with console.status(
f"Installing [primary]{package_count}[/] package(s)", spinner="point"
Expand Down
2 changes: 1 addition & 1 deletion src/monas/commands/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def new(
"""
if location is None:
location = config.package_paths[0]
if any(package == pkg.path.name for pkg in config.iter_packages()):
if any(package == pkg.name for pkg in config.iter_packages()):
raise click.BadParameter(f"{package} already exists")
package_path = Path(location, package).absolute()
repo = config.get_repo()
Expand Down
2 changes: 1 addition & 1 deletion src/monas/commands/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def publish(
index = f"[succ]{repository}[/]"
info(f"The following packages are to be built and published to {index}:")
for pkg in packages_to_publish:
console.print(f" [primary]{pkg.path.name}[/] [succ]{pkg.version}[/]")
console.print(f" [primary]{pkg.name}[/] [succ]{pkg.version}[/]")
if not Confirm.ask("Continue?", console=console, default=True):
ctx.abort()
dist = config.path / "dist"
Expand Down
5 changes: 5 additions & 0 deletions src/monas/metadata/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def version(self) -> str:
"""Get the project version"""
pass

@abc.abstractproperty
def package_name(self) -> str:
"""Get the project version"""
pass

@version.setter
def version(self, value: str) -> None:
"""Set the project version"""
Expand Down
4 changes: 4 additions & 0 deletions src/monas/metadata/pep621.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def _write(self) -> None:
def version(self) -> str:
return self._data["project"]["version"]

@property
def package_name(self) -> str:
return self._data["project"]["name"]

@version.setter
def version(self, value: str) -> None:
self._data["project"]["version"] = value
Expand Down
4 changes: 4 additions & 0 deletions src/monas/metadata/setupcfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ def _write(self) -> None:
def version(self) -> str:
return self._parser.get("metadata", "version")

@property
def package_name(self) -> str:
return self._parser.get("metadata", "name")

@version.setter
def version(self, value: str) -> None:
self._parser["metadata"]["version"] = value
Expand Down
7 changes: 6 additions & 1 deletion src/monas/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,15 @@ def _get_metadata(self) -> Metadata:
raise ValueError("Can't determine a metadata type from the pyproject.toml")
return cast(Type[Metadata], result)(self.path)

@property
def name(self) -> str:
"""Get the project name"""
return self.metadata.package_name

@property
def canonical_name(self) -> str:
"""Get the project name"""
return canonicalize_name(self.path.name)
return canonicalize_name(self.name)

@property
def version(self) -> str:
Expand Down
43 changes: 23 additions & 20 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,29 @@ def python_version():
@pytest.fixture()
def test_project(cli_run, project):
run_command(["git", "init"], cwd=str(project))
with mock.patch(
"monas.commands.new.ask_for",
side_effect=[
{
"name": "foo",
"version": "0.0.0",
"author": "John",
"author_email": "john@doe.me",
"description": "Test Project",
"license_expr": "MIT",
"homepage": "https://example.org",
"requires_python": ">=3.7",
"build_backend": backend,
}
for backend in ["setuptools(setup.cfg)", "pdm", "flit"]
],
):
cli_run(["new", "foo"], cwd=project, input="\n")
cli_run(["new", "bar"], cwd=project, input="\n")
cli_run(["new", "foo-more", "extras"], cwd=project, input="\n")
projects = (
(("new", "foo"), "setuptools(setup.cfg)"),
(("new", "bar"), "pdm"),
(("new", "foo-more", "extras"), "flit"),
)
for cli_args, backend in projects:
with mock.patch(
"monas.commands.new.ask_for",
side_effect=[
{
"name": cli_args[1],
"version": "0.0.0",
"author": "John",
"author_email": "john@doe.me",
"description": "Test Project",
"license_expr": "MIT",
"homepage": "https://example.org",
"requires_python": ">=3.7",
"build_backend": backend,
}
],
):
cli_run(cli_args, cwd=project, input="\n")
run_command(["git", "add", "."], cwd=str(project))
run_command(["git", "commit", "-m", "Initial commit"], cwd=str(project))
return project