├── .github └── workflows │ └── main.yml ├── .gitignore ├── LICENSE ├── README.md ├── raco-pkg-env-lib ├── info.rkt └── main.rkt └── raco-pkg-env ├── .gitignore ├── info.rkt └── scribblings ├── changelog.scrbl └── raco-pkg-env.scrbl /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Test install and compile 2 | on: 3 | push: 4 | pull_request: 5 | schedule: 6 | - cron: "17 23 * * TUE" 7 | jobs: 8 | build: 9 | name: "Build on Racket" 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@master 13 | - uses: Bogdanp/setup-racket@v1.8.1 14 | with: 15 | version: stable 16 | - name: Installing raco-pkg-env-lib and its dependencies 17 | run: raco pkg install --batch --no-docs --auto --link raco-pkg-env-lib 18 | - name: Installing raco-pkg-env and its dependencies 19 | run: raco pkg install --batch --no-docs --auto --link raco-pkg-env 20 | - name: Compiling raco-pkg-env-lib and building its docs 21 | run: raco setup --check-pkg-deps --unused-pkg-deps --pkgs raco-pkg-env-lib 22 | - name: Compiling raco-pkg-env and building its docs 23 | run: raco setup --check-pkg-deps --unused-pkg-deps --pkgs raco-pkg-env 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | \#* 3 | .\#* 4 | .DS_Store 5 | compiled/ 6 | /doc/ 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2021 Sam Phillips 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # raco-env-lib 2 | 3 | **EXPERIMENTAL** 4 | 5 | This tool writes a config.rktd file that you can point PLTCONFIGDIR and install 6 | packages into a place that isn’t the installation scope or the user scope. 7 | 8 | The package environment overlays the system installation scope. There will 9 | probably be some hiccups if you are using this. Open some PRs and Issues. 10 | 11 | ## Usage 12 | Create a new package environment (from the shell): 13 | ``` 14 | ;; make the environment 15 | new-package> raco pkg-env _env 16 | 17 | ;; simple bash script that sets the PLTCONFIGDIR variable 18 | new-package> source _env/activate.sh 19 | 20 | ;; install some-package into _env 21 | new-package> raco pkg install some-packagename 22 | ``` 23 | 24 | ## Credits 25 | - [Sam Phillips](https://github.com/samdphillips) - initial implementation 26 | - [Leif Andersen](https://github.com/LeifAndersen) - additional functionality, 27 | bringing the tools more in line with Python venv facility. 28 | 29 | -------------------------------------------------------------------------------- /raco-pkg-env-lib/info.rkt: -------------------------------------------------------------------------------- 1 | #lang info 2 | 3 | (define name "raco-pkg-env-lib") 4 | (define collection "raco-pkg-env") 5 | (define version "0.1.4") 6 | (define deps '("base")) 7 | (define build-deps '("at-exp-lib")) 8 | (define pkg-authors '(samdphillips@gmail.com)) 9 | (define license 'Apache-2.0) 10 | (define raco-commands 11 | '(("pkg-env" (submod raco-pkg-env main) 12 | "sets up a package environment" 13 | 10))) 14 | -------------------------------------------------------------------------------- /raco-pkg-env-lib/main.rkt: -------------------------------------------------------------------------------- 1 | #lang at-exp racket/base 2 | 3 | (require racket/file 4 | racket/format 5 | racket/match 6 | racket/path 7 | racket/pretty 8 | setup/dirs) 9 | 10 | (define-logger pkg-env) 11 | 12 | (define (setup-env-dir key system-config env-config proc) 13 | (log-pkg-env-info "setup-env-dir ~s" key) 14 | (let ([src (hash-ref system-config key #f)] 15 | [dest (hash-ref env-config key)]) 16 | (log-pkg-env-info "setting up ~s -> ~s" src dest) 17 | (make-directory* dest) 18 | (when src 19 | (define (destname n) 20 | (build-path dest (file-name-from-path n))) 21 | (define (link n) 22 | (make-file-or-directory-link n (destname n))) 23 | (define (copy n) 24 | (copy-file n (destname n))) 25 | (for ([fname (directory-list src #:build? #t)]) 26 | (log-pkg-env-info "setting up ~s -> ~s" fname (destname fname)) 27 | (proc fname copy link))))) 28 | 29 | (define (install-environment! env-dir) 30 | (log-pkg-env-info "install-environment! in ~s" env-dir) 31 | (define env-config-dir (build-path env-dir "etc")) 32 | (define system-config-rktd 33 | (build-path (find-config-dir) "config.rktd")) 34 | (log-pkg-env-info "system-config-rktd is at ~s" system-config-rktd) 35 | 36 | (define system-config (file->value system-config-rktd)) 37 | (when (log-level? pkg-env-logger 'debug) 38 | (log-pkg-env-debug "system-config is:") 39 | (log-pkg-env-debug (pretty-format system-config #:mode 'write))) 40 | 41 | (define env-bin-dir (build-path env-dir "bin")) 42 | 43 | (define env-config 44 | (hash-set* system-config 45 | ;; changed keys 46 | 'bin-dir (path->string env-bin-dir) 47 | 48 | 'doc-dir 49 | (path->string (build-path env-dir "doc")) 50 | 51 | 'lib-dir 52 | (path->string (build-path env-dir "lib")) 53 | 54 | 'share-dir 55 | (path->string (build-path env-dir "share")) 56 | 57 | ;; added keys 58 | 'default-scope 59 | "installation" 60 | 61 | 'links-file 62 | (path->string (build-path env-dir "links.rktd")) 63 | 64 | 'doc-search-dirs 65 | (list #f (path->string (find-doc-dir))) 66 | 67 | 'links-search-files 68 | (list #f (path->string (find-links-file))) 69 | 70 | 'pkgs-dir 71 | (path->string (build-path env-dir "pkgs")) 72 | 73 | 'pkgs-search-dirs 74 | (list #f (path->string (find-pkgs-dir))) 75 | 76 | ;; random from uuidgen, maybe the user doesn't want to mess with this? 77 | ;; 'installation-name "b1760145-c765-4f74-ac27-bd5f441c60a5" 78 | )) 79 | 80 | (make-directory* env-config-dir) 81 | (call-with-output-file (build-path env-config-dir "config.rktd") 82 | (lambda (outp) 83 | (pretty-write env-config outp))) 84 | 85 | ;; Setup lib-dir 86 | ;; Copy config files, symlink everything else 87 | (setup-env-dir 'lib-dir system-config env-config 88 | (lambda (fname copy link) 89 | (match (path-get-extension fname) 90 | [#".rktd" (copy fname)] 91 | [_ (link fname)]))) 92 | 93 | 94 | ;; Setup bin-dir 95 | (setup-env-dir 'bin-dir system-config env-config 96 | (lambda (fname copy link) (link fname))) 97 | 98 | (call-with-output-file (build-path env-dir "activate.sh") 99 | (lambda (outp) 100 | (displayln 101 | @~a{export PS1="(@(file-name-from-path (simplify-path env-dir))) ${PS1}" 102 | export PLTCONFIGDIR="@env-config-dir" 103 | export PATH="@|env-bin-dir|:$PATH"} 104 | outp)))) 105 | 106 | (module+ main 107 | (require racket/cmdline) 108 | (define clear-directory (make-parameter #f)) 109 | (define env-dir 110 | (command-line 111 | #:program "pkg-env" 112 | #:once-each 113 | [("-c" "--clear") "Delete existing contents of environment directory" 114 | (clear-directory #t)] 115 | #:args (folder) 116 | folder)) 117 | (when (clear-directory) (delete-directory/files env-dir #:must-exist? #f)) 118 | (install-environment! 119 | (path->complete-path 120 | (string->path env-dir)))) 121 | 122 | -------------------------------------------------------------------------------- /raco-pkg-env/.gitignore: -------------------------------------------------------------------------------- 1 | doc/ 2 | -------------------------------------------------------------------------------- /raco-pkg-env/info.rkt: -------------------------------------------------------------------------------- 1 | #lang info 2 | 3 | (define name "raco-pkg-env") 4 | (define version "0.1.4") 5 | (define collection "raco-pkg-env") 6 | (define deps '("base" "raco-pkg-env-lib")) 7 | (define implies '("raco-pkg-env-lib")) 8 | (define build-deps '("racket-doc" "scribble-lib")) 9 | (define scribblings '(["scribblings/raco-pkg-env.scrbl"])) 10 | (define pkg-authors '(samdphillips@gmail.com)) 11 | (define license 'Apache-2.0) 12 | -------------------------------------------------------------------------------- /raco-pkg-env/scribblings/changelog.scrbl: -------------------------------------------------------------------------------- 1 | #lang scribble/manual 2 | 3 | @(require (for-label racket)) 4 | 5 | @(define-syntax-rule (changelog version release-date items ...) 6 | (begin 7 | (section version) 8 | "Release data:" release-date 9 | (itemlist items ...))) 10 | 11 | @title{Changelog} 12 | 13 | @changelog[ 14 | "0.1.4" 15 | "2022/11/19" 16 | @item{Documentation tweaks} 17 | @item{Added license package metadata}] 18 | 19 | @changelog[ 20 | "0.1.3" 21 | "2022/08/28" 22 | @item{Add bin directory to path.} 23 | @item{Add a @litchar{--clear} command line flag to match python venv.} 24 | @item{Update the @litchar{PS1} environment variable in the 25 | activate script.}] 26 | 27 | @changelog[ 28 | "0.1.2" 29 | "2022/04/19" 30 | @item{Fix incorrect use of @racket[in-directory]} 31 | @item{Add logging} 32 | @item{Populate the contents of `lib-dir` and `bin-dir` from the "source" 33 | Racket installation.}] 34 | 35 | @changelog[ 36 | "0.1.1" 37 | "2021/04/19" 38 | @item{Initial release.}] 39 | 40 | -------------------------------------------------------------------------------- /raco-pkg-env/scribblings/raco-pkg-env.scrbl: -------------------------------------------------------------------------------- 1 | #lang scribble/manual 2 | 3 | @title{raco-pkg-env: virtualenv like tool for Racket} 4 | @author[(author+email "Sam Phillips" "samdphillips@gmail.com")] 5 | 6 | @section{Guide} 7 | 8 | @bold{**EXPERIMENTAL**} 9 | 10 | This tool writes a @tt{config.rktd} file that you can point 11 | @envvar{PLTCONFIGDIR} and install packages into a place that isn't the 12 | installation scope or the user scope. 13 | 14 | The package environment overlays the system installation scope. There will 15 | probably be some hiccups if you are using this. Open some PRs and Issues. 16 | 17 | Create a new package environment (from the shell): 18 | @codeblock{ 19 | ;; make the environment 20 | new-package> raco pkg-env _env 21 | 22 | ;; make the environment removing any existing environment 23 | new-package> raco pkg-env --clear _env 24 | 25 | ;; simple bash script that sets the PLTCONFIGDIR variable 26 | new-package> source _env/activate.sh 27 | 28 | ;; install some-package into _env 29 | (_env) new-package> raco pkg install some-packagename 30 | } 31 | 32 | @include-section["changelog.scrbl"] 33 | 34 | --------------------------------------------------------------------------------