Skip to content

Commit

Permalink
Validated the changes in approval for the Python code generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandervsokol committed Dec 6, 2019
1 parent 53663b7 commit 6687d91
Showing 1 changed file with 105 additions and 164 deletions.
@@ -1,4 +1,4 @@
Verify: datacentric/date_time/zone.py
Verify: datacentric/date_time//zone.py
# Copyright (C) 2013-present The DataCentric Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -14,36 +14,13 @@ Verify: datacentric/date_time/zone.py
# limitations under the License.

import attr
from datacentric.storage.typed_key import TypedKey
from datacentric.storage.typed_record import TypedRecord


class ZoneKeyHint:
"""
This class provides timezone conversion between UTC
and local datetime for the specified timezone.

Only the following timezone names are permitted:

* UTC; and
* IANA city timezones such as America/New_York

Other 3-letter regional timezones such as EST or EDT are
not permitted because they do not handle the transition
between winter and summer time automatically for those
regions where winter time is defined.

Because ZoneName is used to look up timezone conventions,
it must match either the string UTC or the code in IANA
timezone database precisely. The IANA city timezone code
has two slash-delimited tokens, the first referencing the
country and the other the city, for example America/New_York.
"""
pass
from typing import Union
from datacentric.storage.record import Record
from datacentric.date_time..zone_key import ZoneKey


@attr.s(slots=True, auto_attribs=True)
class ZoneKey(TypedKey['Zone']):
class Zone(Record):
"""
This class provides timezone conversion between UTC
and local datetime for the specified timezone.
Expand Down Expand Up @@ -86,33 +63,37 @@ Verify: datacentric/date_time/zone.py
country and the other the city, for example America/New_York.
"""

def to_key(self) -> str:
"""Get Zone key."""
return 'Zone=' + self.zone_name

@attr.s(slots=True, auto_attribs=True)
class Zone(TypedRecord[ZoneKey]):
"""
This class provides timezone conversion between UTC
and local datetime for the specified timezone.

Only the following timezone names are permitted:
@classmethod
def create_key(cls, *, zone_name: str) -> Union[str, ZoneKey]:
"""Create Zone key."""
return 'Zone=' + zone_name
Verify: datacentric/date_time//zone_key.py
# Copyright (C) 2013-present The DataCentric Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

* UTC; and
* IANA city timezones such as America/New_York
from abc import ABC
from datacentric.storage.key import Key

Other 3-letter regional timezones such as EST or EDT are
not permitted because they do not handle the transition
between winter and summer time automatically for those
regions where winter time is defined.

Because ZoneName is used to look up timezone conventions,
it must match either the string UTC or the code in IANA
timezone database precisely. The IANA city timezone code
has two slash-delimited tokens, the first referencing the
country and the other the city, for example America/New_York.
class ZoneKey(Key, ABC):
"""

zone_name: str = attr.ib(default=None, kw_only=True)
"""
Unique timezone name.
This class provides timezone conversion between UTC
and local datetime for the specified timezone.

Only the following timezone names are permitted:

Expand All @@ -130,7 +111,8 @@ Verify: datacentric/date_time/zone.py
has two slash-delimited tokens, the first referencing the
country and the other the city, for example America/New_York.
"""
Verify: datacentric/job/job.py
pass
Verify: datacentric/job//job.py
# Copyright (C) 2013-present The DataCentric Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -148,13 +130,13 @@ Verify: datacentric/job/job.py
import attr
from bson import ObjectId
from typing import List, Union
from datacentric.storage.typed_key import TypedKey
from datacentric.storage.typed_record import TypedRecord
from datacentric.job.job_queue import JobQueueKeyHint
from datacentric.job.job import JobKeyHint
from datacentric.storage.record import Record
from datacentric.job..job_key import JobKey
from datacentric.job..job_queue_key import JobQueueKey


class JobKeyHint:
@attr.s(slots=True, auto_attribs=True)
class Job(Record):
"""
The job executes a method of the specified record using:

Expand Down Expand Up @@ -215,77 +197,90 @@ Verify: datacentric/job/job.py
access to the resources it needs and will be able to run successfully
in each of these cases.
"""
pass

queue: Union[str, JobQueueKey] = attr.ib(default=None, kw_only=True)
"""Queue to which the job is submitted."""

@attr.s(slots=True, auto_attribs=True)
class JobKey(TypedKey['Job']):
collection_name: str = attr.ib(default=None, kw_only=True)
"""
The job executes a method of the specified record using:

* CollectionName - collection where the record is stored
* RecordId - TemporalId of the record
* MethodName - method to be executed
* ParamNames - method parameter names (optional)
* ParamValues - serialized method parameter values (optional)
Name of the collection where the referenced record is stored.

The method to be executed may take the following parameter types:
Referenced record is the record in this collection whose
TemporalId is RecordId.
"""

* Atomic type - serialized by AsString() method
* Enum - serialized as string value
* Key - serialized in semicolon delimited format without type
record_id: ObjectId = attr.ib(default=None, kw_only=True, metadata={'optional': True})
"""
TemporalId of the referenced record.

The order of parameters in ParameterNames and ParameterValues
must match, but does not have to be the same as the order
of parameters in the method signature.
This key is specific to the version of the referenced record.
When a new record is created for the same key, the view will
continue referencing the original version of the record where
Id=RecordId.
"""

The invoked method must return void.
method_name: str = attr.ib(default=None, kw_only=True)
"""
Name of the method of the referenced record executed by the job.

A job can execute any public method of a class that returns void.
There is no requirement to mark the method by [HandlerMethod] or
[ViewerMethod] attribute.
Referenced record is the record in collection with CollectionName
whose TemporalId is RecordId.
"""

The job may optionally provides the list of prerequisite job keys.
The job will be executed after JobProgress record for each of the
prerequisite jobs has Completed status.
param_names: List[str] = attr.ib(default=None, kw_only=True, repr=False, metadata={'optional': True})
"""
Method parameter names (optional).

After a job record is created, it is detected and scheduled for
execution by the queue specified by the record.JobQueue element.
It will have Pending status until all prerequisite jobs are
completed.
The order of parameters in ParameterNames and ParameterValues
must match, but does not have to be the same as the order
of parameters in the method signature.
"""

The queue updates the JobProgress record at least every time its
status changes, and optionally more often to update its progress
fraction and progress message. It also monitors the dataset where
it is running for JobCancellation records and writes log entries
to the log specified by the queue.
param_values: List[str] = attr.ib(default=None, kw_only=True, repr=False, metadata={'optional': True})
"""
Serialized method parameter values (optional).

Because Job records reference the queue by its JobQueueName,
the existing jobs do not need to be resubmitted when a new
queue record is created for the same JobQueueName but it is
important to ensure that only one job with a given JobQueueName
is running at any given time.
The order of parameters in ParameterNames and ParameterValues
must match, but does not have to be the same as the order
of parameters in the method signature.
"""

To run the job, JobQueue executes the Run() method of Job which
in turn invokes method with MethodName in the referenced record
referenced by the job.
prerequisites: List[Union[str, JobKey]] = attr.ib(default=None, kw_only=True, repr=False, metadata={'optional': True})
"""
Optional list of prerequisite job keys.

Depending on the type of queue, MethodName may be executed:
The job will be executed after JobProgress record for each of
the prerequisite jobs has Completed status.
"""

* In a different process or thread than the one that created the job
* On a different machine than the one where the job was created
* In parallel or out of sequence relative to other jobs
def to_key(self) -> str:
"""Get Job key."""
return 'Job='

The job submitter must ensure that the specified method will have
access to the resources it needs and will be able to run successfully
in each of these cases.
"""
@classmethod
def create_key(cls, *, ) -> Union[str, JobKey]:
"""Create Job key."""
return 'Job='
Verify: datacentric/job//job_key.py
# Copyright (C) 2013-present The DataCentric Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

pass
from abc import ABC
from datacentric.storage.key import Key


@attr.s(slots=True, auto_attribs=True)
class Job(TypedRecord[JobKey]):
class JobKey(Key, ABC):
"""
The job executes a method of the specified record using:

Expand Down Expand Up @@ -346,62 +341,8 @@ Verify: datacentric/job/job.py
access to the resources it needs and will be able to run successfully
in each of these cases.
"""

queue: Union[str, JobQueueKeyHint] = attr.ib(default=None, kw_only=True)
"""Queue to which the job is submitted."""

collection_name: str = attr.ib(default=None, kw_only=True)
"""
Name of the collection where the referenced record is stored.

Referenced record is the record in this collection whose
TemporalId is RecordId.
"""

record_id: ObjectId = attr.ib(default=None, kw_only=True, metadata={'optional': True})
"""
TemporalId of the referenced record.

This key is specific to the version of the referenced record.
When a new record is created for the same key, the view will
continue referencing the original version of the record where
Id=RecordId.
"""

method_name: str = attr.ib(default=None, kw_only=True)
"""
Name of the method of the referenced record executed by the job.

Referenced record is the record in collection with CollectionName
whose TemporalId is RecordId.
"""

param_names: List[str] = attr.ib(default=None, kw_only=True, repr=False, metadata={'optional': True})
"""
Method parameter names (optional).

The order of parameters in ParameterNames and ParameterValues
must match, but does not have to be the same as the order
of parameters in the method signature.
"""

param_values: List[str] = attr.ib(default=None, kw_only=True, repr=False, metadata={'optional': True})
"""
Serialized method parameter values (optional).

The order of parameters in ParameterNames and ParameterValues
must match, but does not have to be the same as the order
of parameters in the method signature.
"""

prerequisites: List[Union[str, JobKeyHint]] = attr.ib(default=None, kw_only=True, repr=False, metadata={'optional': True})
"""
Optional list of prerequisite job keys.

The job will be executed after JobProgress record for each of
the prerequisite jobs has Completed status.
"""
Verify: datacentric/job/job_status.py
pass
Verify: datacentric/job//job_status.py
# Copyright (C) 2013-present The DataCentric Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down

0 comments on commit 6687d91

Please sign in to comment.