Skip to content

Commit 5aaa50b

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

2 files changed

Lines changed: 31 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: 30 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,34 @@ 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 'export JUST_TEMPDIR=/tmp'"; \
70+
echo ""; \
71+
echo "Or add it to your ~/.bashrc for persistence."; \
72+
exit 1; \
73+
fi
74+
4975
# Initialize a new project (use this for projects not yet under version control)
5076
[group('project management')]
51-
setup: _check-config _git-init install _git-add && _setup_part2
77+
setup: _wsl2_compat_check _check-config _git-init install _git-add && _setup_part2
5278
git commit -m "Initialise git with minimal project" -a || true
5379

5480
_setup_part2: gen-project gen-doc
@@ -70,7 +96,7 @@ update: _update-template _update-linkml
7096

7197
# Clean all generated files
7298
[group('project management')]
73-
clean: _clean_project
99+
clean: _wsl2_compat_check _clean_project
74100
rm -rf tmp
75101
rm -rf {{docdir}}/*.md
76102

@@ -131,7 +157,7 @@ gen-project:
131157
# Hidden command to adjust the directory layout on upgrading a project
132158
# created with linkml-project-copier v0.1.x to v0.2.0 or newer.
133159
# Use with care! - It may not work for customized projects.
134-
_post_upgrade_v020: && _post_upgrade_v020py
160+
_post_upgrade_v020: _wsl2_compat_check && _post_upgrade_v020py
135161
mv docs/*.md docs/elements
136162

137163
_post_upgrade_v020py:
@@ -160,7 +186,7 @@ _post_upgrade_v020py:
160186
# ============== Hidden internal recipes ==============
161187

162188
# Show current project status
163-
_status: _check-config
189+
_status: _wsl2_status_check _check-config
164190
@echo "Project: {{schema_name}}"
165191
@echo "Source: {{source_schema_path}}"
166192

0 commit comments

Comments
 (0)