Skip to content

Commit

Permalink
use uv.workspace.members table
Browse files Browse the repository at this point in the history
  • Loading branch information
carderne committed Aug 27, 2024
1 parent 4edd526 commit a35a5a9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 25 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ And start your workspace:
```bash
uv init unarepo # choose another name if you prefer
cd unarepo
git init
uv add --dev una
```

Then setup the Una workspace. This will generate a structure and an example lib and app.
```
uv run una create workspace
rm -rf src
uv sync
```

Expand Down Expand Up @@ -92,7 +94,7 @@ It didn't add `cowsay-python`, as external dependencies are only resolved at bui

Now you can build your app:
```bash
uvx --from build pyproject-build --installer uv apps/printer
uvx --from build pyproject-build --installer=uv --outdir=dist apps/printer
# this will inject the cowsay-python externel dependency
```

Expand Down
28 changes: 6 additions & 22 deletions una/una/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,21 @@ def get_ns(path: Path) -> str:


def get_members(path: Path) -> list[str]:
return load_conf(path).tool.una.members
return load_conf(path).tool.uv.members


def get_workspace_root() -> Path:
cwd = Path.cwd()
root = _find_upwards_dir(cwd, consts.ROOT_FILE)
root = _find_upwards(Path.cwd(), consts.ROOT_FILE)
if not root:
raise ValueError("Didn't find the workspace root. Expected to find a .git directory.")
return root


def _is_drive_root(cwd: Path) -> bool:
return cwd == Path(cwd.root) or cwd == cwd.parent


def _is_repo_root(cwd: Path) -> bool:
fullpath = cwd / consts.ROOT_FILE
return fullpath.exists()
return root.parent


def _find_upwards(cwd: Path, name: str) -> Path | None:
if _is_drive_root(cwd):
if cwd == Path(cwd.root) or cwd == cwd.parent:
return None
fullpath = cwd / name
if fullpath.exists():
elif (fullpath := cwd / name).exists():
return fullpath
if _is_repo_root(cwd):
elif (cwd / consts.ROOT_FILE).exists():
return None
return _find_upwards(cwd.parent, name)


def _find_upwards_dir(cwd: Path, name: str) -> Path | None:
fullpath = _find_upwards(cwd, name)
return fullpath.parent if fullpath else None
3 changes: 2 additions & 1 deletion una/una/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ def _update_root_pyproj(path: Path, ns: str, dependencies: str) -> None:
with pyproj.open() as f:
toml = tomlkit.parse(f.read())

toml.pop("project") # pyright:ignore[reportUnknownMemberType]
toml.pop("build-system") # pyright:ignore[reportUnknownMemberType]
toml["tool"]["uv"]["workspace"] = {"members": _EXAMPLE_MEMBERS} # pyright:ignore[reportIndexIssue]
toml["tool"]["una"] = {"members": _EXAMPLE_MEMBERS} # pyright:ignore[reportIndexIssue]
with pyproj.open("w") as f:
f.write(tomlkit.dumps(toml)) # pyright:ignore[reportUnknownMemberType]
8 changes: 7 additions & 1 deletion una/una/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,20 @@ def _default_members() -> list[str]:

@dataclass_json
@dataclass(frozen=True)
class Una:
class Uv:
members: list[str] = field(default_factory=_default_members)


@dataclass_json
@dataclass(frozen=True)
class Una:
deps: dict[str, str] = field(default_factory=dict)


@dataclass_json
@dataclass(frozen=False)
class Tool:
uv: Uv = field(default_factory=Uv)
una: Una = field(default_factory=Una)


Expand Down

0 comments on commit a35a5a9

Please sign in to comment.