From df8eabb3ef705e0807b863db2a0c99061f691bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20FARKAS?= Date: Tue, 12 Apr 2022 06:39:55 +0200 Subject: [PATCH] Add cross-platform justfile example (#1152) --- README.md | 2 ++ examples/cross-platform.just | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 examples/cross-platform.just diff --git a/README.md b/README.md index d867a17..2f23adf 100644 --- a/README.md +++ b/README.md @@ -893,6 +893,8 @@ $ just system-info This is an x86_64 machine ``` +The `os_family()` function can be used to create cross-platform `justfile`s that work on various operating systems. For an example, see [cross-platform.just](examples/cross-platform.just) file. + #### Environment Variables - `env_var(key)` — Retrieves the environment variable with name `key`, aborting if it is not present. diff --git a/examples/cross-platform.just b/examples/cross-platform.just new file mode 100644 index 0000000..4617d41 --- /dev/null +++ b/examples/cross-platform.just @@ -0,0 +1,26 @@ +# use with https://github.com/casey/just +# +# Example cross-platform Python project +# + +python_dir := if os_family() == "windows" { "./.venv/Scripts" } else { "./.venv/bin" } +python := python_dir + if os_family() == "windows" { "/python.exe" } else { "/python3" } +system_python := if os_family() == "windows" { "py.exe -3.9" } else { "python3.9" } + +# Set up development environment +bootstrap: + if test ! -e .venv; then {{ system_python }} -m venv .venv; fi + {{ python }} -m pip install --upgrade pip wheel pip-tools + {{ python_dir }}/pip-sync + +# Upgrade Python dependencies +upgrade-deps: && bootstrap + {{ python_dir }}/pip-compile --upgrade + +# Sample project script 1 +script1: + {{ python }} script1.py + +# Sample project script 2 +script2 *ARGS: + {{ python }} script2.py {{ ARGS }}