Skip to content

Commit e0de641

Browse files
Merge pull request #732 from guzman-raphael/schema
Rename dj.schema to dj.Schema and dj.create_virtual_module to dj.VirtualModule
2 parents 31edaea + a63f9df commit e0de641

33 files changed

+147
-75
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## Release notes
22

3+
### 0.12.5 -- Feb TBA, 2020
4+
* Rename module `dj.schema` into `dj.schemas`. `dj.schema` remains an alias for class `dj.Schema`. (#731) PR #732
5+
* `dj.create_virtual_module` is now called `dj.VirtualModule` (#731) PR #732
6+
* Bugfix - SSL `KeyError` on failed connection (#716) PR #725
7+
* Bugfix - Unable to run unit tests using nosetests (#723) PR #724
8+
* Bugfix - `suppress_errors` does not suppress loss of connection error (#720) PR #721
9+
310
### 0.12.4 -- Jan 14, 2020
411
* Support for simple scalar datatypes in blobs (#690) PR #709
512
* Add support for the `serial` data type in declarations: alias for `bigint unsigned auto_increment` PR #713

LNX-docker-compose.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ services:
1414
fakeservices.datajoint.io:
1515
condition: service_healthy
1616
environment:
17-
- DJ_HOST=db
17+
- DJ_HOST=fakeservices.datajoint.io
1818
- DJ_USER=root
1919
- DJ_PASS=simple
20-
- DJ_TEST_HOST=db
20+
- DJ_TEST_HOST=fakeservices.datajoint.io
2121
- DJ_TEST_USER=datajoint
2222
- DJ_TEST_PASSWORD=datajoint
2323
- S3_ENDPOINT=fakeservices.datajoint.io:9000
@@ -57,10 +57,10 @@ services:
5757
# - ./mysql/data:/var/lib/mysql
5858
minio:
5959
<<: *net
60+
image: minio/minio:$MINIO_VER
6061
environment:
6162
- MINIO_ACCESS_KEY=datajoint
6263
- MINIO_SECRET_KEY=datajoint
63-
image: minio/minio:$MINIO_VER
6464
# ports:
6565
# - "9000:9000"
6666
# volumes:
@@ -79,6 +79,7 @@ services:
7979
- URL=datajoint.io
8080
- SUBDOMAINS=fakeservices
8181
- MINIO_SERVER=http://minio:9000
82+
- MYSQL_SERVER=db:3306
8283
entrypoint: /entrypoint.sh
8384
healthcheck:
8485
test: wget --quiet --tries=1 --spider https://fakeservices.datajoint.io:443/minio/health/live || exit 1
@@ -88,8 +89,10 @@ services:
8889
# ports:
8990
# - "9000:9000"
9091
# - "443:443"
92+
# - "3306:3306"
9193
volumes:
9294
- ./tests/nginx/base.conf:/base.conf
95+
- ./tests/nginx/nginx.conf:/nginx.conf
9396
- ./tests/nginx/entrypoint.sh:/entrypoint.sh
9497
- ./tests/nginx/fullchain.pem:/certs/fullchain.pem
9598
- ./tests/nginx/privkey.pem:/certs/privkey.pem

datajoint/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
__date__ = "February 7, 2019"
1919
__all__ = ['__author__', '__version__',
2020
'config', 'conn', 'Connection',
21-
'schema', 'create_virtual_module', 'list_schemas',
22-
'Table', 'FreeTable',
21+
'Schema', 'schema', 'VirtualModule', 'create_virtual_module',
22+
'list_schemas', 'Table', 'FreeTable',
2323
'Manual', 'Lookup', 'Imported', 'Computed', 'Part',
2424
'Not', 'AndList', 'U', 'Diagram', 'Di', 'ERD',
2525
'set_password', 'kill',
@@ -29,8 +29,8 @@
2929
from .version import __version__
3030
from .settings import config
3131
from .connection import conn, Connection
32-
from .schema import Schema as schema
33-
from .schema import create_virtual_module, list_schemas
32+
from .schemas import Schema
33+
from .schemas import VirtualModule, list_schemas
3434
from .table import Table, FreeTable
3535
from .user_tables import Manual, Lookup, Imported, Computed, Part
3636
from .expression import Not, AndList, U
@@ -43,4 +43,6 @@
4343
from .errors import DataJointError
4444
from .migrate import migrate_dj011_external_blob_storage_to_dj012
4545

46-
ERD = Di = Diagram # Aliases for Diagram
46+
ERD = Di = Diagram # Aliases for Diagram
47+
schema = Schema # Aliases for Schema
48+
create_virtual_module = VirtualModule # Aliases for VirtualModule

datajoint/migrate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def migrate_dj011_external_blob_storage_to_dj012(migration_schema, store):
2525
Proceed?
2626
""", default='no') == 'yes'
2727
if do_migration:
28-
_migrate_dj011_blob(dj.schema(migration_schema), store)
28+
_migrate_dj011_blob(dj.Schema(migration_schema), store)
2929
print('Migration completed for schema: {}, store: {}.'.format(
3030
migration_schema, store))
3131
return

datajoint/schema.py renamed to datajoint/schemas.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ def repl(s):
280280
body = '\n\n\n'.join(make_class_definition(table) for table in diagram.topological_sort())
281281
python_code = '\n\n\n'.join((
282282
'"""This module was auto-generated by datajoint from an existing schema"""',
283-
"import datajoint as dj\n\nschema = dj.schema('{db}')".format(db=db),
284-
'\n'.join("{module} = dj.create_virtual_module('{module}', '{schema_name}')".format(module=v, schema_name=k)
283+
"import datajoint as dj\n\nschema = dj.Schema('{db}')".format(db=db),
284+
'\n'.join("{module} = dj.VirtualModule('{module}', '{schema_name}')".format(module=v, schema_name=k)
285285
for k, v in module_lookup.items()), body))
286286
if python_filename is None:
287287
return python_code
@@ -290,26 +290,30 @@ def repl(s):
290290
f.write(python_code)
291291

292292

293-
def create_virtual_module(module_name, schema_name, *,
294-
create_schema=False, create_tables=False, connection=None, add_objects=None):
293+
class VirtualModule(types.ModuleType):
295294
"""
296-
Creates a python module with the given name from the name of a schema on the server and
297-
automatically adds classes to it corresponding to the tables in the schema.
298-
:param module_name: displayed module name
299-
:param schema_name: name of the database in mysql
300-
:param create_schema: if True, create the schema on the database server
301-
:param create_tables: if True, module.schema can be used as the decorator for declaring new
302-
:param connection: a dj.Connection object to pass into the schema
303-
:param add_objects: additional objects to add to the module
304-
:return: the python module containing classes from the schema object and the table classes
295+
A virtual module which will contain context for schema.
305296
"""
306-
module = types.ModuleType(module_name)
307-
_schema = Schema(schema_name, create_schema=create_schema, create_tables=create_tables, connection=connection)
308-
if add_objects:
309-
module.__dict__.update(add_objects)
310-
module.__dict__['schema'] = _schema
311-
_schema.spawn_missing_classes(context=module.__dict__)
312-
return module
297+
def __init__(self, module_name, schema_name, *, create_schema=False,
298+
create_tables=False, connection=None, add_objects=None):
299+
"""
300+
Creates a python module with the given name from the name of a schema on the server and
301+
automatically adds classes to it corresponding to the tables in the schema.
302+
:param module_name: displayed module name
303+
:param schema_name: name of the database in mysql
304+
:param create_schema: if True, create the schema on the database server
305+
:param create_tables: if True, module.schema can be used as the decorator for declaring new
306+
:param connection: a dj.Connection object to pass into the schema
307+
:param add_objects: additional objects to add to the module
308+
:return: the python module containing classes from the schema object and the table classes
309+
"""
310+
super(VirtualModule, self).__init__(name=module_name)
311+
_schema = Schema(schema_name, create_schema=create_schema, create_tables=create_tables,
312+
connection=connection)
313+
if add_objects:
314+
self.__dict__.update(add_objects)
315+
self.__dict__['schema'] = _schema
316+
_schema.spawn_missing_classes(context=self.__dict__)
313317

314318

315319
def list_schemas(connection=None):

datajoint/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = "0.12.4"
1+
__version__ = "0.12.5"
22

33
assert len(__version__) <= 10 # The log table limits version to the 10 characters

docs-parts/definition/01-Creating-Schemas_lang1.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
.. note:: By convention, the ``datajoint`` package is imported as ``dj``.
33
The documentation refers to the package as ``dj`` throughout.
44

5-
Create a new schema using the ``dj.schema`` function:
5+
Create a new schema using the ``dj.Schema`` class object:
66

77
.. code-block:: python
88
99
import datajoint as dj
10-
schema = dj.schema('alice_experiment')
10+
schema = dj.Schema('alice_experiment')
1111
1212
This statement creates the database schema ``alice_experiment`` on the server.
1313

1414
The returned object ``schema`` will then serve as a decorator for DataJoint classes, as described in :ref:`table`.
1515

1616
It is a common practice to have a separate Python module for each schema.
17-
Therefore, each such module has only one ``dj.schema`` object defined and is usually named ``schema``.
17+
Therefore, each such module has only one ``dj.Schema`` object defined and is usually named ``schema``.
1818

19-
The ``dj.schema`` constructor can take a number of optional parameters after the schema name.
19+
The ``dj.Schema`` constructor can take a number of optional parameters after the schema name.
2020

2121
- ``context`` - Dictionary for looking up foreign key references.
2222
Defaults to ``None`` to use local context.

docs-parts/definition/02-Creating-Tables_lang1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ For example, the following code defines the table ``Person``:
1212
.. code-block:: python
1313
1414
import datajoint as dj
15-
schema = dj.schema('alice_experiment')
15+
schema = dj.Schema('alice_experiment')
1616
1717
@schema
1818
class Person(dj.Manual):

docs-parts/definition/11-ERD_lang1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ To plot the ERD for an entire schema, an ERD object can be initialized with the
44
.. code-block:: python
55
66
import datajoint as dj
7-
schema = dj.schema('my_database')
7+
schema = dj.Schema('my_database')
88
dj.ERD(schema).draw()
99
1010
or alternatively an object that has the schema object as an attribute, such as the module defining a schema:

docs-parts/existing/0-Virtual-Modules_lang1.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
The function ``create_virtual_module`` of the ``dj.schema`` class provides access to virtual modules.
1+
The class object ``VirtualModule`` of the ``dj.Schema`` class provides access to virtual modules.
22
It creates a python module with the given name from the name of a schema on the server, automatically adds classes to it corresponding to the tables in the schema.
33

44
The function can take several parameters:

0 commit comments

Comments
 (0)