Repository: mwouts/itables (language: python)

Issue:
Transition ITables to the `src` layout
In prevision of #245 I would like to transition ITables to the [`src` layout](https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/).

@mahendrapaipuri do you think you could give me a hand on this?

This is what I am wondering:
- Where should the `dt_for_itables` node package go? Currently it is at `itables/dt_for_itables`, should I move it at `src/dt_for_itables`? Or at the root of the project? Note that the Python package uses `dt_bundle.js` and `dt_bundle.css` that are created by that package
- Can I create a `src/itables_for_dash` folder with more or less [this content](https://github.com/plotly/dash-component-boilerplate/tree/master/%7B%7Bcookiecutter.project_shortname%7D%7D) (e.g. a node package, a Python package, and optionally a R and Julia package)? Or should I move that somewhere else? I would much prefer **not to** create another repo for that.
- Should I move the `html` folder currently within `itables` (with the html table template) at some other location, or is the current location fine?


Discussion / hints:
If you want to use `src-layout`, I think a sensible organization would be as follows

```
├── packages
│   └── dt_tables
│       ├── package.json
│       └── src
│           └── index.js
└── src
    └── itables

```

Basically that is how most of JupyterLab packages are organized. Then you will have to move the transpiled `js` assets to `src/itables/js/<some_name>.js` file so that you can distribute it with `wheel` and `sdist`. I mean the same strategy that we use for Jupytext.

You can keep `html` folder within the same folder as `itables` but during installation, it is more cleaner if you install it at `sys.prefix/share/itables/html` as they are data files and not package files. Similarly the transpiled `js` can be installed at `sys.prefix/share/itables/js` during installation. 

Does it make sense to you?
Thanks @mahendrapaipuri! Yes that makes perfect sense. I'll give this a try over the week-end, thanks for the advice!

Fix patch:
diff --git a/README.md b/README.md
index e94b8230..cfc36d64 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-![ITables Logo](itables/logo/wide.svg)
+![ITables logo](https://raw.githubusercontent.com/mwouts/itables/3f8e8bd75af7ad38a500518fcb4fbbc370ea6c4c/itables/logo/wide.svg)
 
 ![CI](https://github.com/mwouts/itables/actions/workflows/continuous-integration.yml/badge.svg?branch=main)
 [![codecov.io](https://codecov.io/github/mwouts/itables/coverage.svg?branch=main)](https://codecov.io/github/mwouts/itables?branch=main)
diff --git a/docs/_config.yml b/docs/_config.yml
index 748c067d..26886116 100644
--- a/docs/_config.yml
+++ b/docs/_config.yml
@@ -1,7 +1,7 @@
 title: Interactive Tables
 author: Marc Wouts
 copyright: "2019-2024"
-logo: "../itables/logo/logo.svg"
+logo: "../src/itables/logo/logo.svg"
 execute:
   execute_notebooks: force
 sphinx:
diff --git a/docs/changelog.md b/docs/changelog.md
index ad1a3ec5..6af89975 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -1,6 +1,13 @@
 ITables ChangeLog
 =================
 
+2.1.0-dev (2024-05-??)
+------------------
+
+**Changed**
+- ITables now uses the `src` layout ([#246](https://github.com/mwouts/itables/issues/246)) - many thanks to [Mahendra Paipuri](https://github.com/mahendrapaipuri) for his help on this topic!
+
+
 2.0.1 (2024-04-30)
 ------------------
 
diff --git a/docs/custom_extensions.md b/docs/custom_extensions.md
index 9b450c30..5de5effe 100644
--- a/docs/custom_extensions.md
+++ b/docs/custom_extensions.md
@@ -53,18 +53,26 @@ To use custom extensions in the offline mode, you will need
 to create a bundle of jQuery, DataTables, and the desired extensions.
 
 To do so, make a copy of
-[`itables/dt_for_itables`](https://github.com/mwouts/itables/tree/main/itables/dt_for_itables):
+[`packages/dt_for_itables`](https://github.com/mwouts/itables/tree/main/packages/dt_for_itables):
 ```bash
-$ ls itables/dt_for_itables/
-package.json  package-lock.json  README.md  src.js
+$ tree
+```
+```
+.
+├── LICENSE
+├── package.json
+├── package-lock.json
+├── README.md
+└── src
+    └── index.js
 ```
 
-Add or remove the desired extensions in `package.json` and `src.js`. To do this,
+Add or remove the desired extensions in `package.json` and `src/index.js`. To do this,
 you can use the [DataTables download](https://datatables.net/download/) page and
 follow the instructions for the _NPM_ download method.
 
 For instance, say you want to bundle the PDF export button. Change
-`src.js` to this code:
+`src/index.js` to this code:
 ```javascript
 import JSZip from 'jszip';
 import jQuery from 'jquery';
diff --git a/docs/quick_start.md b/docs/quick_start.md
index bbaabe89..0f842033 100644
--- a/docs/quick_start.md
+++ b/docs/quick_start.md
@@ -12,7 +12,7 @@ kernelspec:
   name: itables
 ---
 
-![ITables Logo](../itables/logo/text.svg)
+![ITables Logo](../src/itables/logo/text.svg)
 
 ![CI](https://github.com/mwouts/itables/actions/workflows/continuous-integration.yml/badge.svg?branch=main)
 [![codecov.io](https://codecov.io/github/mwouts/itables/coverage.svg?branch=main)](https://codecov.io/github/mwouts/itables?branch=main)
diff --git a/itables/dt_for_itables/LICENSE b/packages/dt_for_itables/LICENSE
similarity index 100%
rename from itables/dt_for_itables/LICENSE
rename to packages/dt_for_itables/LICENSE
diff --git a/itables/dt_for_itables/README.md b/packages/dt_for_itables/README.md
similarity index 97%
rename from itables/dt_for_itables/README.md
rename to packages/dt_for_itables/README.md
index 5b7bd4d4..8af8aa40 100644
--- a/itables/dt_for_itables/README.md
+++ b/packages/dt_for_itables/README.md
@@ -8,7 +8,7 @@ and some of its extensions for [ITables](https://github.com/mwouts/itables/).
 Run the following commands:
 ```bash
 npm install
-npm run build
+npm run build:js
 ```
 
 # How to update the dependencies
diff --git a/itables/dt_for_itables/package-lock.json b/packages/dt_for_itables/package-lock.json
similarity index 100%
rename from itables/dt_for_itables/package-lock.json
rename to packages/dt_for_itables/package-lock.json
diff --git a/itables/dt_for_itables/package.json b/packages/dt_for_itables/package.json
similarity index 79%
rename from itables/dt_for_itables/package.json
rename to packages/dt_for_itables/package.json
index 51d997be..85763b04 100644
--- a/itables/dt_for_itables/package.json
+++ b/packages/dt_for_itables/package.json
@@ -4,7 +4,9 @@
   "description": "DataTables bundle for itables",
   "main": "src.js",
   "scripts": {
-    "build": "esbuild src.js --format=esm --bundle --outfile=dt_bundle.js --minify"
+    "build:js": "esbuild src/index.js --format=esm --bundle --outfile=dt_bundle.js --minify",
+    "install:js": "cp dt_bundle.js dt_bundle.css  ../../src/itables/html",
+    "build": "npm run build:js && npm run install:js"
   },
   "author": "Marc Wouts",
   "license": "MIT",
diff --git a/itables/dt_for_itables/src.js b/packages/dt_for_itables/src/index.js
similarity index 100%
rename from itables/dt_for_itables/src.js
rename to packages/dt_for_itables/src/index.js
diff --git a/pyproject.toml b/pyproject.toml
index b3530c4e..4b7203f0 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -50,7 +50,7 @@ test = [
 ]
 
 [tool.hatch.version]
-path = "itables/version.py"
+path = "src/itables/version.py"
 
 [project.urls]
 Homepage = "https://mwouts.github.io/itables/"
@@ -76,15 +76,15 @@ exclude_lines = [
 enable-by-default = true
 dependencies = ["hatch-jupyter-builder"]
 build-function = "hatch_jupyter_builder.npm_builder"
-ensured-targets = ["itables/dt_for_itables/dt_bundle.js", "itables/dt_for_itables/dt_bundle.css"]
+ensured-targets = ["src/itables/html/dt_bundle.js", "src/itables/html/dt_bundle.css"]
 
 [tool.hatch.build.hooks.jupyter-builder.build-kwargs]
-path = "itables/dt_for_itables"
+path = "packages/dt_for_itables"
 build_cmd = "build"
 npm = ["npm"]
 
 [tool.hatch.build.targets.sdist]
-artifacts = ["itables/dt_for_itables/dt_bundle.js", "itables/dt_for_itables/dt_bundle.css"]
+artifacts = ["src/itables/html/dt_bundle.js", "src/itables/html/dt_bundle.css"]
 
 [tool.hatch.build.targets.wheel]
-artifacts = ["itables/dt_for_itables/dt_bundle.js", "itables/dt_for_itables/dt_bundle.css"]
+artifacts = ["src/itables/html/dt_bundle.js", "src/itables/html/dt_bundle.css"]
diff --git a/itables/__init__.py b/src/itables/__init__.py
similarity index 100%
rename from itables/__init__.py
rename to src/itables/__init__.py
diff --git a/itables/datatables_format.py b/src/itables/datatables_format.py
similarity index 100%
rename from itables/datatables_format.py
rename to src/itables/datatables_format.py
diff --git a/itables/downsample.py b/src/itables/downsample.py
similarity index 100%
rename from itables/downsample.py
rename to src/itables/downsample.py
diff --git a/itables/html/column_filters/initComplete.js b/src/itables/html/column_filters/initComplete.js
similarity index 100%
rename from itables/html/column_filters/initComplete.js
rename to src/itables/html/column_filters/initComplete.js
diff --git a/itables/html/column_filters/pre_dt_code.js b/src/itables/html/column_filters/pre_dt_code.js
similarity index 100%
rename from itables/html/column_filters/pre_dt_code.js
rename to src/itables/html/column_filters/pre_dt_code.js
diff --git a/itables/html/datatables_template.html b/src/itables/html/datatables_template.html
similarity index 100%
rename from itables/html/datatables_template.html
rename to src/itables/html/datatables_template.html
diff --git a/itables/html/init_datatables.html b/src/itables/html/init_datatables.html
similarity index 100%
rename from itables/html/init_datatables.html
rename to src/itables/html/init_datatables.html
diff --git a/itables/interactive.py b/src/itables/interactive.py
similarity index 100%
rename from itables/interactive.py
rename to src/itables/interactive.py
diff --git a/itables/javascript.py b/src/itables/javascript.py
similarity index 100%
rename from itables/javascript.py
rename to src/itables/javascript.py
diff --git a/itables/logo/loading.svg b/src/itables/logo/loading.svg
similarity index 100%
rename from itables/logo/loading.svg
rename to src/itables/logo/loading.svg
diff --git a/itables/logo/logo.svg b/src/itables/logo/logo.svg
similarity index 100%
rename from itables/logo/logo.svg
rename to src/itables/logo/logo.svg
diff --git a/itables/logo/text.svg b/src/itables/logo/text.svg
similarity index 100%
rename from itables/logo/text.svg
rename to src/itables/logo/text.svg
diff --git a/itables/logo/wide.svg b/src/itables/logo/wide.svg
similarity index 100%
rename from itables/logo/wide.svg
rename to src/itables/logo/wide.svg
diff --git a/itables/logo/with_text.svg b/src/itables/logo/with_text.svg
similarity index 100%
rename from itables/logo/with_text.svg
rename to src/itables/logo/with_text.svg
diff --git a/itables/options.py b/src/itables/options.py
similarity index 96%
rename from itables/options.py
rename to src/itables/options.py
index a1cf9033..9c7183b0 100644
--- a/itables/options.py
+++ b/src/itables/options.py
@@ -61,7 +61,7 @@
 dt_url = UNPKG_DT_BUNDLE_URL
 
 """The DataTable bundle for the offline mode"""
-dt_bundle = find_package_file("dt_for_itables/dt_bundle.js")
+dt_bundle = find_package_file("html/dt_bundle.js")
 
 """Display the ITables animated logo when loading"""
 display_logo_when_loading = True
diff --git a/itables/sample_dfs.py b/src/itables/sample_dfs.py
similarity index 100%
rename from itables/sample_dfs.py
rename to src/itables/sample_dfs.py
diff --git a/itables/samples/countries.csv b/src/itables/samples/countries.csv
similarity index 100%
rename from itables/samples/countries.csv
rename to src/itables/samples/countries.csv
diff --git a/itables/samples/indicators.csv b/src/itables/samples/indicators.csv
similarity index 100%
rename from itables/samples/indicators.csv
rename to src/itables/samples/indicators.csv
diff --git a/itables/samples/population.csv b/src/itables/samples/population.csv
similarity index 100%
rename from itables/samples/population.csv
rename to src/itables/samples/population.csv
diff --git a/itables/shiny.py b/src/itables/shiny.py
similarity index 100%
rename from itables/shiny.py
rename to src/itables/shiny.py
diff --git a/itables/utils.py b/src/itables/utils.py
similarity index 100%
rename from itables/utils.py
rename to src/itables/utils.py
diff --git a/itables/version.py b/src/itables/version.py
similarity index 54%
rename from itables/version.py
rename to src/itables/version.py
index 2104eec6..537a34c1 100644
--- a/itables/version.py
+++ b/src/itables/version.py
@@ -1,3 +1,3 @@
 """ITables' version number"""
 
-__version__ = "2.0.1"
+__version__ = "2.1.0-dev"


Test patch:
diff --git a/tests/test_javascript.py b/tests/test_javascript.py
index ad562cce..e3a4b094 100644
--- a/tests/test_javascript.py
+++ b/tests/test_javascript.py
@@ -114,7 +114,7 @@ def test_unpkg_links(url):
 
 
 def test_unpkg_urls_are_up_to_date():
-    with open(Path(__file__).parent / "../itables/dt_for_itables/package.json") as fp:
+    with open(Path(__file__).parent / "../packages/dt_for_itables/package.json") as fp:
         dt_for_itables = json.load(fp)
     bundle_version = dt_for_itables["version"]
     assert (
diff --git a/tests/test_update_samples.py b/tests/test_update_samples.py
index f4b38cf2..7e2204f8 100644
--- a/tests/test_update_samples.py
+++ b/tests/test_update_samples.py
@@ -2,7 +2,7 @@
 
 import world_bank_data as wb
 
-SAMPLE_DIR = Path(__file__).parent / ".." / "itables" / "samples"
+SAMPLE_DIR = Path(__file__).parent / ".." / "src" / "itables" / "samples"
 
 
 def create_csv_file_if_missing(df, csv_file):