|
| 1 | ++++ |
| 2 | +title = '' |
| 3 | +date = 2024-04-06T22:34:36+05:30 |
| 4 | +draft = false |
| 5 | +toc = true |
| 6 | +[cascade] |
| 7 | + type = 'docs' |
| 8 | ++++ |
| 9 | + |
| 10 | +# Documentation for `hugo-python-distributions` |
| 11 | + |
| 12 | +This webpage is meant to serve the documentation for the `hugo-python-distributions` project, which aims to provide a distribution |
| 13 | +channel for the extended version of the Hugo static site generator through `pip`-installable binaries (wheels) hosted on the [Python Package Index (PyPI)](https://pypi.org/). |
| 14 | + |
| 15 | +## Table of contents |
| 16 | + |
| 17 | +- [Quickstart](#quickstart) |
| 18 | +- [Supported platforms](#supported-platforms) |
| 19 | +- [Building from sources](building-from-sources/) |
| 20 | + - [Cross-compiling for different architectures](#cross-compiling-for-different-architectures) |
| 21 | + - [macOS](#macos) |
| 22 | + - [Linux](#linux) |
| 23 | + - [Windows](#windows) |
| 24 | + |
| 25 | + |
| 26 | +### Quickstart |
| 27 | + |
| 28 | +Create a [virtual environment](https://realpython.com/python-virtual-environments-a-primer/) and install the package (or install it globally on your system): |
| 29 | + |
| 30 | +{{< tabs items="Linux/macOS,Windows" >}} |
| 31 | + |
| 32 | + {{< tab >}} |
| 33 | + ```bash |
| 34 | + python -m virtualenv venv |
| 35 | + source venv/bin/activate |
| 36 | + python -m pip install hugo |
| 37 | + ``` |
| 38 | + {{< /tab >}} |
| 39 | + |
| 40 | + {{< tab >}} |
| 41 | + ```powershell |
| 42 | + py -m virtualenv venv |
| 43 | + venv\Scripts\activate.bat |
| 44 | + py -m pip install hugo |
| 45 | + ``` |
| 46 | + {{< /tab >}} |
| 47 | + |
| 48 | +{{< /tabs >}} |
| 49 | + |
| 50 | +This example is using [`virtualenv`](https://virtualenv.pypa.io/en/latest/) to create a virtual environment, however, you can use any virtual environment manager of your choice. Some popular ones are the built-in [`venv`](https://docs.python.org/3/library/venv.html) module, [`virtualenvwrapper`](https://virtualenvwrapper.readthedocs.io/en/latest/), [`pipenv`](https://pipenv.pypa.io/en/latest/), [`conda`](https://docs.conda.io/en/latest/), [`poetry`](https://python-poetry.org/), [`pyenv`](https://github.com/pyenv/pyenv), [`uv`](https://github.com/astral-sh/uv), and so on. |
| 51 | + |
| 52 | +This places a `hugo` installation with an executable in your virtual environment and adds an [entry point](https://packaging.python.org/en/latest/specifications/entry-points/) to it in your virtual environment's `bin` directory. |
| 53 | + |
| 54 | +Then, you can use the `hugo` CLI commands as you would normally: |
| 55 | + |
| 56 | +```bash |
| 57 | +hugo version |
| 58 | +hugo env --logLevel info |
| 59 | +hugo new site my-new-site |
| 60 | +hugo mod <...> |
| 61 | +hugo --printI18nWarnings --buildDrafts server |
| 62 | +``` |
| 63 | + |
| 64 | +and more! |
| 65 | + |
| 66 | +Alternatively, you can install the package globally on your system: |
| 67 | + |
| 68 | +{{< tabs items="Linux/macOS,Windows" >}} |
| 69 | + |
| 70 | + {{< tab >}} |
| 71 | + ```bash |
| 72 | + python3.X -m pip install hugo |
| 73 | + ``` |
| 74 | + {{< /tab >}} |
| 75 | + |
| 76 | + {{< tab >}} |
| 77 | + ```powershell |
| 78 | + py -m pip install hugo |
| 79 | + ``` |
| 80 | + {{< /tab >}} |
| 81 | + |
| 82 | +{{< /tabs >}} |
| 83 | + |
| 84 | +{{< callout emoji=✨ >}} |
| 85 | + |
| 86 | +It is a great idea to use [`pipx`](https://github.com/pypa/pipx) to install or use Hugo in an isolated location without having to create a virtual environment, which will allow you to run Hugo as a command-line tool without having to install it globally on your system. |
| 87 | + |
| 88 | +{{</ callout >}} |
| 89 | + |
| 90 | + |
| 91 | +{{< tabs items="Install it as an app globally, Run it" >}} |
| 92 | + |
| 93 | + {{< tab >}} |
| 94 | + ```bash |
| 95 | + pipx install hugo |
| 96 | + ``` |
| 97 | + This installs Hugo in a separate location on your system that is isolated from your global Python environment(s). |
| 98 | + {{< /tab >}} |
| 99 | + |
| 100 | + {{< tab >}} |
| 101 | + ```bash |
| 102 | + pipx run hugo version |
| 103 | + pipx run hugo env --logLevel info |
| 104 | + ``` |
| 105 | + This runs the latest version of Hugo available on PyPI and installed through `pipx`. You can also run a specific version of Hugo through `pipx`, even if a different version is installed in whatever environment you are in: |
| 106 | + ```bash |
| 107 | + pipx run hugo==0.124.1 version |
| 108 | + pipx run hugo==0.124.1 env --logLevel info |
| 109 | + ``` |
| 110 | + {{< /tab >}} |
| 111 | + |
| 112 | +{{< /tabs >}} |
| 113 | + |
| 114 | +Please refer to the [`pipx` documentation](https://pipx.pypa.io/stable/) for more information. |
| 115 | + |
| 116 | +For more information on using Hugo and its command-line interface, please refer to the [Hugo documentation](https://gohugo.io/documentation/) and the [Hugo CLI documentation](https://gohugo.io/commands/). |
| 117 | + |
| 118 | +### Supported platforms |
| 119 | + |
| 120 | +A subset of the platforms supported by Hugo itself are supported by these wheels for `hugo` via `hugo-python-distributions`. The plan is to support as many platforms as possible with Python wheels and platform tags. Please refer to the following table for a list of supported platforms and architectures: |
| 121 | + |
| 122 | +| Platform | Architecture | Support | |
| 123 | +| -------- | --------------- | ------------------------------- | |
| 124 | +| macOS | x86_64 (Intel) | ✅ | |
| 125 | +| macOS | arm64 (Silicon) | ✅ | |
| 126 | +| Linux | amd64 | ✅ | |
| 127 | +| Linux | arm64 | ✅ | |
| 128 | +| Windows | x86_64 | ✅ | |
| 129 | +| Windows | arm64 | 💡 Experimental support [^1] | |
| 130 | +| Windows | x86 | 💡 Experimental support [^1] | |
| 131 | +| DragonFlyBSD | amd64 | ❌ Will not receive support[^2] | |
| 132 | +| FreeBSD | amd64 | ❌ Will not receive support[^2] | |
| 133 | +| OpenBSD | amd64 | ❌ Will not receive support[^2] | |
| 134 | +| NetBSD | amd64 | ❌ Will not receive support[^2] | |
| 135 | +| Solaris | amd64 | ❌ Will not receive support[^2] | |
| 136 | + |
| 137 | +[^1]: Support for 32-bit (i686) and arm64 architectures on Windows is made possible through the use of the [Zig compiler toolchain](https://ziglang.org/) that uses the LLVM ecosystem. These wheels are experimental owing to the use of `cibuildwheel` and cross-compilation and may not be stable or reliable for all use cases, and are not officially supported by the Hugo project at this time. Please refer to the [Building from source](#building-from-source) section for more information on how to build Hugo for these platforms and architectures, since these wheels are not currently pushed to PyPI for general availability – however, they are tested regularly in CI. If you need support for these platforms, please consider building from source or through a CI provider. |
| 138 | + |
| 139 | +[^2]: Support for these platforms is not possible to include because of i. the lack of resources to test and build for them and ii. the lack of support for these platform specifications in Python packaging standards and tooling. If you need support for these platforms, please consider downloading the [official Hugo binaries](https://github.com/gohugoio/hugo/releases). |
| 140 | + |
| 141 | +#### Cross-compiling for different architectures |
| 142 | + |
| 143 | +{{< callout type="warning" >}} |
| 144 | +Cross-compilation is experimental and may not be stable or reliable for all use cases. If you encounter any issues with cross-compilation, please feel free to [open an issue](https://github.com/agriyakhetarpal/hugo-python-distributions/issues/new). |
| 145 | +{{</ callout >}} |
| 146 | + |
| 147 | +This project is capable of cross-compiling Hugo binaries for various platforms and architectures and it can be used as follows. Cross-compilation is provided for the following platforms: |
| 148 | + |
| 149 | +1. macOS for the `arm64` and `amd64` architectures via the Xcode toolchain, |
| 150 | +2. Linux for the `arm64` and `amd64` architectures via the Zig toolchain, and |
| 151 | +3. Windows for the `arm64`, and `x86` architectures via the Zig toolchain. |
| 152 | + |
| 153 | +Please refer to the examples below for more information on how to cross-compile Hugo for different architectures: |
| 154 | + |
| 155 | +##### macOS |
| 156 | + |
| 157 | +Say, on an Intel-based (x86_64) macOS machine: |
| 158 | + |
| 159 | +```bash |
| 160 | +export GOARCH="arm64" |
| 161 | +pip install . # or pip install -e . |
| 162 | +``` |
| 163 | + |
| 164 | +This will build a macOS `arm64` binary distribution of Hugo that can be used on Apple Silicon-based (`arm64`) macOS machines. To build a binary distribution for the _target_ Intel-based (`x86_64`) macOS platform on the _host_ Apple Silicon-based (`arm64`) macOS machine, you can use the following command: |
| 165 | + |
| 166 | +```bash |
| 167 | +export GOARCH="amd64" |
| 168 | +pip install . # or pip install -e . |
| 169 | +``` |
| 170 | + |
| 171 | +##### Linux |
| 172 | + |
| 173 | +First, install [Zig](https://ziglang.org/download/) on your Linux machine, and set these environment variables prior to installing the package: |
| 174 | + |
| 175 | +Say, on an `amd64` Linux machine: |
| 176 | + |
| 177 | +```bash |
| 178 | +export CC="zig cc -target aarch64-linux-gnu" |
| 179 | +export CXX="zig c++ -target aarch64-linux-gnu" |
| 180 | +export GOARCH="arm64" |
| 181 | +pip install . # or pip install -e . |
| 182 | +``` |
| 183 | + |
| 184 | +will cross-compile a Linux arm64 binary distribution of Hugo that can be used on the targeted arm64 Linux machines. To build a binary distribution for the _target_ `amd64` Linux platform on the _host_ `arm64` Linux machine, set the targets differently: |
| 185 | + |
| 186 | +```bash |
| 187 | +export CC="zig cc -target x86_64-linux-gnu" |
| 188 | +export CXX="zig c++ -target x86_64-linux-gnu" |
| 189 | +export GOARCH="amd64" |
| 190 | +pip install . # or pip install -e . |
| 191 | +``` |
| 192 | + |
| 193 | +This creates dynamic linkage for the built Hugo binary with a system-provided GLIBC. If you wish to statically link the binary with MUSL, change the `CC` and `CXX` environment variables as follows: |
| 194 | + |
| 195 | +```bash |
| 196 | +export CC="zig cc -target x86_64-linux-musl" |
| 197 | +export CXX="zig c++ -target x86_64-linux-musl" |
| 198 | +``` |
| 199 | + |
| 200 | +Linkage against MUSL is not tested in CI at this time, but it should work in theory. The official Hugo binaries do not link against MUSL for a variety of reasons including but not limited to the size of the binary and the popularity of the GLIBC C standard library and its conventions. |
| 201 | + |
| 202 | +##### Windows |
| 203 | + |
| 204 | +First, install [Zig](https://ziglang.org/download/) on your Windows machine, and set these environment variables prior to installing the package: |
| 205 | + |
| 206 | +Say, on an `amd64` Windows machine: |
| 207 | + |
| 208 | +```bash |
| 209 | +set CC="zig cc -target aarch64-windows-gnu" |
| 210 | +set CXX="zig c++ -target aarch64-windows-gnu" |
| 211 | +set GOARCH="arm64" |
| 212 | +pip install . # or pip install -e . |
| 213 | +``` |
| 214 | + |
| 215 | +will cross-compile a Windows `arm64` binary distribution of Hugo that can be used on the targeted `arm64` Windows machines (note the use of `set` instead of `export` on Windows), and so on for the `x86` architecture: |
| 216 | + |
| 217 | +```bash |
| 218 | +set CC="zig cc -target x86-windows-gnu" |
| 219 | +set CXX="zig c++ -target x86-windows-gnu" |
| 220 | +set GOARCH="386" |
| 221 | +pip install . # or pip install -e . |
| 222 | +``` |
| 223 | + |
| 224 | +For a list of supported distributions for Go, please run the `go tool dist list` command on your system. For a list of supported targets for Zig, please refer to the [Zig documentation](https://ziglang.org/documentation/) for more information or run the `zig targets` command on your system. |
| 225 | + |
| 226 | +> [!TIP] |
| 227 | +> Cross-compilation for a target platform and architecture from a different host platform and architecture is also possible, but it remains largely untested at this time. Currently, the [Zig compiler toolchain](https://ziglang.org/) is known to work for cross-platform, cross-architecture compilation. |
0 commit comments