Skip to content

Commit

Permalink
abstractproperty -> property + abstractmethod (#2847)
Browse files Browse the repository at this point in the history
* Update .travis.yml

* no py27 in travis (#2836)

* no py27 in travis

* py37

* flake8 and docs back

* py36 py37 postgres

* py36-apache

* MixedUnicodeBytes removed

* unused imports removed

* no-if-py3

* space

* space

* MixedUnicodeBytesFormat returned

* abstractproperty -> property + abstractmethod

* Update beam_dataflow.py

* Update beam_dataflow.py
  • Loading branch information
drowoseque authored and honnix committed Dec 3, 2019
1 parent e3cf752 commit ce6d4b8
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 51 deletions.
57 changes: 37 additions & 20 deletions luigi/contrib/beam_dataflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#

import abc
from abc import abstractmethod, abstractproperty
import logging
import json
import os
Expand All @@ -36,75 +35,93 @@ class DataflowParamKeys(metaclass=abc.ABCMeta):
the Python implementation expects snake case.
"""
@abstractproperty
@property
@abc.abstractmethod
def runner(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def project(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def zone(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def region(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def staging_location(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def temp_location(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def gcp_temp_location(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def num_workers(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def autoscaling_algorithm(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def max_num_workers(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def disk_size_gb(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def worker_machine_type(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def worker_disk_type(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def job_name(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def service_account(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def network(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def subnetwork(self):
pass

@abstractproperty
@property
@abc.abstractmethod
def labels(self):
pass

Expand Down Expand Up @@ -218,7 +235,7 @@ def __init__(self):
raise ValueError("dataflow_params must be of type DataflowParamKeys")
super(BeamDataflowJobTask, self).__init__()

@abstractmethod
@abc.abstractmethod
def dataflow_executable(self):
"""
Command representing the Dataflow executable to be run.
Expand Down
3 changes: 2 additions & 1 deletion luigi/contrib/esindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def http_auth(self):
"""
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def index(self):
"""
The target index.
Expand Down
9 changes: 6 additions & 3 deletions luigi/contrib/pai.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,20 @@ class OpenPai(luigi.Config):
class PaiTask(luigi.Task):
__POLL_TIME = 5

@abc.abstractproperty
@property
@abc.abstractmethod
def name(self):
"""Name for the job, need to be unique, required"""
return 'SklearnExample'

@abc.abstractproperty
@property
@abc.abstractmethod
def image(self):
"""URL pointing to the Docker image for all tasks in the job, required"""
return 'openpai/pai.example.sklearn'

@abc.abstractproperty
@property
@abc.abstractmethod
def tasks(self):
"""List of taskRole, one task role at least, required"""
return []
Expand Down
33 changes: 22 additions & 11 deletions luigi/contrib/rdbms.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,28 @@ class CopyToTable(luigi.task.MixinNaiveBulkComplete, _MetadataColumnsMixin, luig
* `port`
"""

@abc.abstractproperty
@property
@abc.abstractmethod
def host(self):
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def database(self):
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def user(self):
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def password(self):
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def table(self):
return None

Expand Down Expand Up @@ -287,7 +292,8 @@ class Query(luigi.task.MixinNaiveBulkComplete, luigi.Task):
* `output`
"""

@abc.abstractproperty
@property
@abc.abstractmethod
def host(self):
"""
Host of the RDBMS. Implementation should support `hostname:port`
Expand All @@ -302,23 +308,28 @@ def port(self):
"""
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def database(self):
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def user(self):
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def password(self):
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def table(self):
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def query(self):
return None

Expand Down
21 changes: 14 additions & 7 deletions luigi/contrib/redshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ def s3_load_path(self):
"""
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def copy_options(self):
"""
Add extra copy options, for example:
Expand Down Expand Up @@ -526,14 +527,16 @@ class S3CopyJSONToTable(S3CopyToTable, _CredentialsMixin):
configuration or environment variables.
"""

@abc.abstractproperty
@property
@abc.abstractmethod
def jsonpath(self):
"""
Override the jsonpath schema location for the table.
"""
return ''

@abc.abstractproperty
@property
@abc.abstractmethod
def copy_json_options(self):
"""
Add extra copy options, for example:
Expand Down Expand Up @@ -622,19 +625,23 @@ class KillOpenRedshiftSessions(luigi.Task):
# 30 seconds is usually fine; 60 is conservative
connection_reset_wait_seconds = luigi.IntParameter(default=60)

@abc.abstractproperty
@property
@abc.abstractmethod
def host(self):
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def database(self):
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def user(self):
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def password(self):
return None

Expand Down
6 changes: 4 additions & 2 deletions luigi/contrib/salesforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ class salesforce(luigi.Config):


class QuerySalesforce(Task):
@abc.abstractproperty
@property
@abc.abstractmethod
def object_name(self):
"""
Override to return the SF object we are querying.
Expand All @@ -126,7 +127,8 @@ def sandbox_name(self):
"""Override to specify the sandbox name if it is intended to be used."""
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def soql(self):
"""Override to return the raw string SOQL or the path to it."""
return None
Expand Down
6 changes: 4 additions & 2 deletions luigi/contrib/sqla.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,13 @@ class CopyToTable(luigi.Task):
echo = False
connect_args = {}

@abc.abstractproperty
@property
@abc.abstractmethod
def connection_string(self):
return None

@abc.abstractproperty
@property
@abc.abstractmethod
def table(self):
return None

Expand Down
9 changes: 6 additions & 3 deletions luigi/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ def __init__(self, interval=1, start=None, **kwargs):
self.interval = interval
self.start = start if start is not None else _UNIX_EPOCH.date()

@abc.abstractproperty
@property
@abc.abstractmethod
def date_format(self):
"""
Override me with a :py:meth:`~datetime.date.strftime` string.
Expand Down Expand Up @@ -501,14 +502,16 @@ def __init__(self, interval=1, start=None, **kwargs):
self.interval = interval
self.start = start if start is not None else _UNIX_EPOCH

@abc.abstractproperty
@property
@abc.abstractmethod
def date_format(self):
"""
Override me with a :py:meth:`~datetime.date.strftime` string.
"""
pass

@abc.abstractproperty
@property
@abc.abstractmethod
def _timedelta(self):
"""
How to move one interval of this type forward (i.e. not counting self.interval).
Expand Down
3 changes: 2 additions & 1 deletion luigi/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ def __init__(self, path):
# cast to str to allow path to be objects like pathlib.PosixPath and py._path.local.LocalPath
self.path = str(path)

@abc.abstractproperty
@property
@abc.abstractmethod
def fs(self):
"""
The :py:class:`FileSystem` associated with this FileSystemTarget.
Expand Down
3 changes: 2 additions & 1 deletion test/subtask_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
class AbstractTask(luigi.Task):
k = luigi.IntParameter()

@abc.abstractproperty
@property
@abc.abstractmethod
def foo(self):
raise NotImplementedError

Expand Down

0 comments on commit ce6d4b8

Please sign in to comment.