Skip to content

Commit d1059d6

Browse files
Merge pull request #1071 from guzman-raphael/codespaces
Add `devcontainer` environment suitable for development
2 parents 5245124 + a8edd19 commit d1059d6

File tree

13 files changed

+445
-452
lines changed

13 files changed

+445
-452
lines changed

.devcontainer/Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Note: You can use any Debian/Ubuntu based image you want.
2+
FROM mcr.microsoft.com/devcontainers/python:3.7-bullseye
3+
4+
RUN \
5+
apt update && \
6+
apt-get install bash-completion graphviz default-mysql-client -y && \
7+
pip install flake8 black faker ipykernel nose nose-cov datajoint && \
8+
pip uninstall datajoint -y
9+
10+
ENV DJ_HOST fakeservices.datajoint.io
11+
ENV DJ_USER root
12+
ENV DJ_PASS simple

.devcontainer/devcontainer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
{
3+
"name": "Development",
4+
"dockerComposeFile": "docker-compose.yaml",
5+
"service": "app",
6+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
7+
// Use this environment variable if you need to bind mount your local source code into a new container.
8+
"remoteEnv": {
9+
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
10+
},
11+
// https://containers.dev/features
12+
"features": {
13+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
14+
"ghcr.io/devcontainers/features/git:1": {},
15+
"ghcr.io/eitsupi/devcontainer-features/jq-likes:1": {},
16+
"ghcr.io/guiyomh/features/vim:0": {}
17+
},
18+
"onCreateCommand": "pip install -e .",
19+
"postStartCommand": "MYSQL_VER=5.7 MINIO_VER=RELEASE.2022-08-11T04-37-28Z docker compose -f local-docker-compose.yml up --build -d",
20+
"customizations": {
21+
"vscode": {
22+
"extensions": [
23+
"ms-python.python"
24+
]
25+
}
26+
}
27+
}

.devcontainer/docker-compose.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: "3"
2+
services:
3+
app:
4+
build: .
5+
extra_hosts:
6+
- fakeservices.datajoint.io:127.0.0.1
7+
volumes:
8+
- ../..:/workspaces:cached
9+
entrypoint: /usr/local/share/docker-init.sh
10+
command: tail -f /dev/null

.github/workflows/development.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@ name: Development
22
on:
33
push:
44
branches:
5-
- '**' # every branch
6-
- '!gh-pages' # exclude gh-pages branch
7-
- '!stage*' # exclude branches beginning with stage
5+
- "**" # every branch
6+
- "!gh-pages" # exclude gh-pages branch
7+
- "!stage*" # exclude branches beginning with stage
88
tags:
99
- '\d+\.\d+\.\d+' # only semver tags
1010
pull_request:
1111
branches:
12-
- '**' # every branch
13-
- '!gh-pages' # exclude gh-pages branch
14-
- '!stage*' # exclude branches beginning with stage
12+
- "**" # every branch
13+
- "!gh-pages" # exclude gh-pages branch
14+
- "!stage*" # exclude branches beginning with stage
1515
jobs:
1616
build:
1717
runs-on: ubuntu-latest
1818
strategy:
1919
matrix:
2020
include:
21-
- py_ver: '3.9'
21+
- py_ver: "3.9"
2222
distro: debian
2323
image: djbase
2424
env:
@@ -77,6 +77,7 @@ jobs:
7777
- name: Run primary tests
7878
env:
7979
PY_VER: ${{matrix.py_ver}}
80+
DJ_PASS: simple
8081
MYSQL_VER: ${{matrix.mysql_ver}}
8182
DISTRO: alpine
8283
MINIO_VER: RELEASE.2021-09-03T03-56-13Z
@@ -119,7 +120,7 @@ jobs:
119120
strategy:
120121
matrix:
121122
include:
122-
- py_ver: '3.9'
123+
- py_ver: "3.9"
123124
distro: debian
124125
image: djbase
125126
env:

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ build/
2121
*.env
2222
docker-compose.yml
2323
notebook
24-
.vscode
2524
__main__.py
2625
jupyter_custom.js
2726
.eggs
2827
*.code-workspace
2928
docs/site
29+
30+
31+
!.vscode/settings.json
32+
!.devcontainer/devcontainer.json

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"editor.formatOnPaste": false,
3+
"editor.formatOnSave": true,
4+
"editor.rulers": [
5+
94
6+
],
7+
"python.formatting.provider": "black",
8+
"[python]": {
9+
"editor.defaultFormatter": null
10+
}
11+
}

CHANGELOG.md

Lines changed: 209 additions & 207 deletions
Large diffs are not rendered by default.

LNX-docker-compose.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
# docker compose -f LNX-docker-compose.yml --env-file LNX.env up --exit-code-from app --build
2-
version: '2.4'
1+
# PY_VER=3.8 MYSQL_VER=5.7 DISTRO=alpine MINIO_VER=RELEASE.2022-08-11T04-37-28Z HOST_UID=$(id -u) docker compose -f LNX-docker-compose.yml up --exit-code-from app --build
2+
version: "2.4"
33
x-net: &net
44
networks:
5-
- main
5+
- main
66
services:
77
db:
88
<<: *net
99
image: datajoint/mysql:${MYSQL_VER}
1010
environment:
11-
- MYSQL_ROOT_PASSWORD=simple
11+
- MYSQL_ROOT_PASSWORD=${DJ_PASS}
1212
# ports:
1313
# - "3306:3306"
1414
# volumes:
@@ -34,12 +34,12 @@ services:
3434
<<: *net
3535
image: datajoint/nginx:v0.2.4
3636
environment:
37-
- ADD_db_TYPE=DATABASE
38-
- ADD_db_ENDPOINT=db:3306
39-
- ADD_minio_TYPE=MINIO
40-
- ADD_minio_ENDPOINT=minio:9000
41-
- ADD_minio_PORT=80 # allow unencrypted connections
42-
- ADD_minio_PREFIX=/datajoint
37+
- ADD_db_TYPE=DATABASE
38+
- ADD_db_ENDPOINT=db:3306
39+
- ADD_minio_TYPE=MINIO
40+
- ADD_minio_ENDPOINT=minio:9000
41+
- ADD_minio_PORT=80 # allow unencrypted connections
42+
- ADD_minio_PREFIX=/datajoint
4343
# ports:
4444
# - "80:80"
4545
# - "443:443"
@@ -58,7 +58,7 @@ services:
5858
environment:
5959
- DJ_HOST=fakeservices.datajoint.io
6060
- DJ_USER=root
61-
- DJ_PASS=simple
61+
- DJ_PASS
6262
- DJ_TEST_HOST=fakeservices.datajoint.io
6363
- DJ_TEST_USER=datajoint
6464
- DJ_TEST_PASSWORD=datajoint

README.md

Lines changed: 14 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -6,161 +6,28 @@
66
[![Slack](https://img.shields.io/badge/slack-chat-green.svg)](https://datajoint.slack.com/)
77

88
# Welcome to DataJoint for Python!
9+
910
DataJoint for Python is a framework for scientific workflow management based on relational principles. DataJoint is built on the foundation of the relational data model and prescribes a consistent method for organizing, populating, computing, and querying data.
1011

1112
DataJoint was initially developed in 2009 by Dimitri Yatsenko in Andreas Tolias' Lab at Baylor College of Medicine for the distributed processing and management of large volumes of data streaming from regular experiments. Starting in 2011, DataJoint has been available as an open-source project adopted by other labs and improved through contributions from several developers.
12-
Presently, the primary developer of DataJoint open-source software is the company DataJoint (https://datajoint.com). Related resources are listed at https://datajoint.org.
13-
14-
## Installation
15-
```
16-
pip3 install datajoint
17-
```
13+
Presently, the primary developer of DataJoint open-source software is the company DataJoint (https://datajoint.com).
1814

19-
If you already have an older version of DataJoint installed using `pip`, upgrade with
20-
```bash
21-
pip3 install --upgrade datajoint
22-
```
15+
- [Getting Started](https://datajoint.com/docs/core/datajoint-python/latest/getting-started/)
16+
- [DataJoint Elements](https://datajoint.com/docs/elements/) - Catalog of example pipelines
17+
- [DataJoint CodeBook](https://codebook.datajoint.io) - Interactive online tutorials
18+
- Contribute
2319

24-
## Documentation and Tutorials
20+
- [Development Environment](https://datajoint.com/docs/core/datajoint-python/latest/develop/)
21+
- [Guidelines](https://datajoint.com/docs/community/contribute/)
2522

26-
* https://datajoint.org -- start page
27-
* https://docs.datajoint.org -- up-to-date documentation
28-
* https://tutorials.datajoint.io -- step-by-step tutorials
29-
* https://elements.datajoint.org -- catalog of example pipelines
30-
* https://codebook.datajoint.io -- interactive online tutorials
23+
- Legacy Resources (To be replaced by above)
24+
- [Documentation](https://docs.datajoint.org)
25+
- [Tutorials](https://tutorials.datajoint.org)
3126

3227
## Citation
33-
+ If your work uses DataJoint for Python, please cite the following Research Resource Identifier (RRID) and manuscript.
34-
35-
+ DataJoint ([RRID:SCR_014543](https://scicrunch.org/resolver/SCR_014543)) - DataJoint for Python (version `<Enter version number>`)
36-
37-
+ Yatsenko D, Reimer J, Ecker AS, Walker EY, Sinz F, Berens P, Hoenselaar A, Cotton RJ, Siapas AS, Tolias AS. DataJoint: managing big scientific data using MATLAB or Python. bioRxiv. 2015 Jan 1:031658. doi: https://doi.org/10.1101/031658
38-
39-
## Python Native Blobs
40-
<details>
41-
<summary>Click to expand details</summary>
42-
43-
DataJoint 0.12 adds full support for all native python data types in blobs: tuples, lists, sets, dicts, strings, bytes, `None`, and all their recursive combinations.
44-
The new blobs are a superset of the old functionality and are fully backward compatible.
45-
In previous versions, only MATLAB-style numerical arrays were fully supported.
46-
Some Python datatypes such as dicts were coerced into numpy recarrays and then fetched as such.
47-
48-
However, since some Python types were coerced into MATLAB types, old blobs and new blobs may now be fetched as different types of objects even if they were inserted the same way.
49-
For example, new `dict` objects will be returned as `dict` while the same types of objects inserted with `datajoint 0.11` will be recarrays.
50-
51-
Since this is a big change, we chose to temporarily disable this feature by default in DataJoint for Python 0.12.x, allowing users to adjust their code if necessary.
52-
From 13.x, the flag will default to True (on), and will ultimately be removed when corresponding decode support for the new format is added to datajoint-matlab (see: datajoint-matlab #222, datajoint-python #765).
53-
54-
The flag is configured by setting the `enable_python_native_blobs` flag in `dj.config`.
55-
56-
```python
57-
import datajoint as dj
58-
dj.config["enable_python_native_blobs"] = True
59-
```
60-
61-
You can safely enable this setting if both of the following are true:
62-
63-
* The only kinds of blobs your pipeline have inserted previously were numerical arrays.
64-
* You do not need to share blob data between Python and MATLAB.
65-
66-
Otherwise, read the following explanation.
67-
68-
DataJoint v0.12 expands DataJoint's blob serialization mechanism with
69-
improved support for complex native python datatypes, such as dictionaries
70-
and lists of strings.
71-
72-
Prior to DataJoint v0.12, certain python native datatypes such as
73-
dictionaries were 'squashed' into numpy structured arrays when saved into
74-
blob attributes. This facilitated easier data sharing between MATLAB
75-
and Python for certain record types. However, this created a discrepancy
76-
between insert and fetch datatypes which could cause problems in other
77-
portions of users pipelines.
78-
79-
DataJoint v0.12, removes the squashing behavior, instead encoding native python datatypes in blobs directly.
80-
However, this change creates a compatibility problem for pipelines
81-
which previously relied on the type squashing behavior since records
82-
saved via the old squashing format will continue to fetch
83-
as structured arrays, whereas new record inserted in DataJoint 0.12 with
84-
`enable_python_native_blobs` would result in records returned as the
85-
appropriate native python type (dict, etc).
86-
Furthermore, DataJoint for MATLAB does not yet support unpacking native Python datatypes.
87-
88-
With `dj.config["enable_python_native_blobs"]` set to `False`,
89-
any attempt to insert any datatype other than a numpy array will result in an exception.
90-
This is meant to get users to read this message in order to allow proper testing
91-
and migration of pre-0.12 pipelines to 0.12 in a safe manner.
92-
93-
The exact process to update a specific pipeline will vary depending on
94-
the situation, but generally the following strategies may apply:
95-
96-
* Altering code to directly store numpy structured arrays or plain
97-
multidimensional arrays. This strategy is likely best one for those
98-
tables requiring compatibility with MATLAB.
99-
* Adjust code to deal with both structured array and native fetched data
100-
for those tables that are populated with `dict`s in blobs in pre-0.12 version.
101-
In this case, insert logic is not adjusted, but downstream consumers
102-
are adjusted to handle records saved under the old and new schemes.
103-
* Migrate data into a fresh schema, fetching the old data, converting blobs to
104-
a uniform data type and re-inserting.
105-
* Drop/Recompute imported/computed tables to ensure they are in the new
106-
format.
107-
108-
As always, be sure that your data is safely backed up before modifying any
109-
important DataJoint schema or records.
110-
111-
</details>
112-
113-
### API docs
114-
115-
The API documentation can be built with mkdocs using the docker compose file in
116-
`docs/` with the following command:
117-
118-
``` bash
119-
MODE="LIVE" PACKAGE=datajoint UPSTREAM_REPO=https://github.com/datajoint/datajoint-python.git HOST_UID=$(id -u) docker compose -f docs/docker-compose.yaml up --build
120-
```
121-
122-
The site will then be available at `http://localhost/`. When finished, be sure to run
123-
the same command as above, but replace `up --build` with `down`.
124-
125-
## Running Tests Locally
126-
<details>
127-
<summary>Click to expand details</summary>
128-
129-
* Create an `.env` with desired development environment values e.g.
130-
``` sh
131-
PY_VER=3.9
132-
MYSQL_VER=5.7
133-
DISTRO=alpine
134-
MINIO_VER=RELEASE.2022-01-03T18-22-58Z
135-
HOST_UID=1000
136-
```
137-
* `cp local-docker-compose.yml docker-compose.yml`
138-
* `docker-compose up -d` (Note configured `JUPYTER_PASSWORD`)
139-
* Select a means of running Tests e.g. Docker Terminal, or Local Terminal (see bottom)
140-
* Add entry in `/etc/hosts` for `127.0.0.1 fakeservices.datajoint.io`
141-
* Run desired tests. Some examples are as follows:
142-
143-
| Use Case | Shell Code |
144-
| ---------------------------- | ------------------------------------------------------------------------------ |
145-
| Run all tests | `nosetests -vsw tests --with-coverage --cover-package=datajoint` |
146-
| Run one specific class test | `nosetests -vs --tests=tests.test_fetch:TestFetch.test_getattribute_for_fetch1` |
147-
| Run one specific basic test | `nosetests -vs --tests=tests.test_external_class:test_insert_and_fetch` |
148-
149-
150-
### Launch Docker Terminal
151-
* Shell into `datajoint-python_app_1` i.e. `docker exec -it datajoint-python_app_1 sh`
152-
153-
154-
### Launch Local Terminal
155-
* See `datajoint-python_app` environment variables in `local-docker-compose.yml`
156-
* Launch local terminal
157-
* `export` environment variables in shell
158-
* Add entry in `/etc/hosts` for `127.0.0.1 fakeservices.datajoint.io`
15928

29+
- If your work uses DataJoint for Python, please cite the following Research Resource Identifier (RRID) and manuscript.
16030

161-
### Launch Jupyter Notebook for Interactive Use
162-
* Navigate to `localhost:8888`
163-
* Input Jupyter password
164-
* Launch a notebook i.e. `New > Python 3`
31+
- DataJoint ([RRID:SCR_014543](https://scicrunch.org/resolver/SCR_014543)) - DataJoint for Python (version `<Enter version number>`)
16532

166-
</details>
33+
- Yatsenko D, Reimer J, Ecker AS, Walker EY, Sinz F, Berens P, Hoenselaar A, Cotton RJ, Siapas AS, Tolias AS. DataJoint: managing big scientific data using MATLAB or Python. bioRxiv. 2015 Jan 1:031658. doi: https://doi.org/10.1101/031658

docs/docker-compose.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# MODE="LIVE|QA|BUILD" PACKAGE=datajoint UPSTREAM_REPO=https://github.com/datajoint/datajoint-python.git HOST_UID=$(id -u) docker compose -f docs/docker-compose.yaml up --build
2-
#
3-
# navigate to http://localhost/
42
version: "2.4"
53
services:
64
docs:
@@ -18,7 +16,7 @@ services:
1816
- ..:/main
1917
user: ${HOST_UID}:anaconda
2018
ports:
21-
- 80:80
19+
- 8080:80
2220
command:
2321
- sh
2422
- -c

0 commit comments

Comments
 (0)