9.2
3 Enigma API: Content Guess
| (require enigma/emacs/file/content-guess) | |
| package: enigma-app | |
procedure
(guess-file-test-runner file-path) → symbol?
file-path : path-string?
Guess the test runner used by the file at file-path.
Returns 'ert, 'ert-runner, 'buttercup or 'none.
procedure
(guess-file-dependencies file-path) → (listof symbol?)
file-path : path-string?
Guess the package-requires dependencies of the file at
file-path.
Returns a list of symbols representing package dependencies.
procedure
(guess-file-version file-path) → (or/c string? #false)
file-path : path-string?
Guess the version of the file at file-path.
Returns a version string or #false.
The source code of this module:
#lang racket/base (require racket/contract/base) (require racket/file) (require racket/match) (require racket/string) (require threading) (require "../../system/utils/path.rkt") (provide (contract-out [guess-file-test-runner (-> path-string? symbol?)] [guess-file-dependencies (-> path-string? (listof symbol?))] [guess-file-version (-> path-string? (or/c string? #false))])) (define (guess-file-test-runner file-path) (cond [(~> file-path path->directory (build-path "test-helper.el") file-exists?) 'ert-runner] [else (define content (file->string file-path)) (match content [(regexp #rx"\\(require 'ert") 'ert] [(regexp #rx"\\(ert-deftest ") 'ert] [(regexp #rx"\\(require 'buttercup") 'buttercup] [(regexp #rx"\\(describe ") 'buttercup] [_ 'none])])) (define (guess-file-dependencies file-path) (define maybe-deps (for/or ([line (file->lines file-path)]) (match line [(regexp #rx"^;; Package-Requires: \\(.+\\)" (list matched)) ;; FIXME: A little fragile, maybe reimplement. (~> matched (regexp-replace ";; Package-Requires:" _ "") string-trim open-input-string ; "((emacs \"26.3\") (s \"0.2\"))" read ; ((emacs "26.3") (s "0.2")) (map car _) ; (emacs s) (filter (lambda (pkg-name) (match pkg-name [(or 'emacs 'seq) #false] [_ #true])) _))] [_ #false]))) (cond [maybe-deps] [else '()])) (define (guess-file-version file-path) (for/or ([line (file->lines file-path)]) (match line [(regexp #rx"^;; Version: .*" (list matched)) (~> matched (regexp-replace ";; Version:" _ "") string-trim)] [_ #false])))