gennaker-tools 0.1.5__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/CHANGELOG.md +44 -2
  2. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/PKG-INFO +3 -2
  3. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/gennaker_tools/_version.py +1 -1
  4. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/gennaker_tools/labextension/package.json +2 -2
  5. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/gennaker_tools/labextension/schemas/gennaker-tools/package.json.orig +1 -1
  6. gennaker_tools-0.1.5/gennaker_tools/labextension/static/509.4ba7e0c1be6d39a3ec07.js → gennaker_tools-0.2.0/gennaker_tools/labextension/static/509.031cb77fbf5c28a28cdf.js +1 -1
  7. gennaker_tools-0.1.5/gennaker_tools/labextension/static/remoteEntry.7cf8ef915feb12b1787a.js → gennaker_tools-0.2.0/gennaker_tools/labextension/static/remoteEntry.e63ec10f554c0558443e.js +1 -1
  8. gennaker_tools-0.2.0/gennaker_tools/settings_sync_extension.py +194 -0
  9. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/package.json +1 -1
  10. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/pyproject.toml +3 -2
  11. gennaker_tools-0.1.5/gennaker_tools/settings_sync_extension.py +0 -132
  12. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/.copier-answers.yml +0 -0
  13. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/.gitignore +0 -0
  14. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/.prettierignore +0 -0
  15. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/.yarnrc.yml +0 -0
  16. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/LICENSE +0 -0
  17. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/README.md +0 -0
  18. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/RELEASE.md +0 -0
  19. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/flake.lock +0 -0
  20. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/flake.nix +0 -0
  21. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/gennaker_tools/__init__.py +0 -0
  22. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/gennaker_tools/labextension/schemas/gennaker-tools/stateless-run.json +0 -0
  23. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/gennaker_tools/labextension/static/728.c3ac4b62173ea8b3c44b.js +0 -0
  24. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/gennaker_tools/labextension/static/747.28975bdde163d0eaf6e0.js +0 -0
  25. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/gennaker_tools/labextension/static/style.js +0 -0
  26. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/gennaker_tools/labextension/static/third-party-licenses.json +0 -0
  27. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/install.json +0 -0
  28. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/jupyter-config/jupyter_server_config.d/gennaker_tools.json +0 -0
  29. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/renovate.json5 +0 -0
  30. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/schema/stateless-run.json +0 -0
  31. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/setup.py +0 -0
  32. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/src/index.ts +0 -0
  33. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/style/base.css +0 -0
  34. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/style/index.css +0 -0
  35. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/style/index.js +0 -0
  36. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/tsconfig.json +0 -0
  37. {gennaker_tools-0.1.5 → gennaker_tools-0.2.0}/yarn.lock +0 -0
@@ -2,12 +2,54 @@
2
2
 
3
3
  <!-- <START NEW CHANGELOG ENTRY> -->
4
4
 
5
- ## 0.1.5
5
+ ## 0.2.0
6
6
 
7
- No merged PRs
7
+ ([Full Changelog](https://github.com/agoose77/gennaker-tools/compare/v0.1.6...aa7f7967572d33167af8aacbcc3f6079e8b3a1fa))
8
+
9
+ ### Maintenance and upkeep improvements
10
+
11
+ - deps: Update jupyter-server/jupyter_releaser action to v1.10.2 [#20](https://github.com/agoose77/gennaker-tools/pull/20) ()
12
+ - deps: Update gha (major) [#19](https://github.com/agoose77/gennaker-tools/pull/19) ()
13
+ - deps: Update gha [#18](https://github.com/agoose77/gennaker-tools/pull/18) ()
14
+
15
+ ### Other merged PRs
16
+
17
+ - feat: only log filename [#22](https://github.com/agoose77/gennaker-tools/pull/22) ([@agoose77](https://github.com/agoose77))
18
+ - fix: only print when actual reconciliation occurs [#21](https://github.com/agoose77/gennaker-tools/pull/21) ([@agoose77](https://github.com/agoose77))
19
+
20
+ ### Contributors to this release
21
+
22
+ The following people contributed discussions, new ideas, code and documentation contributions, and review.
23
+ See [our definition of contributors](https://github-activity.readthedocs.io/en/latest/use/#how-does-this-tool-define-contributions-in-the-reports).
24
+
25
+ ([GitHub contributors page for this release](https://github.com/agoose77/gennaker-tools/graphs/contributors?from=2026-01-11&to=2026-01-28&type=c))
26
+
27
+ @agoose77 ([activity](https://github.com/search?q=repo%3Aagoose77%2Fgennaker-tools+involves%3Aagoose77+updated%3A2026-01-11..2026-01-28&type=Issues))
8
28
 
9
29
  <!-- <END NEW CHANGELOG ENTRY> -->
10
30
 
31
+ ## 0.1.6
32
+
33
+ ([Full Changelog](https://github.com/agoose77/gennaker-tools/compare/v0.1.5...0403a7b883afedf5634d7446c88a8bc1b3a9d842))
34
+
35
+ ### Bugs fixed
36
+
37
+ - fix: handle round-trip and null [#17](https://github.com/agoose77/gennaker-tools/pull/17) ([@agoose77](https://github.com/agoose77))
38
+
39
+ ### Other merged PRs
40
+
41
+ - Fix: perform initial reconciliation [#16](https://github.com/agoose77/gennaker-tools/pull/16) ([@agoose77](https://github.com/agoose77))
42
+
43
+ ### Contributors to this release
44
+
45
+ ([GitHub contributors page for this release](https://github.com/agoose77/gennaker-tools/graphs/contributors?from=2026-01-11&to=2026-01-11&type=c))
46
+
47
+ [@agoose77](https://github.com/search?q=repo%3Aagoose77%2Fgennaker-tools+involves%3Aagoose77+updated%3A2026-01-11..2026-01-11&type=Issues)
48
+
49
+ ## 0.1.5
50
+
51
+ No merged PRs
52
+
11
53
  ## 0.1.4
12
54
 
13
55
  ([Full Changelog](https://github.com/agoose77/gennaker-tools/compare/v0.1.3...795450402276c565914c01971d096d93afac9662))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gennaker-tools
3
- Version: 0.1.5
3
+ Version: 0.2.0
4
4
  Summary: A JupyterLab extension to provide a restart-and-run-to-selected command variant that clears non-executed cell outputs.
5
5
  Project-URL: Homepage, https://github.com/agoose77/gennaker-tools
6
6
  Project-URL: Bug Tracker, https://github.com/agoose77/gennaker-tools/issues
@@ -50,8 +50,9 @@ Classifier: Programming Language :: Python :: 3.10
50
50
  Classifier: Programming Language :: Python :: 3.11
51
51
  Classifier: Programming Language :: Python :: 3.12
52
52
  Classifier: Programming Language :: Python :: 3.13
53
- Requires-Python: >=3.9
53
+ Requires-Python: >=3.10
54
54
  Requires-Dist: aiofiles
55
+ Requires-Dist: json5
55
56
  Requires-Dist: tomli
56
57
  Requires-Dist: tomli-w
57
58
  Requires-Dist: watchfiles
@@ -1,4 +1,4 @@
1
1
  # This file is auto-generated by Hatchling. As such, do not:
2
2
  # - modify
3
3
  # - track in version control e.g. be sure to add to .gitignore
4
- __version__ = VERSION = '0.1.5'
4
+ __version__ = VERSION = '0.2.0'
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gennaker-tools",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "A JupyterLab extension to provide a restart-and-run-to-selected command variant that clears non-executed cell outputs.",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -99,7 +99,7 @@
99
99
  "outputDir": "gennaker_tools/labextension",
100
100
  "schemaDir": "schema",
101
101
  "_build": {
102
- "load": "static/remoteEntry.7cf8ef915feb12b1787a.js",
102
+ "load": "static/remoteEntry.e63ec10f554c0558443e.js",
103
103
  "extension": "./extension",
104
104
  "style": "./style"
105
105
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gennaker-tools",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "A JupyterLab extension to provide a restart-and-run-to-selected command variant that clears non-executed cell outputs.",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -1 +1 @@
1
- "use strict";(self.webpackChunkgennaker_tools=self.webpackChunkgennaker_tools||[]).push([[509],{509:(e,t,a)=>{a.r(t),a.d(t,{default:()=>b,reloadPlugin:()=>u,snippetsPlugin:()=>d,statelessRunPlugin:()=>p});var n,o=a(389),r=a(827),s=a(591),l=a(460),i=a(505);!function(e){e.restartRunStateless="gennaker-tools:restart-run-stateless",e.resetJupyterLab="gennaker-tools:reset-jupyterlab"}(n||(n={}));const p={id:"gennaker-tools:stateless-run",description:"A JupyterLab extension.",autoStart:!0,requires:[r.ICommandPalette,o.INotebookTracker],optional:[s.ITranslator],activate:(e,t,a,o)=>{const r=(null!=o?o:s.nullTranslator).load("jupyterlab"),{commands:l,shell:i}=e;console.log("JupyterLab plugin gennaker-tools:stateless-run is activated!"),l.addCommand(n.restartRunStateless,{label:"Restart Kernel, Clear Outputs, and Run All Above Selected Cell",caption:"Clear all outputs, restart kernel, and run all cells above the selected cell",isEnabled:()=>null!==a.currentWidget&&a.currentWidget===i.currentWidget,execute:async e=>{const t=e.origin;console.log(`${n.restartRunStateless} has been called from... ${t}.`),"init"!==t&&await l.execute("apputils:run-all-enabled",{commands:["notebook:clear-all-cell-outputs","notebook:restart-and-run-to-selected"]})}});const p=r.__("Notebook Operations");t.addItem({command:n.restartRunStateless,category:p,args:{origin:"from palette"}})}},u={id:"gennaker-tools:reload",description:"A JupyterLab extension.",autoStart:!0,requires:[r.ICommandPalette],optional:[s.ITranslator],activate:(e,t,a)=>{console.log("JupyterLab plugin gennaker-tools:reload is activated!");const{commands:o}=e,r=(null!=a?a:s.nullTranslator).load("jupyterlab");o.addCommand(n.resetJupyterLab,{label:"Reset JupyterLab",caption:"Reset JupyterLab",isEnabled:()=>!0,execute:e=>{"init"!==e.origin&&window.location.reload()}});const l=r.__("Reset");t.addItem({command:n.resetJupyterLab,category:l,args:{origin:"from palette"}})}},c={properties:{snippets:{type:"array",title:"Codemirror snippets",description:"Snippets of the form accepted by Codemirrors snippetCompletion",items:{type:"object",properties:{type:{type:"string",enum:["class","constant","enum","function","interface","keyword","method","namespace","property","text","type","variable"]},body:{type:"string"},label:{type:"string"}},required:["type","body","label"]}}},additionalProperties:!1,type:"object"},d={id:"gennaker-tools:snippets",description:"A JupyterLab extension.",autoStart:!0,requires:[l.IEditorExtensionRegistry],optional:[],activate:(e,t)=>{console.log("JupyterLab plugin gennaker-tools:snippets is activated!"),t.addExtension(Object.freeze({name:"gennaker-tools:snippets",factory:()=>l.EditorExtensionRegistry.createConfigurableExtension(e=>(0,i.autocompletion)({override:[(0,i.completeFromList)(e.snippets.map(e=>{const{body:t,...a}=e;return(0,i.snippetCompletion)(t,a)}))]})),default:{snippets:[]},schema:c}))}},b=[p,u,d]}}]);
1
+ "use strict";(self.webpackChunkgennaker_tools=self.webpackChunkgennaker_tools||[]).push([[509],{509:(e,t,a)=>{a.r(t),a.d(t,{default:()=>b,reloadPlugin:()=>u,snippetsPlugin:()=>d,statelessRunPlugin:()=>p});var n,o=a(931),r=a(285),s=a(769),l=a(790),i=a(505);!function(e){e.restartRunStateless="gennaker-tools:restart-run-stateless",e.resetJupyterLab="gennaker-tools:reset-jupyterlab"}(n||(n={}));const p={id:"gennaker-tools:stateless-run",description:"A JupyterLab extension.",autoStart:!0,requires:[r.ICommandPalette,o.INotebookTracker],optional:[s.ITranslator],activate:(e,t,a,o)=>{const r=(null!=o?o:s.nullTranslator).load("jupyterlab"),{commands:l,shell:i}=e;console.log("JupyterLab plugin gennaker-tools:stateless-run is activated!"),l.addCommand(n.restartRunStateless,{label:"Restart Kernel, Clear Outputs, and Run All Above Selected Cell",caption:"Clear all outputs, restart kernel, and run all cells above the selected cell",isEnabled:()=>null!==a.currentWidget&&a.currentWidget===i.currentWidget,execute:async e=>{const t=e.origin;console.log(`${n.restartRunStateless} has been called from... ${t}.`),"init"!==t&&await l.execute("apputils:run-all-enabled",{commands:["notebook:clear-all-cell-outputs","notebook:restart-and-run-to-selected"]})}});const p=r.__("Notebook Operations");t.addItem({command:n.restartRunStateless,category:p,args:{origin:"from palette"}})}},u={id:"gennaker-tools:reload",description:"A JupyterLab extension.",autoStart:!0,requires:[r.ICommandPalette],optional:[s.ITranslator],activate:(e,t,a)=>{console.log("JupyterLab plugin gennaker-tools:reload is activated!");const{commands:o}=e,r=(null!=a?a:s.nullTranslator).load("jupyterlab");o.addCommand(n.resetJupyterLab,{label:"Reset JupyterLab",caption:"Reset JupyterLab",isEnabled:()=>!0,execute:e=>{"init"!==e.origin&&window.location.reload()}});const l=r.__("Reset");t.addItem({command:n.resetJupyterLab,category:l,args:{origin:"from palette"}})}},c={properties:{snippets:{type:"array",title:"Codemirror snippets",description:"Snippets of the form accepted by Codemirrors snippetCompletion",items:{type:"object",properties:{type:{type:"string",enum:["class","constant","enum","function","interface","keyword","method","namespace","property","text","type","variable"]},body:{type:"string"},label:{type:"string"}},required:["type","body","label"]}}},additionalProperties:!1,type:"object"},d={id:"gennaker-tools:snippets",description:"A JupyterLab extension.",autoStart:!0,requires:[l.IEditorExtensionRegistry],optional:[],activate:(e,t)=>{console.log("JupyterLab plugin gennaker-tools:snippets is activated!"),t.addExtension(Object.freeze({name:"gennaker-tools:snippets",factory:()=>l.EditorExtensionRegistry.createConfigurableExtension(e=>(0,i.autocompletion)({override:[(0,i.completeFromList)(e.snippets.map(e=>{const{body:t,...a}=e;return(0,i.snippetCompletion)(t,a)}))]})),default:{snippets:[]},schema:c}))}},b=[p,u,d]}}]);
@@ -1 +1 @@
1
- var _JUPYTERLAB;(()=>{"use strict";var e,r,t,o,n,a,i,u,l,s,f,d,c,p,h,v,g,b,m,y,w,k,S,j={842:(e,r,t)=>{var o={"./index":()=>t.e(509).then(()=>()=>t(509)),"./extension":()=>t.e(509).then(()=>()=>t(509)),"./style":()=>t.e(728).then(()=>()=>t(728))},n=(e,r)=>(t.R=r,r=t.o(o,e)?o[e]():Promise.resolve().then(()=>{throw new Error('Module "'+e+'" does not exist in container.')}),t.R=void 0,r),a=(e,r)=>{if(t.S){var o="default",n=t.S[o];if(n&&n!==e)throw new Error("Container initialization failed as it has already been initialized with a different share scope");return t.S[o]=e,t.I(o,r)}};t.d(r,{get:()=>n,init:()=>a})}},E={};function P(e){var r=E[e];if(void 0!==r)return r.exports;var t=E[e]={id:e,exports:{}};return j[e](t,t.exports,P),t.exports}P.m=j,P.c=E,P.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return P.d(r,{a:r}),r},P.d=(e,r)=>{for(var t in r)P.o(r,t)&&!P.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},P.f={},P.e=e=>Promise.all(Object.keys(P.f).reduce((r,t)=>(P.f[t](e,r),r),[])),P.u=e=>e+"."+{509:"4ba7e0c1be6d39a3ec07",728:"c3ac4b62173ea8b3c44b",747:"28975bdde163d0eaf6e0"}[e]+".js?v="+{509:"4ba7e0c1be6d39a3ec07",728:"c3ac4b62173ea8b3c44b",747:"28975bdde163d0eaf6e0"}[e],P.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),P.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),e={},r="gennaker-tools:",P.l=(t,o,n,a)=>{if(e[t])e[t].push(o);else{var i,u;if(void 0!==n)for(var l=document.getElementsByTagName("script"),s=0;s<l.length;s++){var f=l[s];if(f.getAttribute("src")==t||f.getAttribute("data-webpack")==r+n){i=f;break}}i||(u=!0,(i=document.createElement("script")).charset="utf-8",P.nc&&i.setAttribute("nonce",P.nc),i.setAttribute("data-webpack",r+n),i.src=t),e[t]=[o];var d=(r,o)=>{i.onerror=i.onload=null,clearTimeout(c);var n=e[t];if(delete e[t],i.parentNode&&i.parentNode.removeChild(i),n&&n.forEach(e=>e(o)),r)return r(o)},c=setTimeout(d.bind(null,void 0,{type:"timeout",target:i}),12e4);i.onerror=d.bind(null,i.onerror),i.onload=d.bind(null,i.onload),u&&document.head.appendChild(i)}},P.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{P.S={};var e={},r={};P.I=(t,o)=>{o||(o=[]);var n=r[t];if(n||(n=r[t]={}),!(o.indexOf(n)>=0)){if(o.push(n),e[t])return e[t];P.o(P.S,t)||(P.S[t]={});var a=P.S[t],i="gennaker-tools",u=(e,r,t,o)=>{var n=a[e]=a[e]||{},u=n[r];(!u||!u.loaded&&(!o!=!u.eager?o:i>u.from))&&(n[r]={get:t,from:i,eager:!!o})},l=[];return"default"===t&&(u("@codemirror/autocomplete","6.19.1",()=>Promise.all([P.e(747),P.e(949)]).then(()=>()=>P(747))),u("gennaker-tools","0.1.5",()=>P.e(509).then(()=>()=>P(509)))),e[t]=l.length?Promise.all(l).then(()=>e[t]=1):1}}})(),(()=>{var e;P.g.importScripts&&(e=P.g.location+"");var r=P.g.document;if(!e&&r&&(r.currentScript&&"SCRIPT"===r.currentScript.tagName.toUpperCase()&&(e=r.currentScript.src),!e)){var t=r.getElementsByTagName("script");if(t.length)for(var o=t.length-1;o>-1&&(!e||!/^http(s?):/.test(e));)e=t[o--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),P.p=e})(),t=e=>{var r=e=>e.split(".").map(e=>+e==e?+e:e),t=/^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(e),o=t[1]?r(t[1]):[];return t[2]&&(o.length++,o.push.apply(o,r(t[2]))),t[3]&&(o.push([]),o.push.apply(o,r(t[3]))),o},o=(e,r)=>{e=t(e),r=t(r);for(var o=0;;){if(o>=e.length)return o<r.length&&"u"!=(typeof r[o])[0];var n=e[o],a=(typeof n)[0];if(o>=r.length)return"u"==a;var i=r[o],u=(typeof i)[0];if(a!=u)return"o"==a&&"n"==u||"s"==u||"u"==a;if("o"!=a&&"u"!=a&&n!=i)return n<i;o++}},n=e=>{var r=e[0],t="";if(1===e.length)return"*";if(r+.5){t+=0==r?">=":-1==r?"<":1==r?"^":2==r?"~":r>0?"=":"!=";for(var o=1,a=1;a<e.length;a++)o--,t+="u"==(typeof(u=e[a]))[0]?"-":(o>0?".":"")+(o=2,u);return t}var i=[];for(a=1;a<e.length;a++){var u=e[a];i.push(0===u?"not("+l()+")":1===u?"("+l()+" || "+l()+")":2===u?i.pop()+" "+i.pop():n(u))}return l();function l(){return i.pop().replace(/^\((.+)\)$/,"$1")}},a=(e,r)=>{if(0 in e){r=t(r);var o=e[0],n=o<0;n&&(o=-o-1);for(var i=0,u=1,l=!0;;u++,i++){var s,f,d=u<e.length?(typeof e[u])[0]:"";if(i>=r.length||"o"==(f=(typeof(s=r[i]))[0]))return!l||("u"==d?u>o&&!n:""==d!=n);if("u"==f){if(!l||"u"!=d)return!1}else if(l)if(d==f)if(u<=o){if(s!=e[u])return!1}else{if(n?s>e[u]:s<e[u])return!1;s!=e[u]&&(l=!1)}else if("s"!=d&&"n"!=d){if(n||u<=o)return!1;l=!1,u--}else{if(u<=o||f<d!=n)return!1;l=!1}else"s"!=d&&"n"!=d&&(l=!1,u--)}}var c=[],p=c.pop.bind(c);for(i=1;i<e.length;i++){var h=e[i];c.push(1==h?p()|p():2==h?p()&p():h?a(h,r):!p())}return!!p()},i=(e,r)=>e&&P.o(e,r),u=e=>(e.loaded=1,e.get()),l=e=>Object.keys(e).reduce((r,t)=>(e[t].eager&&(r[t]=e[t]),r),{}),s=(e,r,t,n)=>{var i=n?l(e[r]):e[r];return(r=Object.keys(i).reduce((e,r)=>!a(t,r)||e&&!o(e,r)?e:r,0))&&i[r]},f=(e,r,t)=>{var n=t?l(e[r]):e[r];return Object.keys(n).reduce((e,r)=>!e||!n[e].loaded&&o(e,r)?r:e,0)},d=(e,r,t,o)=>"Unsatisfied version "+t+" from "+(t&&e[r][t].from)+" of shared singleton module "+r+" (required "+n(o)+")",c=(e,r,t,o,a)=>{var i=e[t];return"No satisfying version ("+n(o)+")"+(a?" for eager consumption":"")+" of shared module "+t+" found in shared scope "+r+".\nAvailable versions: "+Object.keys(i).map(e=>e+" from "+i[e].from).join(", ")},p=e=>{throw new Error(e)},h=e=>{"undefined"!=typeof console&&console.warn&&console.warn(e)},g=(e,r,t)=>t?t():((e,r)=>p("Shared module "+r+" doesn't exist in shared scope "+e))(e,r),b=(v=e=>function(r,t,o,n,a){var i=P.I(r);return i&&i.then&&!o?i.then(e.bind(e,r,P.S[r],t,!1,n,a)):e(r,P.S[r],t,o,n,a)})((e,r,t,o,n,a)=>{if(!i(r,t))return g(e,t,a);var l=s(r,t,n,o);return l?u(l):a?a():void p(c(r,e,t,n,o))}),m=v((e,r,t,o,n,l)=>{if(!i(r,t))return g(e,t,l);var s=f(r,t,o);return a(n,s)||h(d(r,t,s,n)),u(r[t][s])}),y={},w={389:()=>m("default","@jupyterlab/notebook",!1,[1,4,5,1]),460:()=>m("default","@jupyterlab/codemirror",!1,[1,4,5,1]),505:()=>b("default","@codemirror/autocomplete",!1,[1,6,0,1],()=>Promise.all([P.e(747),P.e(949)]).then(()=>()=>P(747))),591:()=>m("default","@jupyterlab/translation",!1,[1,4,5,1]),827:()=>m("default","@jupyterlab/apputils",!1,[1,4,6,1]),24:()=>m("default","@codemirror/view",!1,[1,6,9,6]),84:()=>m("default","@codemirror/language",!1,[1,6,0,0]),195:()=>m("default","@codemirror/state",!1,[1,6,2,0])},k={509:[389,460,505,591,827],949:[24,84,195]},S={},P.f.consumes=(e,r)=>{P.o(k,e)&&k[e].forEach(e=>{if(P.o(y,e))return r.push(y[e]);if(!S[e]){var t=r=>{y[e]=0,P.m[e]=t=>{delete P.c[e],t.exports=r()}};S[e]=!0;var o=r=>{delete y[e],P.m[e]=t=>{throw delete P.c[e],r}};try{var n=w[e]();n.then?r.push(y[e]=n.then(t).catch(o)):t(n)}catch(e){o(e)}}})},(()=>{var e={204:0};P.f.j=(r,t)=>{var o=P.o(e,r)?e[r]:void 0;if(0!==o)if(o)t.push(o[2]);else if(949!=r){var n=new Promise((t,n)=>o=e[r]=[t,n]);t.push(o[2]=n);var a=P.p+P.u(r),i=new Error;P.l(a,t=>{if(P.o(e,r)&&(0!==(o=e[r])&&(e[r]=void 0),o)){var n=t&&("load"===t.type?"missing":t.type),a=t&&t.target&&t.target.src;i.message="Loading chunk "+r+" failed.\n("+n+": "+a+")",i.name="ChunkLoadError",i.type=n,i.request=a,o[1](i)}},"chunk-"+r,r)}else e[r]=0};var r=(r,t)=>{var o,n,[a,i,u]=t,l=0;if(a.some(r=>0!==e[r])){for(o in i)P.o(i,o)&&(P.m[o]=i[o]);u&&u(P)}for(r&&r(t);l<a.length;l++)n=a[l],P.o(e,n)&&e[n]&&e[n][0](),e[n]=0},t=self.webpackChunkgennaker_tools=self.webpackChunkgennaker_tools||[];t.forEach(r.bind(null,0)),t.push=r.bind(null,t.push.bind(t))})(),P.nc=void 0;var T=P(842);(_JUPYTERLAB=void 0===_JUPYTERLAB?{}:_JUPYTERLAB)["gennaker-tools"]=T})();
1
+ var _JUPYTERLAB;(()=>{"use strict";var e,r,t,o,n,a,i,u,l,s,f,d,c,p,h,v,g,m,b,y,w,k,S,j={842:(e,r,t)=>{var o={"./index":()=>t.e(509).then(()=>()=>t(509)),"./extension":()=>t.e(509).then(()=>()=>t(509)),"./style":()=>t.e(728).then(()=>()=>t(728))},n=(e,r)=>(t.R=r,r=t.o(o,e)?o[e]():Promise.resolve().then(()=>{throw new Error('Module "'+e+'" does not exist in container.')}),t.R=void 0,r),a=(e,r)=>{if(t.S){var o="default",n=t.S[o];if(n&&n!==e)throw new Error("Container initialization failed as it has already been initialized with a different share scope");return t.S[o]=e,t.I(o,r)}};t.d(r,{get:()=>n,init:()=>a})}},E={};function P(e){var r=E[e];if(void 0!==r)return r.exports;var t=E[e]={id:e,exports:{}};return j[e](t,t.exports,P),t.exports}P.m=j,P.c=E,P.n=e=>{var r=e&&e.__esModule?()=>e.default:()=>e;return P.d(r,{a:r}),r},P.d=(e,r)=>{for(var t in r)P.o(r,t)&&!P.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},P.f={},P.e=e=>Promise.all(Object.keys(P.f).reduce((r,t)=>(P.f[t](e,r),r),[])),P.u=e=>e+"."+{509:"031cb77fbf5c28a28cdf",728:"c3ac4b62173ea8b3c44b",747:"28975bdde163d0eaf6e0"}[e]+".js?v="+{509:"031cb77fbf5c28a28cdf",728:"c3ac4b62173ea8b3c44b",747:"28975bdde163d0eaf6e0"}[e],P.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),P.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),e={},r="gennaker-tools:",P.l=(t,o,n,a)=>{if(e[t])e[t].push(o);else{var i,u;if(void 0!==n)for(var l=document.getElementsByTagName("script"),s=0;s<l.length;s++){var f=l[s];if(f.getAttribute("src")==t||f.getAttribute("data-webpack")==r+n){i=f;break}}i||(u=!0,(i=document.createElement("script")).charset="utf-8",P.nc&&i.setAttribute("nonce",P.nc),i.setAttribute("data-webpack",r+n),i.src=t),e[t]=[o];var d=(r,o)=>{i.onerror=i.onload=null,clearTimeout(c);var n=e[t];if(delete e[t],i.parentNode&&i.parentNode.removeChild(i),n&&n.forEach(e=>e(o)),r)return r(o)},c=setTimeout(d.bind(null,void 0,{type:"timeout",target:i}),12e4);i.onerror=d.bind(null,i.onerror),i.onload=d.bind(null,i.onload),u&&document.head.appendChild(i)}},P.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{P.S={};var e={},r={};P.I=(t,o)=>{o||(o=[]);var n=r[t];if(n||(n=r[t]={}),!(o.indexOf(n)>=0)){if(o.push(n),e[t])return e[t];P.o(P.S,t)||(P.S[t]={});var a=P.S[t],i="gennaker-tools",u=(e,r,t,o)=>{var n=a[e]=a[e]||{},u=n[r];(!u||!u.loaded&&(!o!=!u.eager?o:i>u.from))&&(n[r]={get:t,from:i,eager:!!o})},l=[];return"default"===t&&(u("@codemirror/autocomplete","6.19.1",()=>Promise.all([P.e(747),P.e(949)]).then(()=>()=>P(747))),u("gennaker-tools","0.2.0",()=>P.e(509).then(()=>()=>P(509)))),e[t]=l.length?Promise.all(l).then(()=>e[t]=1):1}}})(),(()=>{var e;P.g.importScripts&&(e=P.g.location+"");var r=P.g.document;if(!e&&r&&(r.currentScript&&"SCRIPT"===r.currentScript.tagName.toUpperCase()&&(e=r.currentScript.src),!e)){var t=r.getElementsByTagName("script");if(t.length)for(var o=t.length-1;o>-1&&(!e||!/^http(s?):/.test(e));)e=t[o--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),P.p=e})(),t=e=>{var r=e=>e.split(".").map(e=>+e==e?+e:e),t=/^([^-+]+)?(?:-([^+]+))?(?:\+(.+))?$/.exec(e),o=t[1]?r(t[1]):[];return t[2]&&(o.length++,o.push.apply(o,r(t[2]))),t[3]&&(o.push([]),o.push.apply(o,r(t[3]))),o},o=(e,r)=>{e=t(e),r=t(r);for(var o=0;;){if(o>=e.length)return o<r.length&&"u"!=(typeof r[o])[0];var n=e[o],a=(typeof n)[0];if(o>=r.length)return"u"==a;var i=r[o],u=(typeof i)[0];if(a!=u)return"o"==a&&"n"==u||"s"==u||"u"==a;if("o"!=a&&"u"!=a&&n!=i)return n<i;o++}},n=e=>{var r=e[0],t="";if(1===e.length)return"*";if(r+.5){t+=0==r?">=":-1==r?"<":1==r?"^":2==r?"~":r>0?"=":"!=";for(var o=1,a=1;a<e.length;a++)o--,t+="u"==(typeof(u=e[a]))[0]?"-":(o>0?".":"")+(o=2,u);return t}var i=[];for(a=1;a<e.length;a++){var u=e[a];i.push(0===u?"not("+l()+")":1===u?"("+l()+" || "+l()+")":2===u?i.pop()+" "+i.pop():n(u))}return l();function l(){return i.pop().replace(/^\((.+)\)$/,"$1")}},a=(e,r)=>{if(0 in e){r=t(r);var o=e[0],n=o<0;n&&(o=-o-1);for(var i=0,u=1,l=!0;;u++,i++){var s,f,d=u<e.length?(typeof e[u])[0]:"";if(i>=r.length||"o"==(f=(typeof(s=r[i]))[0]))return!l||("u"==d?u>o&&!n:""==d!=n);if("u"==f){if(!l||"u"!=d)return!1}else if(l)if(d==f)if(u<=o){if(s!=e[u])return!1}else{if(n?s>e[u]:s<e[u])return!1;s!=e[u]&&(l=!1)}else if("s"!=d&&"n"!=d){if(n||u<=o)return!1;l=!1,u--}else{if(u<=o||f<d!=n)return!1;l=!1}else"s"!=d&&"n"!=d&&(l=!1,u--)}}var c=[],p=c.pop.bind(c);for(i=1;i<e.length;i++){var h=e[i];c.push(1==h?p()|p():2==h?p()&p():h?a(h,r):!p())}return!!p()},i=(e,r)=>e&&P.o(e,r),u=e=>(e.loaded=1,e.get()),l=e=>Object.keys(e).reduce((r,t)=>(e[t].eager&&(r[t]=e[t]),r),{}),s=(e,r,t,n)=>{var i=n?l(e[r]):e[r];return(r=Object.keys(i).reduce((e,r)=>!a(t,r)||e&&!o(e,r)?e:r,0))&&i[r]},f=(e,r,t)=>{var n=t?l(e[r]):e[r];return Object.keys(n).reduce((e,r)=>!e||!n[e].loaded&&o(e,r)?r:e,0)},d=(e,r,t,o)=>"Unsatisfied version "+t+" from "+(t&&e[r][t].from)+" of shared singleton module "+r+" (required "+n(o)+")",c=(e,r,t,o,a)=>{var i=e[t];return"No satisfying version ("+n(o)+")"+(a?" for eager consumption":"")+" of shared module "+t+" found in shared scope "+r+".\nAvailable versions: "+Object.keys(i).map(e=>e+" from "+i[e].from).join(", ")},p=e=>{throw new Error(e)},h=e=>{"undefined"!=typeof console&&console.warn&&console.warn(e)},g=(e,r,t)=>t?t():((e,r)=>p("Shared module "+r+" doesn't exist in shared scope "+e))(e,r),m=(v=e=>function(r,t,o,n,a){var i=P.I(r);return i&&i.then&&!o?i.then(e.bind(e,r,P.S[r],t,!1,n,a)):e(r,P.S[r],t,o,n,a)})((e,r,t,o,n,a)=>{if(!i(r,t))return g(e,t,a);var l=s(r,t,n,o);return l?u(l):a?a():void p(c(r,e,t,n,o))}),b=v((e,r,t,o,n,l)=>{if(!i(r,t))return g(e,t,l);var s=f(r,t,o);return a(n,s)||h(d(r,t,s,n)),u(r[t][s])}),y={},w={285:()=>b("default","@jupyterlab/apputils",!1,[1,4,6,3]),505:()=>m("default","@codemirror/autocomplete",!1,[1,6,0,1],()=>Promise.all([P.e(747),P.e(949)]).then(()=>()=>P(747))),769:()=>b("default","@jupyterlab/translation",!1,[1,4,5,3]),790:()=>b("default","@jupyterlab/codemirror",!1,[1,4,5,3]),931:()=>b("default","@jupyterlab/notebook",!1,[1,4,5,3]),24:()=>b("default","@codemirror/view",!1,[1,6,9,6]),84:()=>b("default","@codemirror/language",!1,[1,6,0,0]),195:()=>b("default","@codemirror/state",!1,[1,6,2,0])},k={509:[285,505,769,790,931],949:[24,84,195]},S={},P.f.consumes=(e,r)=>{P.o(k,e)&&k[e].forEach(e=>{if(P.o(y,e))return r.push(y[e]);if(!S[e]){var t=r=>{y[e]=0,P.m[e]=t=>{delete P.c[e],t.exports=r()}};S[e]=!0;var o=r=>{delete y[e],P.m[e]=t=>{throw delete P.c[e],r}};try{var n=w[e]();n.then?r.push(y[e]=n.then(t).catch(o)):t(n)}catch(e){o(e)}}})},(()=>{var e={204:0};P.f.j=(r,t)=>{var o=P.o(e,r)?e[r]:void 0;if(0!==o)if(o)t.push(o[2]);else if(949!=r){var n=new Promise((t,n)=>o=e[r]=[t,n]);t.push(o[2]=n);var a=P.p+P.u(r),i=new Error;P.l(a,t=>{if(P.o(e,r)&&(0!==(o=e[r])&&(e[r]=void 0),o)){var n=t&&("load"===t.type?"missing":t.type),a=t&&t.target&&t.target.src;i.message="Loading chunk "+r+" failed.\n("+n+": "+a+")",i.name="ChunkLoadError",i.type=n,i.request=a,o[1](i)}},"chunk-"+r,r)}else e[r]=0};var r=(r,t)=>{var o,n,[a,i,u]=t,l=0;if(a.some(r=>0!==e[r])){for(o in i)P.o(i,o)&&(P.m[o]=i[o]);u&&u(P)}for(r&&r(t);l<a.length;l++)n=a[l],P.o(e,n)&&e[n]&&e[n][0](),e[n]=0},t=self.webpackChunkgennaker_tools=self.webpackChunkgennaker_tools||[];t.forEach(r.bind(null,0)),t.push=r.bind(null,t.push.bind(t))})(),P.nc=void 0;var T=P(842);(_JUPYTERLAB=void 0===_JUPYTERLAB?{}:_JUPYTERLAB)["gennaker-tools"]=T})();
@@ -0,0 +1,194 @@
1
+ from jupyter_server.extension.application import ExtensionApp
2
+ import jupyterlab.commands
3
+
4
+ from traitlets import Instance, default, validate, TraitError, Unicode
5
+ import pathlib
6
+ import watchfiles
7
+ import jupyter_server.serverapp
8
+ import asyncio
9
+ import aiofiles.os
10
+ import tomli
11
+ import json5
12
+ import tomli_w
13
+ import os
14
+
15
+
16
+ class SettingsSyncApp(ExtensionApp):
17
+ # -------------- Required traits --------------
18
+ name = "settings-sync"
19
+ load_other_extensions = True
20
+ settings_path = Instance(pathlib.Path)
21
+ null_sentinel = Unicode("__NULL__")
22
+
23
+ _task = Instance(asyncio.Task, allow_none=True)
24
+ _event = Instance(asyncio.Event, allow_none=True)
25
+
26
+ @default("settings_path")
27
+ def _default_settings_path(self):
28
+ return pathlib.Path(jupyterlab.commands.get_user_settings_dir())
29
+
30
+ @validate("settings_path")
31
+ def _valid_settings_path(self, proposal):
32
+ try:
33
+ _path = pathlib.Path(proposal["value"])
34
+ except TypeError:
35
+ raise TraitError("settings_path should be a valid pathlike value")
36
+ return _path
37
+
38
+ def _json_mapping_to_toml(self, mapping):
39
+ return {
40
+ key: self._json_mapping_to_toml(value)
41
+ if isinstance(value, dict)
42
+ else self.null_sentinel
43
+ if value is None
44
+ else value
45
+ for key, value in mapping.items()
46
+ }
47
+
48
+ def _toml_mapping_to_json(self, mapping):
49
+ return {
50
+ key: self._toml_mapping_to_json(value)
51
+ if isinstance(value, dict)
52
+ else None
53
+ if value == self.null_sentinel
54
+ else value
55
+ for key, value in mapping.items()
56
+ }
57
+
58
+ def _toml_to_settings_path(self, path: pathlib.Path) -> pathlib.Path:
59
+ return path.with_name(path.stem)
60
+
61
+ def _settings_to_toml_path(self, path: pathlib.Path) -> pathlib.Path:
62
+ return path.with_name(f"{path.name}.toml")
63
+
64
+ def _is_settings_path(self, path: pathlib.Path) -> bool:
65
+ return path.suffix == ".jupyterlab-settings"
66
+
67
+ def _is_toml_path(self, path: pathlib.Path) -> bool:
68
+ return path.suffix == ".toml"
69
+
70
+ async def _watched_files_need_sync(
71
+ self, path: pathlib.Path, other_path: pathlib.Path
72
+ ) -> bool:
73
+ return not (
74
+ path.exists()
75
+ and other_path.exists()
76
+ and path.stat().st_mtime == other_path.stat().st_mtime
77
+ )
78
+
79
+ async def _sync_watched_files(self, path: pathlib.Path, other_path: pathlib.Path):
80
+ try:
81
+ if self._is_settings_path(path):
82
+ self.log.debug(f"Synchronising JSON to TOML for {path}")
83
+ settings = self._json_mapping_to_toml(json5.loads(path.read_text()))
84
+ with open(other_path, "wb") as f:
85
+ tomli_w.dump(settings, f)
86
+
87
+ else:
88
+ self.log.debug(f"Synchronising TOML to JSON for {path}")
89
+ with open(path, "rb") as f:
90
+ settings = self._toml_mapping_to_json(tomli.load(f))
91
+ with open(other_path, "w") as sf:
92
+ json5.dump(settings, sf, indent=2)
93
+
94
+ # Sync mtimes
95
+ stat = path.stat()
96
+ os.utime(other_path, (stat.st_atime, stat.st_mtime))
97
+
98
+ except Exception as exc:
99
+ self.log.error(f"Error reconciling {path} with {other_path} {exc}")
100
+
101
+ async def _unsync_watched_files(self, path: pathlib.Path, other_path: pathlib.Path):
102
+ if self._is_settings_path(path) and other_path.exists():
103
+ other_path.unlink()
104
+
105
+ async def _reconcile_initial(self, root_path):
106
+ """
107
+ Reconcile existing files. No files will be deleted.
108
+ """
109
+ tasks = []
110
+
111
+ async def reconcile(path):
112
+ for entry in await aiofiles.os.scandir(path):
113
+ entry_path = pathlib.Path(entry.path)
114
+
115
+ if entry.is_dir():
116
+ await reconcile(entry_path)
117
+ elif (
118
+ is_settings_path := self._is_settings_path(entry_path)
119
+ ) or self._is_toml_path(entry_path):
120
+ other_path = (
121
+ self._settings_to_toml_path(entry_path)
122
+ if is_settings_path
123
+ else self._toml_to_settings_path(entry_path)
124
+ )
125
+ # Reconcile onto the "other" file if it doesn't exist, or it's older than us
126
+ if (
127
+ not other_path.exists()
128
+ or other_path.stat().st_mtime <= entry.stat().st_mtime
129
+ ):
130
+ tasks.append(self._sync_watched_files(entry_path, other_path))
131
+
132
+ await reconcile(root_path)
133
+ await asyncio.gather(*tasks)
134
+
135
+ async def _event_loop(self):
136
+ await self._reconcile_initial(self.settings_path)
137
+ async for changes in watchfiles.awatch(
138
+ self.settings_path, stop_event=self._event
139
+ ):
140
+ for change, _path in changes:
141
+ await self._reconcile_change(change, pathlib.Path(_path))
142
+
143
+ async def _reconcile_change(self, change, path):
144
+ # Ignore .~ files
145
+ if path.name.startswith(".~"):
146
+ return
147
+
148
+ # Only process settings files
149
+ path_is_toml = self._is_toml_path(path)
150
+ if not (path_is_toml or self._is_settings_path(path)):
151
+ return
152
+
153
+ # Find other path
154
+ other_path = (
155
+ self._toml_to_settings_path(path)
156
+ if path_is_toml
157
+ else self._settings_to_toml_path(path)
158
+ )
159
+
160
+ self.log.debug(f"Detected filesystem change {change} in {path} file")
161
+
162
+ match change:
163
+ # Now we have either TOML or JSON setting files
164
+ # File needs deleting
165
+ case watchfiles.Change.deleted:
166
+ self.log.info(f"Detected deletion of {path.name} file, synchronising")
167
+ await self._unsync_watched_files(path, other_path)
168
+ case watchfiles.Change.added:
169
+ if await self._watched_files_need_sync(path, other_path):
170
+ self.log.info(
171
+ f"Detected addition of {path.name} file, creating {other_path.name}"
172
+ )
173
+ await self._sync_watched_files(path, other_path)
174
+ case watchfiles.Change.modified:
175
+ if await self._watched_files_need_sync(path, other_path):
176
+ self.log.info(
177
+ f"Detected modification of {path.name} file, updating {other_path.name}"
178
+ )
179
+ await self._sync_watched_files(path, other_path)
180
+
181
+ async def _start_jupyter_server_extension(self, app):
182
+ self._event = asyncio.Event()
183
+ self._task = asyncio.create_task(self._event_loop())
184
+
185
+ async def stop_extension(self):
186
+ if self._event is not None:
187
+ self._event.set()
188
+ try:
189
+ await self._task
190
+ except asyncio.CancelledError:
191
+ pass
192
+ finally:
193
+ self._event = None
194
+ self._task = None
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gennaker-tools",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "A JupyterLab extension to provide a restart-and-run-to-selected command variant that clears non-executed cell outputs.",
5
5
  "keywords": [
6
6
  "jupyter",
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
6
6
  name = "gennaker-tools"
7
7
  readme = "README.md"
8
8
  license = { file = "LICENSE" }
9
- requires-python = ">=3.9"
9
+ requires-python = ">=3.10"
10
10
  classifiers = [
11
11
  "Framework :: Jupyter",
12
12
  "Framework :: Jupyter :: JupyterLab",
@@ -26,7 +26,8 @@ dependencies = [
26
26
  "tomli",
27
27
  "tomli_w",
28
28
  "watchfiles",
29
- "aiofiles"
29
+ "aiofiles",
30
+ "json5"
30
31
  ]
31
32
  dynamic = ["version", "description", "authors", "urls", "keywords"]
32
33
 
@@ -1,132 +0,0 @@
1
- from jupyter_server.extension.application import ExtensionApp
2
- import jupyterlab.commands
3
-
4
- from traitlets import Instance, default, validate, TraitError
5
- import pathlib
6
- import watchfiles
7
- import jupyter_server.serverapp
8
- import asyncio
9
- import tomli
10
- import json
11
- import tomli_w
12
- import re
13
- import os
14
-
15
-
16
- class SettingsSyncApp(ExtensionApp):
17
- # -------------- Required traits --------------
18
- name = "settings-sync"
19
- load_other_extensions = True
20
- settings_path = Instance(pathlib.Path)
21
-
22
- _task = Instance(asyncio.Task, allow_none=True)
23
- _event = Instance(asyncio.Event, allow_none=True)
24
-
25
- @default("settings_path")
26
- def _default_settings_path(self):
27
- return pathlib.Path(jupyterlab.commands.get_user_settings_dir())
28
-
29
- @validate("settings_path")
30
- def _valid_settings_path(self, proposal):
31
- try:
32
- _path = pathlib.Path(proposal["value"])
33
- except TypeError:
34
- raise TraitError("settings_path should be a valid pathlike value")
35
- return _path
36
-
37
- def _toml_to_settings_path(self, path: pathlib.Path) -> pathlib.Path:
38
- return path.with_name(path.stem)
39
-
40
- def _settings_to_toml_path(self, path: pathlib.Path) -> pathlib.Path:
41
- return path.with_name(f"{path.name}.toml")
42
-
43
- def _is_settings_path(self, path: pathlib.Path) -> bool:
44
- return path.suffix == ".jupyterlab-settings"
45
-
46
- def _is_toml_path(self, path: pathlib.Path) -> bool:
47
- return path.suffix == ".toml"
48
-
49
- def _strip_comments(self, source: str) -> str:
50
- without_single_line_comments = re.sub(r"//.*$", "", source, flags=re.MULTILINE)
51
-
52
- return re.sub(
53
- r"/\*[\s\S]*?\*/", "", without_single_line_comments, flags=re.MULTILINE
54
- )
55
-
56
- async def _watched_files_need_sync(
57
- self, path: pathlib.Path, other_path: pathlib.Path
58
- ) -> bool:
59
- return path.stat().st_mtime != other_path.stat().st_mtime
60
-
61
- async def _sync_watched_files(self, path: pathlib.Path, other_path: pathlib.Path):
62
- self.log.info(f"Detected change in {path} file, synchronising")
63
- if self._is_settings_path(path):
64
- settings = json.loads(self._strip_comments(path.read_text()))
65
- with open(other_path, "wb") as f:
66
- tomli_w.dump(settings, f)
67
-
68
- else:
69
- with open(path, "rb") as f:
70
- settings = tomli.load(f)
71
- with open(other_path, "w") as sf:
72
- json.dump(settings, sf, indent=2)
73
-
74
- # Sync mtimes
75
- stat = path.stat()
76
- os.utime(other_path, (stat.st_atime, stat.st_mtime))
77
-
78
- async def _unsync_watched_files(self, path: pathlib.Path, other_path: pathlib.Path):
79
- if self._is_settings_path(path) and other_path.exists():
80
- other_path.unlink()
81
-
82
- async def _event_loop(self):
83
- async for changes in watchfiles.awatch(
84
- self.settings_path, stop_event=self._event
85
- ):
86
- for change, _path in changes:
87
- try:
88
- await self._reconcile_change(change, pathlib.Path(_path))
89
- except Exception as exc:
90
- self.log.error(exc)
91
-
92
- async def _reconcile_change(self, change, path):
93
- # Ignore .~ files
94
- if path.name.startswith(".~"):
95
- return
96
-
97
- # Only process settings files
98
- path_is_toml = self._is_toml_path(path)
99
- if not (path_is_toml or self._is_settings_path(path)):
100
- return
101
-
102
- # Find other path
103
- other_path = (
104
- self._toml_to_settings_path(path)
105
- if path_is_toml
106
- else self._settings_to_toml_path(path)
107
- )
108
-
109
- # Now we have either TOML or JSON setting files
110
- # File needs deleting
111
- if change == watchfiles.Change.deleted:
112
- await self._unsync_watched_files(path, other_path)
113
-
114
- # Files might need syncing
115
- elif change == watchfiles.Change.added or change == watchfiles.Change.modified:
116
- if await self._watched_files_need_sync(path, other_path):
117
- await self._sync_watched_files(path, other_path)
118
-
119
- async def _start_jupyter_server_extension(self, app):
120
- self._event = asyncio.Event()
121
- self._task = asyncio.create_task(self._event_loop())
122
-
123
- async def stop_extension(self):
124
- if self._event is not None:
125
- self._event.set()
126
- try:
127
- await self._task
128
- except asyncio.CancelledError:
129
- pass
130
- finally:
131
- self._event = None
132
- self._task = None
File without changes
File without changes
File without changes
File without changes
File without changes