Skip to content

Commit

Permalink
refactor: use juliaWithPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Oct 2, 2023
1 parent dce36f6 commit 5eec2f6
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 51 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ jobs:
run: |
nix build -L .#jupyterlab-kernel-${{ matrix.kernel }}
# TODO remove once we have a better solution. For more info see
# https://github.com/tweag/jupyterWith/pull/280
- name: Install IJulia
if: contains(matrix.kernel, 'julia')
run: |
result/bin/julia examples/$( echo "${{ matrix.kernel }}" | sed -e "s|example-||" | sed -e "s|-|/|g" )/installDeps.jl
- name: Test notebook for ${{ matrix.kernel }} kernel
run: |
echo 'If Julia fails, see if IJulia was updated recently.'
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ result*
/.pre-commit-config.yaml

.ipynb_checkpoints/
*.ipynb
/*.ipynb

# generated folder of jupyter distribution
/jupyterlab/
Expand Down
3 changes: 3 additions & 0 deletions examples/julia/minimal/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{pkgs, ...}: {
kernel.julia.minimal-example = {
enable = true;
extraJuliaPackages = [
"Plots"
];
};
}
2 changes: 0 additions & 2 deletions examples/julia/minimal/installDeps.jl

This file was deleted.

2 changes: 1 addition & 1 deletion examples/python/native/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{pkgs, ...}: {
kernel.python.science-example = {
kernel.python.native-example = {
enable = true;
env = pkgs.python3.withPackages (ps:
with ps; [
Expand Down
69 changes: 69 additions & 0 deletions examples/python/native/test.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "d13cad64-62c0-4b87-b8ef-0242658baa0f",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import scipy as sp\n",
"import matplotlib as mpl"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "16f8a525-ab66-407d-b978-78af1ee27a4d",
"metadata": {},
"outputs": [],
"source": [
"x = np.arange(5)\n",
"print(x)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97728667-fbc5-4e71-a3b7-52f174309b92",
"metadata": {},
"outputs": [],
"source": [
"y_new = sp.interpolate.interp1d(x, x ** 2)(x[:-1] + 0.5)\n",
"print(y_new)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d03e077a-add4-472f-afba-0c1f17e0159a",
"metadata": {},
"outputs": [],
"source": [
"print(mpl.colormaps['viridis'].resampled(8)(0.56))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Example Python Kernel",
"language": "python",
"name": "example-python-science"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 1 addition & 1 deletion examples/python/native/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

current_dir = os.path.dirname(os.path.abspath(__file__))

@testbook(f'{current_dir}/test.ipynb', execute=True, kernel_name="python-science-example")
@testbook(f'{current_dir}/test.ipynb', execute=True, kernel_name="python-native-example")
def test_nb(tb):
np_result = tb.cell_output_text(1)
assert np_result == "[0 1 2 3 4]"
Expand Down
3 changes: 1 addition & 2 deletions examples/python/science/test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"outputs": [],
"source": [
"import numpy as np\n",
"import scipy as sp\n",
"import matplotlib as mpl"
"import scipy as sp"
]
},
{
Expand Down
17 changes: 17 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

inputs.nixpkgs.url = "github:nixos/nixpkgs/2de8efefb6ce7f5e4e75bdf57376a96555986841";
inputs.nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-23.05";
inputs.nixpkgs-julia.url = "github:NixOS/nixpkgs/?ref=refs/pull/225513/head";
inputs.flake-compat.url = "github:edolstra/flake-compat";
inputs.flake-compat.flake = false;
inputs.flake-utils.url = "github:numtide/flake-utils";
Expand Down Expand Up @@ -49,7 +50,8 @@
pre-commit-hooks,
poetry2nix,
rust-overlay,
}: let
...
} @ inputs: let
inherit (nixpkgs) lib;

SYSTEMS = [
Expand Down
60 changes: 26 additions & 34 deletions modules/kernels/julia/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,25 @@
self,
system,
# custom arguments
pkgs ? self.inputs.nixpkgs.legacyPackages.${system},
pkgs,
name ? "julia",
displayName ? "Julia",
requiredRuntimePackages ? [],
runtimePackages ? [],
julia ? pkgs.julia,
julia_depot_path ? "~/.julia",
activateDir ? "",
ijuliaRev ? "6TIq1",
ijuliaRev ? "Vo51o",
extraJuliaPackages ? [],
override ? {},
}: let
inherit (pkgs) writeText;
inherit (pkgs.lib) optionalString;

startupFile = writeText "startup.jl" ''
import Pkg
Pkg.activate("${activateDir}")
Pkg.instantiate()
'';

allRuntimePackages = requiredRuntimePackages ++ runtimePackages;

env = julia;
env = (self.inputs.nixpkgs-julia.legacyPackages.${system}.julia_19.withPackages.override override) ([
"IJulia"
]
++ extraJuliaPackages);

wrappedEnv =
pkgs.runCommand "wrapper-${env.name}"
Expand All @@ -52,7 +49,7 @@
filename=$(basename $i)
ln -s ${env}/bin/$filename $out/bin/$filename
wrapProgram $out/bin/$filename \
--set PATH "${pkgs.lib.makeSearchPath "bin" allRuntimePackages}" ${optionalString (activateDir != "") ''--add-flags "-L ${startupFile}"''}
--set PATH "${pkgs.lib.makeSearchPath "bin" allRuntimePackages}"
done
'';
in {
Expand All @@ -63,7 +60,7 @@
"-i"
"--startup-file=yes"
"--color=yes"
"${julia_depot_path}/packages/IJulia/${ijuliaRev}/src/kernel.jl"
"${env.projectAndDepot}/depot/packages/IJulia/${ijuliaRev}/src/kernel.jl"
"{connection_file}"
];
codemirrorMode = "julia";
Expand All @@ -72,37 +69,32 @@
in {
options =
{
julia_depot_path = lib.mkOption {
ijuliaRev = lib.mkOption {
type = types.str;
default = "~/.julia";
example = "~/.julia";
default = "Vo51o";
description = lib.mdDoc ''
Julia path
IJulia revision
'';
};

activateDir = lib.mkOption {
type = types.str;
default = "";
example = "";
julia = lib.mkOption {
type = types.package;
default = config.nixpkgs.julia;
description = lib.mdDoc ''
Julia activate directory
Julia Version
'';
};

ijuliaRev = lib.mkOption {
type = types.str;
default = "6TIq1";
example = "6TIq1";
extraJuliaPackages = lib.mkOption {
type = types.listOf types.str;
default = [];
description = lib.mdDoc ''
iJulia revision
Extra Julia packages to install
'';
};
julia = lib.mkOption {
type = types.package;
default = config.nixpkgs.julia;
override = lib.mkOption {
type = types.attrs;
default = {};
description = lib.mdDoc ''
Julia Version
Override JuliaWithPackages
'';
};
}
Expand All @@ -112,7 +104,7 @@
build = mkKernel (kernelFunc config.kernelArgs);
kernelArgs =
{
inherit (config) julia_depot_path activateDir ijuliaRev julia;
inherit (config) override extraJuliaPackages ijuliaRev julia;
}
// kernelModule.kernelArgs;
};
Expand Down
4 changes: 2 additions & 2 deletions modules/kernels/scala/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

almondSh = let
baseName = "almond";
version = "0.13.1";
version = "0.14.0-RC7";
scalaVersion = scala.version;
deps = stdenv.mkDerivation {
name = "${baseName}-deps-${version}";
Expand All @@ -50,7 +50,7 @@

outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = "iPWMAvEW83aETWrxt9CmBAYMNouWsHHDoEa+Qy9inyE=";
outputHash = "sha256-JIYAuhV3+PQBceGEIgn5DkHTG80cKNV11FeJTefRHi8=";
};
in
stdenv.mkDerivation {
Expand Down

0 comments on commit 5eec2f6

Please sign in to comment.