From 1e5f0ea6271c714b040afd1981a143a588ec1c12 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 14 Aug 2023 09:06:12 +0300 Subject: Make repository a channel. --- .guix-channel | 3 + .guix/modules/gn/packages/gn-auth.scm | 114 ++++++++++++++++++++++++++++++++++ .guix/modules/guix-package.scm | 114 ---------------------------------- guix.scm | 2 +- 4 files changed, 118 insertions(+), 115 deletions(-) create mode 100644 .guix-channel create mode 100644 .guix/modules/gn/packages/gn-auth.scm delete mode 100644 .guix/modules/guix-package.scm diff --git a/.guix-channel b/.guix-channel new file mode 100644 index 0000000..9ef7a67 --- /dev/null +++ b/.guix-channel @@ -0,0 +1,3 @@ +(channel + (version 0) + (directory ".guix/modules")) \ No newline at end of file diff --git a/.guix/modules/gn/packages/gn-auth.scm b/.guix/modules/gn/packages/gn-auth.scm new file mode 100644 index 0000000..4f4b7a9 --- /dev/null +++ b/.guix/modules/gn/packages/gn-auth.scm @@ -0,0 +1,114 @@ +(define-module (gn gn-auth) + #:use-module (guix) + #:use-module (guix git-download) + #:use-module (guix build-system python) + #:use-module ((guix licenses) #:prefix license:) + + #:use-module (git oid) + #:use-module (git tag) + #:use-module (git bindings) + #:use-module (git reference) + #:use-module (git repository) + + + ;; Packages from guix + #:use-module (gnu packages check) + + #:use-module (gnu packages python-web) + #:use-module (gnu packages python-xyz) + #:use-module (gnu packages python-check) + #:use-module (gnu packages python-crypto) + + #:use-module (gnu packages databases) + + + ;; Packages from guix-bioinformatics + #:use-module (gn packages python-web)) + +(define %source-dir (dirname (dirname (dirname (current-filename))))) + +(define (get-commit) + "Retrieve the commit if the source directory is a repository." + (if (git-predicate %source-dir) + (begin (let ((commit #f)) + (libgit2-init!) + (set! commit (oid->string + (reference-target + (repository-head (repository-open %source-dir))))) + (libgit2-shutdown!) + commit)) + "NOTAREPOSITORY")) + +(define (list-last lst) + (let ((len (length lst))) + (if (> len 0) + (list-ref lst (- len 1))))) + +(define (process-version repo-head tag-vals) + (let ((version-prefix (list-last (string-split (car tag-vals) #\/))) + (repo-head-str (oid->string repo-head))) + (if (zero? (oid-cmp repo-head + (tag-target-id (cdr tag-vals)))) + version-prefix + (string-append version-prefix "-" (substring repo-head-str 0 8))))) + +(define (get-latest-version) + "Get latest version tag from repository." + (let ((%repo #f) + (%tags (list)) + (%repo-head #f)) + (begin (libgit2-init!) + (set! %repo (repository-open %source-dir)) + (set! %repo-head (reference-target (repository-head %repo))) + (tag-foreach %repo + (lambda (tname tref) + (set! %tags (list (cons tname (tag-lookup %repo tref)))) + 0)) + (libgit2-shutdown!) + (if (zero? (length %tags)) + (string-append "v0.0.0-" (substring (oid->string %repo-head) 0 8)) + (process-version + %repo-head + (list-last (sort-list %tags (lambda (item) (error item))))))))) + +(define vcs-file? + (or (git-predicate %source-dir) + (const #t))) + +(package + (name "genenetwork-auth") + (version (string-append (get-latest-version) + "-git-" + (substring (get-commit) 0 9))) + (source (local-file %source-dir "genenetwork-auth-checkout" + #:recursive? #t + #:select? vcs-file?)) + (build-system python-build-system) + (arguments + (list + #:phases + #~(modify-phases %standard-phases + (replace 'check + (lambda _ (invoke "pytest" "-k" "unit_test")))))) + ;; (inputs (list)) + (native-inputs + (list python-mypy + python-pytest + python-pylint + python-hypothesis + python-pytest-mock + python-mypy-extensions)) + (propagated-inputs + (list python-flask + python-redis + python-authlib + python-pymonad + yoyo-migrations + python-bcrypt ;; remove after removing all references + python-mysqlclient + python-argon2-cffi + python-email-validator)) + (home-page "https://github.com/genenetwork/gn-auth") + (synopsis "Authentication and Authorisation server for GeneNetwork services.") + (description "Authentication and Authorisation server for GeneNetwork services.") + (license license:agpl3+)) diff --git a/.guix/modules/guix-package.scm b/.guix/modules/guix-package.scm deleted file mode 100644 index 2bea32f..0000000 --- a/.guix/modules/guix-package.scm +++ /dev/null @@ -1,114 +0,0 @@ -(define-module (genenetwork-auth) - #:use-module (guix) - #:use-module (guix git-download) - #:use-module (guix build-system python) - #:use-module ((guix licenses) #:prefix license:) - - #:use-module (git oid) - #:use-module (git tag) - #:use-module (git bindings) - #:use-module (git reference) - #:use-module (git repository) - - - ;; Packages from guix - #:use-module (gnu packages check) - - #:use-module (gnu packages python-web) - #:use-module (gnu packages python-xyz) - #:use-module (gnu packages python-check) - #:use-module (gnu packages python-crypto) - - #:use-module (gnu packages databases) - - - ;; Packages from guix-bioinformatics - #:use-module (gn packages python-web)) - -(define %source-dir (dirname (dirname (dirname (current-filename))))) - -(define (get-commit) - "Retrieve the commit if the source directory is a repository." - (if (git-predicate %source-dir) - (begin (let ((commit #f)) - (libgit2-init!) - (set! commit (oid->string - (reference-target - (repository-head (repository-open %source-dir))))) - (libgit2-shutdown!) - commit)) - "NOTAREPOSITORY")) - -(define (list-last lst) - (let ((len (length lst))) - (if (> len 0) - (list-ref lst (- len 1))))) - -(define (process-version repo-head tag-vals) - (let ((version-prefix (list-last (string-split (car tag-vals) #\/))) - (repo-head-str (oid->string repo-head))) - (if (zero? (oid-cmp repo-head - (tag-target-id (cdr tag-vals)))) - version-prefix - (string-append version-prefix "-" (substring repo-head-str 0 8))))) - -(define (get-latest-version) - "Get latest version tag from repository." - (let ((%repo #f) - (%tags (list)) - (%repo-head #f)) - (begin (libgit2-init!) - (set! %repo (repository-open %source-dir)) - (set! %repo-head (reference-target (repository-head %repo))) - (tag-foreach %repo - (lambda (tname tref) - (set! %tags (list (cons tname (tag-lookup %repo tref)))) - 0)) - (libgit2-shutdown!) - (if (zero? (length %tags)) - (string-append "v0.0.0-" (substring (oid->string %repo-head) 0 8)) - (process-version - %repo-head - (list-last (sort-list %tags (lambda (item) (error item))))))))) - -(define vcs-file? - (or (git-predicate %source-dir) - (const #t))) - -(package - (name "genenetwork-auth") - (version (string-append (get-latest-version) - "-git-" - (substring (get-commit) 0 9))) - (source (local-file %source-dir "genenetwork-auth-checkout" - #:recursive? #t - #:select? vcs-file?)) - (build-system python-build-system) - (arguments - (list - #:phases - #~(modify-phases %standard-phases - (replace 'check - (lambda _ (invoke "pytest" "-k" "unit_test")))))) - ;; (inputs (list)) - (native-inputs - (list python-mypy - python-pytest - python-pylint - python-hypothesis - python-pytest-mock - python-mypy-extensions)) - (propagated-inputs - (list python-flask - python-redis - python-authlib - python-pymonad - yoyo-migrations - python-bcrypt ;; remove after removing all references - python-mysqlclient - python-argon2-cffi - python-email-validator)) - (home-page "https://github.com/genenetwork/gn-auth") - (synopsis "Authentication and Authorisation server for GeneNetwork services.") - (description "Authentication and Authorisation server for GeneNetwork services.") - (license license:agpl3+)) diff --git a/guix.scm b/guix.scm index 869bf3d..db5aecb 120000 --- a/guix.scm +++ b/guix.scm @@ -1 +1 @@ -.guix/modules/guix-package.scm \ No newline at end of file +.guix/modules/gn/packages/gn-auth.scm \ No newline at end of file -- cgit v1.2.3