una


Nameuna JSON
Version 0.5.2 PyPI version JSON
download
home_pageNone
SummaryPython monorepo tooling
upload_time2024-08-31 20:15:06
maintainerNone
docs_urlNone
authorNone
requires_python>=3.11
licenseMIT License
keywords build monorepo python uv
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Una

<div align="center">
  <img src="https://raw.githubusercontent.com/carderne/una/main/docs/assets/logo.svg" alt="Una logo" width="100" role="img">
  <p>Easy monorepos with Python and uv</p>
</div>

----
<div align="center">

<a href="https://pypi.org/project/una/">
<img alt="pypi" src="https://img.shields.io/pypi/v/una.svg?logo=pypi&label=PyPI&logoColor=gold">
</a>
<a href="https://una.rdrn.me/">
<img alt="docs" src="https://img.shields.io/badge/Docs-gray?logo=materialformkdocs&logoColor=white">
</a>
<a href="https://github.com/carderne/una">
<img alt="GitHub" src="https://img.shields.io/badge/GitHub-una-blue?logo=github">
</a>

</div>

**This is a new project that is still evolving. I'm very open to ideas, suggestions and feedback. Please open an [issue](https://github.com/carderne/una/issues/new) with your comments.**

Una is a tool to build and productionise Python monorepos with [uv](https://docs.astral.sh/uv/).

uv has [Workspaces](https://docs.astral.sh/uv/concepts/workspaces/), but no ability to _build_ them.
This means if you have dependencies between packages in your workspace, there's no good way to distribute or productionise the end result.

Una solves this.
No additional configuration is needed: if you have a functional uv Workspace, just add Una.
It consists of the following two things:

1. A CLI to ensure that all imports are correctly specified as dependencies.
2. A build plugin that enables production builds of individual apps within a monorepo by injecting local dependencies and transitive third-party dependencies.

Una doesn't try to replicate a full build system such as [Bazel](https://bazel.build/) or
[Pants](https://www.pantsbuild.org/).
It just makes it possible to have a simple monorepo with interdependencies.

Una works much like a Rust workspace, with each package having its own pyproject.toml.
In general, packages should either be libraries (imported but not run) or apps (run but never imported), but Una will not enforce this.

It only works with the [Hatch](https://hatch.pypa.io) build backend.

## Examples
You can see an example repo here:

- [una-example](https://github.com/carderne/una-example)

## Quickstart
This will give you a quick view of how this all works.

First install uv:
```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```

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.
```bash
uv run una create workspace
rm -rf src
uv sync
```

Have a look at what's been generated:
```bash
tree
```

Have a look at the generated `__init__.py` files in the `apps/printer` and `libs/greeter` packages.
An external dependency ([cowsay-python](https://pypi.org/project/cowsay-python/)) has also been added to the latter's `pyproject.toml`.

The magic of Una then comes in to resolve the graph of direct and transitive dependencies, which looks like this:
```elm
printer --> greeter --> cowsay-python
```

You can do this by running the following:
```bash
# this checks all imports and ensures they are added to
# project.dependencies and tool.uv.sources in the each pyproject.toml
uv run una sync
```

Have a look at what happened:
```bash
tail apps/printer/pyproject.toml
```

It added `greeter` as an internal dependency to `printer`.
It didn't add `cowsay-python`, as transitive external dependencies are only resolved at build-time.

Now you can build your app. Note that you **must** specify the `--wheel` parameter. Una doesn't currently work for builds that do source -> sdist -> wheel, as these break some things with uv virtual envs.
```bash
uvx --from build pyproject-build --installer=uv \
    --outdir=dist --wheel apps/printer
# this will inject the cowsay-python external dependency
```

And see the result:
```bash
ls dist/
```

And you can do whatever you want with that wheel!
What about stick it in a Dockerfile, have you ever seen such a simple one?
```Dockerfile
FROM python
COPY dist dist
RUN pip install dist/*.whl
```

And run it:
```bash
docker build --tag unarepo-printer .
docker run --rm -it unarepo-printer python -c 'from unarepo.printer import run; run()'
```

## Installation
The CLI tool isn't strictly necessary, as all the stuff that lets the monorepo builds work is in the separate (and tiny) [hatch-una](plugins/hatch) package.
But you will likely struggle to manage your monorepo without the tool!

So you may as well install it:
```bash
uv add --dev una
```

As for the build-time `hatch-una`, it will automatically be installed by build tools when it spots this in your `pyproject.toml` (this will be configured automatically by the CLI):
```toml
[build-system]
requires = ["hatchling", "hatch-una"]
build-backend = "hatchling.build"
```

## Usage
The CLI has a few commands and options, have a look:
```bash
uv run una --help

 Usage: una [OPTIONS] COMMAND [ARGS]...

╭─ Options ─────────────────────────────────────────────╮
│ --help          Show this message and exit.           │
╰───────────────────────────────────────────────────────╯
╭─ Commands ────────────────────────────────────────────╮
│ create   Commands for creating workspace and packages.│
│ sync     Update packages with missing dependencies.   │
╰───────────────────────────────────────────────────────╯
```

## Documentation

Read more at [the official documentation](https://una.rdrn.me/).

It covers additional things like:
- [type-checking](https://una.rdrn.me/types-tests/), testing, editor integration
- and more!

## Contributing
See the instructions at the [official documentation](https://una.rdrn.me/contributing/).

Very briefly, local development is with uv:
```bash
uv sync
make all  # will fmt, lint, typecheck and test
```

Then open a PR.

## License
Una is distributed under the terms of the MIT license.
Some code is from the [python-polylith](https://github.com/DavidVujic/python-polylith) project (c) 2022 David Vujic

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "una",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": null,
    "keywords": "build, monorepo, python, uv",
    "author": null,
    "author_email": "Chris Arderne <chris@rdrn.me>",
    "download_url": "https://files.pythonhosted.org/packages/f1/2c/34135a278bdd030d691cb6e20e5b541d21bd953ed8bb9aaa4d9d65f32276/una-0.5.2.tar.gz",
    "platform": null,
    "description": "# Una\n\n<div align=\"center\">\n  <img src=\"https://raw.githubusercontent.com/carderne/una/main/docs/assets/logo.svg\" alt=\"Una logo\" width=\"100\" role=\"img\">\n  <p>Easy monorepos with Python and uv</p>\n</div>\n\n----\n<div align=\"center\">\n\n<a href=\"https://pypi.org/project/una/\">\n<img alt=\"pypi\" src=\"https://img.shields.io/pypi/v/una.svg?logo=pypi&label=PyPI&logoColor=gold\">\n</a>\n<a href=\"https://una.rdrn.me/\">\n<img alt=\"docs\" src=\"https://img.shields.io/badge/Docs-gray?logo=materialformkdocs&logoColor=white\">\n</a>\n<a href=\"https://github.com/carderne/una\">\n<img alt=\"GitHub\" src=\"https://img.shields.io/badge/GitHub-una-blue?logo=github\">\n</a>\n\n</div>\n\n**This is a new project that is still evolving. I'm very open to ideas, suggestions and feedback. Please open an [issue](https://github.com/carderne/una/issues/new) with your comments.**\n\nUna is a tool to build and productionise Python monorepos with [uv](https://docs.astral.sh/uv/).\n\nuv has [Workspaces](https://docs.astral.sh/uv/concepts/workspaces/), but no ability to _build_ them.\nThis means if you have dependencies between packages in your workspace, there's no good way to distribute or productionise the end result.\n\nUna solves this.\nNo additional configuration is needed: if you have a functional uv Workspace, just add Una.\nIt consists of the following two things:\n\n1. A CLI to ensure that all imports are correctly specified as dependencies.\n2. A build plugin that enables production builds of individual apps within a monorepo by injecting local dependencies and transitive third-party dependencies.\n\nUna doesn't try to replicate a full build system such as [Bazel](https://bazel.build/) or\n[Pants](https://www.pantsbuild.org/).\nIt just makes it possible to have a simple monorepo with interdependencies.\n\nUna works much like a Rust workspace, with each package having its own pyproject.toml.\nIn general, packages should either be libraries (imported but not run) or apps (run but never imported), but Una will not enforce this.\n\nIt only works with the [Hatch](https://hatch.pypa.io) build backend.\n\n## Examples\nYou can see an example repo here:\n\n- [una-example](https://github.com/carderne/una-example)\n\n## Quickstart\nThis will give you a quick view of how this all works.\n\nFirst install uv:\n```bash\ncurl -LsSf https://astral.sh/uv/install.sh | sh\n```\n\nAnd start your workspace:\n```bash\nuv init unarepo   # choose another name if you prefer\ncd unarepo\ngit init\nuv add --dev una\n```\n\nThen setup the Una workspace. This will generate a structure and an example lib and app.\n```bash\nuv run una create workspace\nrm -rf src\nuv sync\n```\n\nHave a look at what's been generated:\n```bash\ntree\n```\n\nHave a look at the generated `__init__.py` files in the `apps/printer` and `libs/greeter` packages.\nAn external dependency ([cowsay-python](https://pypi.org/project/cowsay-python/)) has also been added to the latter's `pyproject.toml`.\n\nThe magic of Una then comes in to resolve the graph of direct and transitive dependencies, which looks like this:\n```elm\nprinter --> greeter --> cowsay-python\n```\n\nYou can do this by running the following:\n```bash\n# this checks all imports and ensures they are added to\n# project.dependencies and tool.uv.sources in the each pyproject.toml\nuv run una sync\n```\n\nHave a look at what happened:\n```bash\ntail apps/printer/pyproject.toml\n```\n\nIt added `greeter` as an internal dependency to `printer`.\nIt didn't add `cowsay-python`, as transitive external dependencies are only resolved at build-time.\n\nNow you can build your app. Note that you **must** specify the `--wheel` parameter. Una doesn't currently work for builds that do source -> sdist -> wheel, as these break some things with uv virtual envs.\n```bash\nuvx --from build pyproject-build --installer=uv \\\n    --outdir=dist --wheel apps/printer\n# this will inject the cowsay-python external dependency\n```\n\nAnd see the result:\n```bash\nls dist/\n```\n\nAnd you can do whatever you want with that wheel!\nWhat about stick it in a Dockerfile, have you ever seen such a simple one?\n```Dockerfile\nFROM python\nCOPY dist dist\nRUN pip install dist/*.whl\n```\n\nAnd run it:\n```bash\ndocker build --tag unarepo-printer .\ndocker run --rm -it unarepo-printer python -c 'from unarepo.printer import run; run()'\n```\n\n## Installation\nThe CLI tool isn't strictly necessary, as all the stuff that lets the monorepo builds work is in the separate (and tiny) [hatch-una](plugins/hatch) package.\nBut you will likely struggle to manage your monorepo without the tool!\n\nSo you may as well install it:\n```bash\nuv add --dev una\n```\n\nAs for the build-time `hatch-una`, it will automatically be installed by build tools when it spots this in your `pyproject.toml` (this will be configured automatically by the CLI):\n```toml\n[build-system]\nrequires = [\"hatchling\", \"hatch-una\"]\nbuild-backend = \"hatchling.build\"\n```\n\n## Usage\nThe CLI has a few commands and options, have a look:\n```bash\nuv run una --help\n\n Usage: una [OPTIONS] COMMAND [ARGS]...\n\n\u256d\u2500 Options \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n\u2502 --help          Show this message and exit.           \u2502\n\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n\u256d\u2500 Commands \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n\u2502 create   Commands for creating workspace and packages.\u2502\n\u2502 sync     Update packages with missing dependencies.   \u2502\n\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n```\n\n## Documentation\n\nRead more at [the official documentation](https://una.rdrn.me/).\n\nIt covers additional things like:\n- [type-checking](https://una.rdrn.me/types-tests/), testing, editor integration\n- and more!\n\n## Contributing\nSee the instructions at the [official documentation](https://una.rdrn.me/contributing/).\n\nVery briefly, local development is with uv:\n```bash\nuv sync\nmake all  # will fmt, lint, typecheck and test\n```\n\nThen open a PR.\n\n## License\nUna is distributed under the terms of the MIT license.\nSome code is from the [python-polylith](https://github.com/DavidVujic/python-polylith) project (c) 2022 David Vujic\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "Python monorepo tooling",
    "version": "0.5.2",
    "project_urls": {
        "homepage": "https://github.com/carderne/una",
        "repository": "https://github.com/carderne/una"
    },
    "split_keywords": [
        "build",
        " monorepo",
        " python",
        " uv"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "654bce430013f46d1b954bb3aa35f5c79f0be32602b584025f5783602ca23ec9",
                "md5": "bb4879311966d8c8443901f6f651ab71",
                "sha256": "92f9bdc63c1b4368467401b54995ffa9ae629a5db5f426caf0957bc6e1d68c77"
            },
            "downloads": -1,
            "filename": "una-0.5.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bb4879311966d8c8443901f6f651ab71",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 16024,
            "upload_time": "2024-08-31T20:15:04",
            "upload_time_iso_8601": "2024-08-31T20:15:04.561174Z",
            "url": "https://files.pythonhosted.org/packages/65/4b/ce430013f46d1b954bb3aa35f5c79f0be32602b584025f5783602ca23ec9/una-0.5.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f12c34135a278bdd030d691cb6e20e5b541d21bd953ed8bb9aaa4d9d65f32276",
                "md5": "74768cf927a69a79e7df115099036b98",
                "sha256": "20b4843fdf415dded53d62d2bccd848ba54d7e351f149974d1fca627f363fdf3"
            },
            "downloads": -1,
            "filename": "una-0.5.2.tar.gz",
            "has_sig": false,
            "md5_digest": "74768cf927a69a79e7df115099036b98",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 12417,
            "upload_time": "2024-08-31T20:15:06",
            "upload_time_iso_8601": "2024-08-31T20:15:06.139258Z",
            "url": "https://files.pythonhosted.org/packages/f1/2c/34135a278bdd030d691cb6e20e5b541d21bd953ed8bb9aaa4d9d65f32276/una-0.5.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-31 20:15:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "carderne",
    "github_project": "una",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "una"
}
        
Elapsed time: 0.48988s