Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cnpryer committed May 4, 2024
1 parent 8612f0b commit 4f2fb5d
Show file tree
Hide file tree
Showing 3 changed files with 304 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The goal is to create an opinionated tool to support a reliably inviting onboard

- [Installation](#installation)
- [Usage](#usage)
- [Documentation](https://cnpryer.github.io/huak/user_guide/)
- [Goals and Motivation](#goals)
- [Contributing](#contributing)

Expand Down
11 changes: 11 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Huak

A Python package manager written in Rust inspired by Cargo.

!!! Warning
`huak` is in an experimental state.

## Contents

* [User Guide](./user_guide.md)

292 changes: 292 additions & 0 deletions docs/user_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
# User Guide

!!! Warning
`huak` is in an experimental state.

## Contents

1. [Getting started](#getting-started)
1. [Manage your dependencies](#manage-your-dependencies)
1. [Support more of your workflow](#support-more-of-your-workflow)
1. [Distribute your project](#distribute-your-project)
1. [Configure Huak](#configure-huak)

## Getting started

### Installation

> ⚠️ WARNING: The PyPI distribution is outdated. Until it is updated you'll need to install `huak` from source.
```
cargo install --git https://github.com/cnpryer/huak.git huak
```

Then add "$HOME/.huak/bin" to your path.

### Create a new project

To create a new project use the `new` command.

```zsh
~/github
❯ huak new my-project
```

### Or initialize an existing project

```zsh
~/github/existing-project
❯ huak init
```

`huak` distinguishes between library and application-like projects. Projects default to the library type if a type isn't specified. Specify the type with either the `--lib` or `--app` flag.

Initializing an existing project adds a `pyproject.toml` to the current directory. Bootstrapping the project with the `new` command creates a Python project with the following structure:

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ tree .
.
β”œβ”€β”€ pyproject.toml
β”œβ”€β”€ src
β”‚Β Β  └── my_project
β”‚Β Β  └── __init__.py
└── tests
└── test_version.py
```

!!! note
Without `--no-vcs` `huak` generates a `git`-initialized project.

## Manage your dependencies

### Add a dependency

Use `huak` to add dependencies to your Python project.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak add xlcsv
```

#### Installer Options

Currently `huak` uses `pip` under the hood for package installation. You can pass additional arguments onto `pip`. Any arguments after `--` are handed off to `pip install`.

Note that `huak` will use `uv` instead of `pip` in the future (see [this issue](https://github.com/cnpryer/huak/issues/890) for any updates).

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak add torch torchvision torchaudio -- --extra-index-url https://download.pytorch.org/whl/cu117
```

`huak` will add the packages to your pyproject.toml, so passing [PEP 508](https://peps.python.org/pep-0508/) strings would help persist this behavior for future installs.

!!! Tip
You can also assign dependencies to a group using `--group`.

### Manually trigger dependency installation

Use the `init` command again to install the project's dependencies.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak init
```

#### Use optional dependency groups

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak add --group my-group
```

### Update dependencies

To update a dependency use the `update` command.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak update xlcsv
```

Or attempt to update everything.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak update
```

### Remove dependencies

To remove a dependency from the project use the `remove` command.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak remove xlcsv
```

## Support more of your workflow

Huak ships commands allowing you to format your python code, lint it, and test it.

### Format your code

Use the `fmt` command to format your Python project's code.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak fmt
```

#### Using --check

!!! Warning
As of `v0.0.20` `huak` no longer uses `black`.

Use `--check` if all you want to do is verify your code is already formatted. Note that `huak` currently uses `ruff` to format your code. This means that `--` can only pass options to `ruff`. Use the `[tool.ruff]` for more configuration.

!!! Warning
`huak` will exit prior to running with `--check` if your imports are not sorted. See [#510](https://github.com/cnpryer/huak/issues/510) for the status of this issue.

### Lint your code

Use the `lint` command to lint your Python project's code.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0 took 2s
❯ huak lint
```

The `--fix` flag can be used to address any auto-fixable issues.

`huak` wraps tools like `ruff` for some of its commands. To configure a wrapped tool such as `ruff` use the pyproject.toml file:

```toml
[tool.ruff]
# ...
```

`huak` also uses `mypy` for type-checking. To disable this behavior use `--no-types`.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0 took 2s
❯ huak lint --no-types
```

!!! Note
Currently, since `ruff` is the default tool used by `huak lint`, passing additional options with `--` is reserved for `ruff`. To configure `mypy` use the `[tool.mypy]` approach. This limitation will be addressed in future versions of `huak` (see [#505](https://github.com/cnpryer/huak/issues/505)).

### Test your code

Use the `test` command to test your project.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak test
```

### Run commands within your project's environment context

You can use `huak` to run a command within the Python environment your project uses.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak run which python
/Users/chrispryer/github/my-project/.venv/bin/python
```

### Activate the virtual environment

`huak` also implements an `activate` command to activate a virtual environment.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak activate

(.venv) bash-3.2$
```

!!! Note
Currently `huak` just runs `bash --init-file` on unix systems and uses `powershell` on Windows.
```powershell
(.venv) PS C:\Users\chris\github\my-project>
```
See [#486](https://github.com/cnpryer/huak/issues/486) for the status on the `activate` command.

## Manage your Python installations

By default `huak` will use the first Python interpreter found from your `PATH` environment variable. You can `list` these by using the `python` command.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak python list
1: /Users/chrispryer/.pyenv/shims/python3.11
2: /Users/chrispryer/.pyenv/shims/python3.10
...
```

So `huak` would use `/Users/chrispryer/.pyenv/shims/python3.11` out of the box. You can use a different installed Python version with `use`.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak python use 3.10
```

## Distribute your project

### Publish to PyPI

If you're building a Python package you'd like to share, use `huak build` and `huak publish` to build and publish the project to [PyPI](https://pypi.org).

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak build

my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak publish
```

### Cleaning up

Use `huak clean` to clean out the dist/ directory.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0 took 26s
❯ huak clean
```

## Configure Huak

### Configure shell completion

With `huak completion` you can setup shell completion for `huak`.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak completion -h
Generates a shell completion script for supported shells. See the help menu for more information on supported shells

Usage: huak completion [OPTIONS]

Options:
-s, --shell <shell> [possible values: bash, elvish, fish, powershell, zsh]
-u, --uninstall Uninstalls the completion script from your shell init file. If this flag is passed the --shell is required
-h, --help Print help
```

Add `huak completion --shell <shell>` to your shell's initialization to use this feature.

```zsh
eval "$(huak completion --shell <shell>)"
```

## Providing feedback

Any bugs or suggestions can be submitted as issues [here](https://github.com/cnpryer/huak/issues/new). All feedback is welcome and greatly appreciated ❀️.

```zsh
my-project on master πŸ“¦ v0.0.1 via 🐍 v3.11.0
❯ huak --version
huak 0.0.20
```

0 comments on commit 4f2fb5d

Please sign in to comment.