diff --git a/recipes/filelock-mojo/recipe.yaml b/recipes/filelock-mojo/recipe.yaml new file mode 100644 index 00000000..e675000e --- /dev/null +++ b/recipes/filelock-mojo/recipe.yaml @@ -0,0 +1,61 @@ +{ + "package": { + "name": "filelock-mojo", + "version": "0.1.0" + }, + "source": { + "git": "https://github.com/henlamp/filelock-mojo.git", + "rev": "5bbf339e870cc60b35f22793472bc6f48057651f" + }, + "build": { + "number": 0, + "string": "mojo110_0", + "skip": "not (osx and arm64)", + "files": [ + "lib/mojo/filelock_mojo.mojoc" + ], + "script": [ + "mkdir -p \"$PREFIX/lib/mojo\"", + "mojo precompile --Werror src/filelock_mojo -o \"$PREFIX/lib/mojo/filelock_mojo.mojoc\"" + ] + }, + "requirements": { + "build": [ + "mojo-compiler ==1.1.0" + ], + "host": [ + "mojo-compiler ==1.1.0" + ], + "run": [ + "mojo-compiler ==1.1.0" + ] + }, + "tests": [ + { + "script": [ + "mojo run --Werror smoke.mojo" + ], + "files": { + "recipe": [ + "smoke.mojo" + ] + } + } + ], + "about": { + "homepage": "https://github.com/henlamp/filelock-mojo", + "repository": "https://github.com/henlamp/filelock-mojo.git", + "license": "MIT", + "license_file": [ + "LICENSE", + "UPSTREAM_LICENSE", + "THIRD_PARTY_NOTICES.md" + ], + "summary": "Unix process locks and atomic text publication in Mojo" + }, + "extra": { + "maintainers": [ + "henlamp" + ] + } +} diff --git a/recipes/filelock-mojo/smoke.mojo b/recipes/filelock-mojo/smoke.mojo new file mode 100644 index 00000000..c474cf2a --- /dev/null +++ b/recipes/filelock-mojo/smoke.mojo @@ -0,0 +1,32 @@ +from std.testing import assert_true +from filelock_mojo import FileLock, ReadWriteLock, LockErrorKind + + +def main() raises: + var owner = FileLock("installed-package.lock", timeout=0) + var rival = FileLock("installed-package.lock", timeout=0) + with owner.hold(): + assert_true(owner.is_locked()) + assert_true(not rival.try_acquire()) + assert_true(rival.try_acquire()) + rival.release() + var reader = FileLock("read.lock", timeout=0, mode=.shared) + with reader.hold(): + pass + var rw = ReadWriteLock("readwrite.lock", timeout=0) + with rw.read(): + pass + with rw.write(): + pass + var rejected = False + try: + rw.release() + except e: + rejected = e.kind == LockErrorKind.not_held + assert_true(rejected) + var attempted = owner.try_hold() + assert_true(Bool(attempted)) + with attempted.take(): + assert_true(owner.lock_count() == 1) + assert_true(not owner.is_locked()) + print("PASS: installed filelock_mojo")