Skip to content

Commit cf8aaf6

Browse files
feat(wsl2): auto-detect wsl2 and advise user
1 parent 940e423 commit cf8aaf6

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ Optionally customize your project if needed:
8989

9090
* pass arguments to linkml generators via 'config.yaml' configuration file;
9191
* pass supported environment variables via '.env.public' configuration file;
92+
* Set 'export JUST_TEMPDIR=/tmp' on WSL2.
9293

9394
Setup your project
9495

9596
```shell
9697
cd my-awesome-schema # using the folder example above
9798
just setup
9899
```
99-
Note: Command `JUST_TEMPDIR=/tmp just setup` may be needed in certain cases [ref](https://github.com/casey/just/?tab=readme-ov-file#script-and-shebang-recipe-temporary-files).
100100

101101
### Step 3: Edit the schema
102102

template/justfile

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
# ============ Variables used in recipes ============
88

9+
# Detect WSL2 variable
10+
_wsl2_check := `[ -n "${WSL_INTEROP:-}" ] && [ -z "${JUST_TEMPDIR:-}" ] && echo "ERROR" || echo "OK"`
11+
912
# Load environment variables from config.public.mk or specified file
1013
set dotenv-load := true
1114
# set dotenv-filename := env_var_or_default("LINKML_ENVIRONMENT_FILENAME", "config.public.mk")
@@ -44,11 +47,36 @@ distrib_schema_path := "docs/schema" # Directory for publishing schema artifact
4447

4548
# List all commands as default command. The prefix "_" hides the command.
4649
_default: _status
50+
@{{ if _wsl2_check == "ERROR" { "echo 'WSL2 detected: run export JUST_TEMPDIR=/tmp'" } else { "" } }}
4751
@just --list
4852

53+
# WSL2 status check - warns but does not abort (safe to use in _status/_default)
54+
[private]
55+
_wsl2_status_check:
56+
@if [ -n "${WSL_INTEROP:-}" ] && [ -z "${JUST_TEMPDIR:-}" ]; then \
57+
echo "WARNING: WSL2 detected but JUST_TEMPDIR is not set."; \
58+
echo "Shebang recipes will fail with 'Permission denied' errors."; \
59+
echo "Fix: run 'export JUST_TEMPDIR=/tmp'"; \
60+
fi
61+
62+
# WSL2 compatibility check - fails early with helpful message
63+
[private]
64+
_wsl2_compat_check:
65+
@if [ -n "${WSL_INTEROP:-}" ] && [ -z "${JUST_TEMPDIR:-}" ]; then \
66+
echo "ERROR: WSL2 detected but JUST_TEMPDIR is not set."; \
67+
echo "Shebang recipes will fail with 'Permission denied' errors."; \
68+
echo ""; \
69+
echo "Fix: run this command:"; \
70+
echo ""; \
71+
echo " export JUST_TEMPDIR=/tmp"; \
72+
echo ""; \
73+
echo "Or add it to your ~/.bashrc for persistence."; \
74+
exit 1; \
75+
fi
76+
4977
# Initialize a new project (use this for projects not yet under version control)
5078
[group('project management')]
51-
setup: _check-config _git-init install _git-add && _setup_part2
79+
setup: _wsl2_compat_check _check-config _git-init install _git-add && _setup_part2
5280
git commit -m "Initialise git with minimal project" -a || true
5381

5482
_setup_part2: gen-project gen-doc
@@ -70,7 +98,7 @@ update: _update-template _update-linkml
7098

7199
# Clean all generated files
72100
[group('project management')]
73-
clean: _clean_project
101+
clean: _wsl2_compat_check _clean_project
74102
rm -rf tmp
75103
rm -rf {{docdir}}/*.md
76104

@@ -131,7 +159,7 @@ gen-project:
131159
# Hidden command to adjust the directory layout on upgrading a project
132160
# created with linkml-project-copier v0.1.x to v0.2.0 or newer.
133161
# Use with care! - It may not work for customized projects.
134-
_post_upgrade_v020: && _post_upgrade_v020py
162+
_post_upgrade_v020: _wsl2_compat_check && _post_upgrade_v020py
135163
mv docs/*.md docs/elements
136164

137165
_post_upgrade_v020py:
@@ -160,7 +188,7 @@ _post_upgrade_v020py:
160188
# ============== Hidden internal recipes ==============
161189

162190
# Show current project status
163-
_status: _check-config
191+
_status: _wsl2_status_check _check-config
164192
@echo "Project: {{schema_name}}"
165193
@echo "Source: {{source_schema_path}}"
166194

0 commit comments

Comments
 (0)