instruction
stringclasses
100 values
code
stringlengths
78
193k
response
stringlengths
259
170k
file
stringlengths
59
203
Add verbose docstrings with examples
# import yaml def get_repo_from_url(url): idx = url.find(".com/") return url[idx + len(".com/") :].strip("/") def create_alternatives_md(names, links): return ", ".join( (f"""[{name.strip()}]({link.strip()})""" for name, link in zip(names, links)) ) def create_shield_link(gh_link): ret...
--- +++ @@ -1,12 +1,30 @@+""" +This script adds company directly to the list +""" # import yaml def get_repo_from_url(url): + """ + Given a url, return the repository name. + + :param url: the url of the repo + :return: The repo name. + """ idx = url.find(".com/") return url[idx + len(".c...
https://raw.githubusercontent.com/RunaCapital/awesome-oss-alternatives/HEAD/add_company.py
Expand my code with proper documentation strings
import json import sys import js from polyscript import config as _polyscript_config from polyscript import js_modules from pyscript.util import NotSupported RUNNING_IN_WORKER = not hasattr(js, "document") """Detect execution context: True if running in a worker, False if main thread.""" config = json.loads(js.JSON...
--- +++ @@ -1,3 +1,42 @@+""" +Execution context management for PyScript. + +This module handles the differences between running in the +[main browser thread](https://developer.mozilla.org/en-US/docs/Glossary/Main_thread) +versus running in a +[Web Worker](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API...
https://raw.githubusercontent.com/pyscript/pyscript/HEAD/core/src/stdlib/pyscript/context.py
Create docstrings for all classes and functions
import base64 import html import io from collections import OrderedDict from pyscript.context import current_target, document, window from pyscript.ffi import is_none def _render_image(mime, value, meta): if isinstance(value, bytes): value = base64.b64encode(value).decode("utf-8") attrs = "".join([f'...
--- +++ @@ -1,3 +1,37 @@+""" +Display Pythonic content in the browser. + +This module provides the `display()` function for rendering Python objects +in the web page. The function introspects objects to determine the appropriate +[MIME type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_typ...
https://raw.githubusercontent.com/pyscript/pyscript/HEAD/core/src/stdlib/pyscript/display.py
Generate consistent documentation across files
import asyncio import inspect from functools import wraps from pyscript.context import document from pyscript.ffi import create_proxy, to_js from pyscript.util import is_awaitable class Event: def __init__(self): self._listeners = [] def trigger(self, result): for listener in self._listener...
--- +++ @@ -1,3 +1,16 @@+""" +Event handling for PyScript. + +This module provides two complementary systems: + +1. The `Event` class: A simple publish-subscribe pattern for custom events + within *your* Python code. + +2. The `@when` decorator: Connects Python functions to browser DOM events, + or instances of the...
https://raw.githubusercontent.com/pyscript/pyscript/HEAD/core/src/stdlib/pyscript/events.py
Add docstrings to incomplete code
from pyscript import window from pyscript.ffi import to_js class Device: def __init__(self, device): self._device_info = device @property def id(self): return self._device_info.deviceId @property def group(self): return self._device_info.groupId @property def k...
--- +++ @@ -1,34 +1,159 @@+""" +This module provides classes and functions for interacting with +[media devices and streams](https://developer.mozilla.org/en-US/docs/Web/API/Media_Capture_and_Streams_API) +in the browser, enabling you to work with cameras, microphones, +and other media input/output devices directly fro...
https://raw.githubusercontent.com/pyscript/pyscript/HEAD/core/src/stdlib/pyscript/media.py
Write docstrings for algorithm functions
try: # Attempt to import Pyodide's FFI utilities. import js from pyodide.ffi import create_proxy as _cp from pyodide.ffi import to_js as _py_tjs from pyodide.ffi import jsnull from_entries = js.Object.fromEntries def _to_js_wrapper(value, **kw): if "dict_converter" not in kw: ...
--- +++ @@ -1,3 +1,26 @@+""" +This module provides a unified +[Foreign Function Interface (FFI)](https://en.wikipedia.org/wiki/Foreign_function_interface) +layer for Python/JavaScript interactions, that works consistently across both +Pyodide and MicroPython, and in a worker or main thread context, abstracting +away th...
https://raw.githubusercontent.com/pyscript/pyscript/HEAD/core/src/stdlib/pyscript/ffi.py
Add structured docstrings to improve clarity
from polyscript import storage as _polyscript_storage from pyscript.flatted import parse as _parse from pyscript.flatted import stringify as _stringify from pyscript.ffi import is_none def _convert_to_idb(value): if is_none(value): return _stringify(["null", 0]) if isinstance(value, (bool, float, int...
--- +++ @@ -1,3 +1,52 @@+""" +This module wraps the browser's +[IndexedDB persistent storage](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) +to provide a familiar Python dictionary API. Data is automatically +serialized and persisted, surviving page reloads and browser restarts. + +Storage is persiste...
https://raw.githubusercontent.com/pyscript/pyscript/HEAD/core/src/stdlib/pyscript/storage.py
Write docstrings for utility functions
import js import inspect def as_bytearray(buffer): ui8a = js.Uint8Array.new(buffer) size = ui8a.length ba = bytearray(size) for i in range(size): ba[i] = ui8a[i] return ba class NotSupported: def __init__(self, name, error): object.__setattr__(self, "name", name) ob...
--- +++ @@ -1,9 +1,26 @@+""" +This module contains general-purpose utility functions that don't fit into +more specific modules. These utilities handle cross-platform compatibility +between Pyodide and MicroPython, feature detection, and common type +conversions: + +- `as_bytearray`: Convert JavaScript `ArrayBuffer` to...
https://raw.githubusercontent.com/pyscript/pyscript/HEAD/core/src/stdlib/pyscript/util.py
Create simple docstrings for beginners
import js from _pyscript import fs as _fs, interpreter from pyscript import window from pyscript.ffi import to_js from pyscript.context import RUNNING_IN_WORKER # Worker-specific imports. if RUNNING_IN_WORKER: from pyscript.context import sync as sync_with_worker from polyscript import IDBMap mounted = {} ""...
--- +++ @@ -1,3 +1,42 @@+""" +This module provides an API for mounting directories from the user's local +filesystem into the browser's virtual filesystem. This means Python code, +running in the browser, can read and write files on the user's local machine. + +!!! warning + **This API only works in Chromium-based b...
https://raw.githubusercontent.com/pyscript/pyscript/HEAD/core/src/stdlib/pyscript/fs.py
Please document this code using docstrings
import json as _json class _Known: def __init__(self): self.key = [] self.value = [] class _String: def __init__(self, value): self.value = value def _array_keys(value): keys = [] i = 0 for _ in value: keys.append(i) i += 1 return keys def _object...
--- +++ @@ -1,3 +1,36 @@+""" +This module is a Python implementation of the +[Flatted JavaScript library](https://www.npmjs.com/package/flatted), which +provides a light and fast way to serialize and deserialize JSON structures +that contain circular references. + +Standard JSON cannot handle circular references - atte...
https://raw.githubusercontent.com/pyscript/pyscript/HEAD/core/src/stdlib/pyscript/flatted.py
Write docstrings that follow conventions
import js from pyscript.ffi import create_proxy from pyscript.util import as_bytearray, is_awaitable def _attach_event_handler(websocket, handler_name, handler_function): if is_awaitable(handler_function): async def async_wrapper(event): await handler_function(WebSocketEvent(event)) ...
--- +++ @@ -1,3 +1,43 @@+""" +This module provides a Pythonic wrapper around the browser's +[WebSocket API](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket), +enabling two-way communication with WebSocket servers. + +Use this for real-time applications: + +- Pythonic interface to browser WebSockets. +- Autom...
https://raw.githubusercontent.com/pyscript/pyscript/HEAD/core/src/stdlib/pyscript/websocket.py
Generate documentation strings for clarity
import json import js from pyscript.util import as_bytearray class _FetchResponse: def __init__(self, response): self._response = response def __getattr__(self, attr): return getattr(self._response, attr) async def arrayBuffer(self): buffer = await self._response.arrayBuffer() ...
--- +++ @@ -1,3 +1,24 @@+""" +This module provides a Python-friendly interface to the +[browser's fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API), +returning native Python data types and supporting directly awaiting the promise +and chaining method calls directly on the promise. + +```python +fro...
https://raw.githubusercontent.com/pyscript/pyscript/HEAD/core/src/stdlib/pyscript/fetch.py
Document this code for team use
import js import json from polyscript import workers as _polyscript_workers class _ReadOnlyWorkersProxy: def __getitem__(self, name): return js.Reflect.get(_polyscript_workers, name) def __getattr__(self, name): return js.Reflect.get(_polyscript_workers, name) # Global workers proxy for a...
--- +++ @@ -1,3 +1,63 @@+""" +This module provides access to named +[web workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API) +defined in `<script>` tags, and utilities for dynamically creating workers +from Python code. + +Named workers are Python web workers defined in HTML with a `name` attribu...
https://raw.githubusercontent.com/pyscript/pyscript/HEAD/core/src/stdlib/pyscript/workers.py
Provide docstrings following PEP 257
# -*- coding: utf-8 -*- # # Copyright 2017 Open Targets # # 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...
--- +++ @@ -16,6 +16,25 @@ # +""" +Docker container wrapper for Luigi. + +Enables running a docker container as a task in luigi. +This wrapper uses the Docker Python SDK to communicate directly with the +Docker API avoiding the common pattern to invoke the docker client +from the command line. Using the SDK it is p...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/docker_runner.py
Can you add docstrings to this Python file?
# -*- coding: utf-8 -*- # # Copyright 2015 Spotify AB # # 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 a...
--- +++ @@ -14,6 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +This module contains luigi internal parsing logic. Things exposed here should +be considered internal to luigi. +""" import argparse import sys @@ -23,16 +27,26 @@ class Cm...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/cmdline_parser.py
Write docstrings for algorithm functions
# -*- coding: utf-8 -*- # # Luigi documentation build configuration file, created by # sphinx-quickstart on Sat Feb 8 00:56:43 2014. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All...
--- +++ @@ -23,6 +23,10 @@ import luigi.parameter def parameter_repr(self): + """ + When building documentation, we want Parameter objects to show their + description in a nice way + """ significance = 'Insignificant ' if not self.significant else '' class_name =...
https://raw.githubusercontent.com/spotify/luigi/HEAD/doc/conf.py
Add docstrings with type hints explained
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -59,6 +59,14 @@ def run_hive(args, check_return_code=True): + """ + Runs the `hive` from the command line, passing in the given args, and + returning stdout. + + With the apache release of Hive, so of the table existence checks + (which are done using DESCRIBE do not exit with a return cod...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/hive.py
Auto-generate documentation strings for this file
# -*- coding: utf-8 -*- # # Copyright 2015 Twitter Inc # # 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 ...
--- +++ @@ -77,6 +77,16 @@ class FieldDelimiter: + """ + The separator for fields in a CSV file. The separator can be any ISO-8859-1 single-byte character. + To use a character in the range 128-255, you must encode the character as UTF8. + BigQuery converts the string to ISO-8859-1 encoding, and then us...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/bigquery.py
Generate docstrings for exported functions
import logging logger = logging.getLogger("luigi-interface") try: import google.auth import httplib2 except ImportError: logger.warning( "Loading GCP module without the python packages httplib2, google-auth. \ This *could* crash at runtime if no other credentials are provided." ) de...
--- +++ @@ -1,3 +1,6 @@+""" +Common code for GCP (google cloud services) integration +""" import logging @@ -14,6 +17,14 @@ def get_authenticate_kwargs(oauth_credentials=None, http_=None): + """Returns a dictionary with keyword arguments for use with discovery + + Prioritizes oauth_credentials or a http ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/gcp.py
Add docstrings for internal functions
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Provides functionality to run a Hadoop job using a Jar +""" import logging import os @@ -28,6 +31,14 @@ def fix_paths(job): + """ + Coerce input arguments to use tempo...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/hadoop_jar.py
Add clean documentation to messy code
# -*- coding: utf-8 -*- # # Copyright (c) 2019 Jose-Ignacio Riaño Chico # # 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 a...
--- +++ @@ -65,8 +65,15 @@ class DropboxClient(FileSystem): + """ + Dropbox client for authentication, designed to be used by the :py:class:`DropboxTarget` class. + """ def __init__(self, token, user_agent="Luigi", root_namespace_id=None): + """ + :param str token: Dropbox Oauth2 Token...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/dropbox.py
Document helper functions with docstrings
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,16 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +This library is a wrapper of ftplib or pysftp. +It is convenient to move data from/to (S)FTP servers. + +There is an example on how to use it (example/ftp_experiment_outputs.py) + ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/ftp.py
Write reusable docstrings
# -*- coding: utf-8 -*- # # Copyright 2015 Outlier Bio, LLC # # 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 la...
--- +++ @@ -15,6 +15,40 @@ # limitations under the License. # +""" +EC2 Container Service wrapper for Luigi + +From the AWS website: + + Amazon EC2 Container Service (ECS) is a highly scalable, high performance + container management service that supports Docker containers and allows you + to easily run applicati...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/ecs.py
Generate docstrings for script automation
import logging import os import time import luigi from luigi.contrib import gcp logger = logging.getLogger("luigi-interface") _dataproc_client = None try: import google.auth from googleapiclient import discovery from googleapiclient.errors import HttpError DEFAULT_CREDENTIALS, _ = google.auth.defa...
--- +++ @@ -1,3 +1,4 @@+"""luigi bindings for Google Dataproc on Google Cloud""" import logging import os @@ -43,6 +44,10 @@ class DataprocBaseTask(_DataprocBaseTask): + """ + Base task for running jobs in Dataproc. It is recommended to use one of the tasks specific to your job type. + Extend this clas...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/dataproc.py
Write docstrings that follow conventions
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,6 +15,19 @@ # limitations under the License. # +""" +luigi.configuration provides some convenience wrappers around Python's +ConfigParser to get configuration options from config files. + +The default location for configuration files is luigi.cfg (or client.cfg) in the current +working directory, then...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/configuration/cfg_parser.py
Create docstrings for reusable components
# -*- coding: utf-8 -*- # # Copyright 2018 Outlier Bio, LLC # # 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 la...
--- +++ @@ -15,6 +15,49 @@ # limitations under the License. # +""" +AWS Batch wrapper for Luigi + +From the AWS website: + + AWS Batch enables you to run batch computing workloads on the AWS Cloud. + + Batch computing is a common way for developers, scientists, and engineers + to access large amounts of com...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/batch.py
Help me document legacy Python code
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,6 +15,9 @@ # limitations under the License. # +""" +The implementations of the hdfs clients. +""" import logging import threading @@ -29,6 +32,9 @@ def get_autoconfig_client(client_cache=_AUTOCONFIG_CLIENT): + """ + Creates the client as specified in the `luigi.cfg` configuration. + "...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/hdfs/clients.py
Write docstrings including parameters and return values
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,6 +15,9 @@ # limitations under the License. # +""" +The implementations of the hdfs clients. +""" import datetime import logging @@ -33,6 +36,10 @@ def create_hadoopcli_client(): + """ + Given that we want one of the hadoop cli clients, + this one will return the right one. + """ ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/hdfs/hadoopcli_clients.py
Add structured docstrings to improve clarity
# -*- coding: utf-8 -*- # # Copyright 2017 Spotify AB. # # 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...
--- +++ @@ -27,12 +27,33 @@ class ExternalDailySnapshot(luigi.ExternalTask): + """ + Abstract class containing a helper method to fetch the latest snapshot. + + Example:: + + class MyTask(luigi.Task): + def requires(self): + return PlaylistContent.latest() + + All tasks subclassing ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/external_daily_snapshot.py
Create docstrings for all classes and functions
# # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,9 @@ # limitations under the License. # +""" +Provides access to HDFS using the :py:class:`HdfsTarget`, a subclass of :py:class:`~luigi.target.Target`. +""" import random import warnings @@ -108,6 +111,12 @@ self.fs.remove(self.path, skip_trash=skip_trash) def rename(self, pat...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/hdfs/target.py
Generate docstrings for this script
# -*- coding: utf-8 -*- # # Copyright 2015 Twitter Inc # # 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 ...
--- +++ @@ -15,6 +15,7 @@ # limitations under the License. # +"""luigi bindings for Google Cloud Storage""" import io import logging @@ -78,6 +79,11 @@ def _wait_for_consistency(checker): + """Eventual consistency: wait until GCS reports something is true. + + This is necessary for e.g. create/delete w...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/gcs.py
Document my Python code with docstrings
# -*- coding: utf-8 -*- # # Copyright 2012-2016 Spotify AB # # 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...
--- +++ @@ -14,6 +14,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Template tasks for running external programs as luigi tasks. + +This module is primarily intended for when you need to call a single external +program or shell script, and it's eno...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/external_program.py
Document functions with clear intent
# -*- coding: utf-8 -*- # # Copyright (c) 2018 Microsoft Corporation # # 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 appl...
--- +++ @@ -29,8 +29,40 @@ class AzureBlobClient(FileSystem): + """ + Create an Azure Blob Storage client for authentication. + Users can create multiple storage account, each of which acts like a silo. Under each storage account, we can + create a container. Inside each container, the user can create m...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/azureblob.py
Document all public functions with docstrings
# -*- coding: utf-8 -*- # # Copyright 2015 VNG Corporation # # 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...
--- +++ @@ -15,6 +15,14 @@ # limitations under the License. # +""" +A luigi file system client that wraps around the hdfs-library (a webhdfs +client) + +Note. This wrapper client is not feature complete yet. As with most software +the authors only implement the features they need. If you need to wrap more of +the f...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/hdfs/webhdfs_client.py
Document all public functions with docstrings
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Provides a :class:`WebHdfsTarget` using the `Python hdfs +<https://pypi.python.org/pypi/hdfs/>`_ + +This module is DEPRECATED and does not play well with rest of luigi's hdfs +cont...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/webhdfs.py
Write Python docstrings for this snippet
# -*- coding: utf-8 -*- # # Copyright 2015 Outlier Bio, LLC # # 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 la...
--- +++ @@ -16,6 +16,22 @@ # +""" +Kubernetes Job wrapper for Luigi. + +From the Kubernetes website: + + Kubernetes is an open-source system for automating deployment, scaling, + and management of containerized applications. + +For more information about Kubernetes Jobs: http://kubernetes.io/docs/user-guide/j...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/kubernetes.py
Document this script properly
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,71 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Support for Elasticsearch (1.0.0 or newer). + +Provides an :class:`ElasticsearchTarget` and a :class:`CopyToIndex` template task. + +Modeled after :class:`luigi.contrib.rdbms.CopyT...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/esindex.py
Add docstrings that explain logic
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,6 +15,10 @@ # limitations under the License. # +""" +You can configure what client by setting the "client" config under the "hdfs" section in the configuration, or using the ``--hdfs-client`` command line option. +"hadoopcli" is the slowest, but should work out of the box. +""" import getpass impo...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/hdfs/config.py
Generate documentation strings for clarity
import logging from luigi.contrib.bigquery import BigQueryLoadTask, SourceFormat from luigi.contrib.gcs import GCSClient from luigi.task import flatten logger = logging.getLogger("luigi-interface") try: import avro import avro.datafile except ImportError: logger.warning("bigquery_avro module imported, b...
--- +++ @@ -1,3 +1,4 @@+"""Specialized tasks for handling Avro data in BigQuery from GCS.""" import logging @@ -15,6 +16,17 @@ class BigQueryLoadAvro(BigQueryLoadTask): + """A helper for loading specifically Avro data into BigQuery from GCS. + + Copies table level description from Avro schema doc, + B...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/bigquery_avro.py
Add return value explanations in docstrings
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -36,29 +36,53 @@ class _CredentialsMixin: + """ + This mixin is used to provide the same credential properties + for AWS to all Redshift tasks. It also provides a helper method + to generate the credentials string for the task. + """ @property def configuration_section(self): +...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/redshift.py
Help me write clear docstrings
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Implements a subclass of :py:class:`~luigi.target.Target` that writes data to Postgres. +Also provides a helper task to copy data into a Postgres table. +""" import datetime im...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/postgres.py
Please document this code using docstrings
# -*- coding: utf-8 -*- # # Copyright 2017 Big Datext Inc # # 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 ...
--- +++ @@ -19,8 +19,17 @@ class MongoTarget(Target): + """Target for a resource in MongoDB""" def __init__(self, mongo_client, index, collection): + """ + :param mongo_client: MongoClient instance + :type mongo_client: MongoClient + :param index: database index + :type ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/mongodb.py
Provide docstrings following PEP 257
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,6 +15,12 @@ # limitations under the License. # +""" +Run Hadoop Mapreduce jobs using Hadoop Streaming. To run a job, you need +to subclass :py:class:`luigi.contrib.hadoop.JobTask` and implement a +``mapper`` and ``reducer`` methods. See :doc:`/example_top_artists` for +an example of how to run a Hadoo...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/hadoop.py
Create Google-style docstrings for my code
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,6 +15,19 @@ # limitations under the License. # +"""OpenerTarget support, allows easier testing and configuration by abstracting +out the LocalTarget, S3Target, and MockTarget types. + +Example: + +.. code-block:: python + + from luigi.contrib.opener import OpenerTarget + + OpenerTarget('/local/p...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/opener.py
Create Google-style docstrings for my code
# -*- coding: utf-8 -*- import logging import os import random import shutil import subprocess import sys import time try: # Dill is used for handling pickling and unpickling if there is a deference # in server setups between the LSF submission node and the nodes in the # cluster import dill as pickl...
--- +++ @@ -1,5 +1,22 @@ # -*- coding: utf-8 -*- +""" +.. Copyright 2012-2015 Spotify AB + Copyright 2018 + Copyright 2018 EMBL-European Bioinformatics Institute + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may o...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/lsf.py
Add docstrings that explain inputs and outputs
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -34,6 +34,15 @@ class SparkSubmitTask(ExternalProgramTask): + """ + Template task for running a Spark job + + Supports running jobs on Spark local, standalone, Mesos or Yarn + + See http://spark.apache.org/docs/latest/submitting-applications.html + for more information + + """ # ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/spark.py
Document this module using docstrings
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,6 +15,9 @@ # limitations under the License. # +""" +Module containing abstract class about hdfs clients. +""" import abc @@ -22,11 +25,30 @@ class HdfsFileSystem(luigi.target.FileSystem, metaclass=abc.ABCMeta): + """ + This client uses Apache 2.x syntax for file system commands, which a...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/hdfs/abstract_client.py
Write docstrings for algorithm functions
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -37,6 +37,9 @@ def get_soql_fields(soql): + """ + Gets queried columns names. + """ soql_fields = re.search("(?<=select)(?s)(.*)(?=from)", soql, re.IGNORECASE) # get fields soql_fields = re.sub(" ", "", soql_fields.group()) # remove extra spaces soql_fields = re.sub("\t", "", so...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/salesforce.py
Add docstrings for internal functions
# -*- coding: utf-8 -*- # # Copyright (c) 2015 Gouthaman Balaraman # # 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 applic...
--- +++ @@ -14,6 +14,130 @@ # License for the specific language governing permissions and limitations under # the License. # +""" +Support for SQLAlchemy. Provides SQLAlchemyTarget for storing in databases +supported by SQLAlchemy. The user would be responsible for installing the +required database driver to connect ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/sqla.py
Write docstrings for data processing functions
# -*- coding: utf-8 -*- # # Copyright 2017 Open Targets # # 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...
--- +++ @@ -15,6 +15,20 @@ # limitations under the License. # +""" +MicroSoft OpenPAI Job wrapper for Luigi. + + "OpenPAI is an open source platform that provides complete AI model training and resource management capabilities, + it is easy to extend and supports on-premise, cloud and hybrid environments in variou...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/pai.py
Create docstrings for API functions
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -33,10 +33,29 @@ class MySqlTarget(luigi.Target): + """ + Target for a resource in MySql. + """ marker_table = luigi.configuration.get_config().get("mysql", "marker-table", "table_updates") def __init__(self, host, database, user, password, table, update_id, **cnx_kwargs): + ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/mysqldb.py
Add standardized docstrings across the file
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,6 +15,69 @@ # limitations under the License. # +"""SGE batch system Tasks. + +Adapted by Jake Feala (@jfeala) from +`LSF extension <https://github.com/dattalab/luigi/blob/lsf/luigi/lsf.py>`_ +by Alex Wiltschko (@alexbw) +Maintained by Jake Feala (@jfeala) + +SunGrid Engine is a job scheduler used to a...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/sge.py
Write docstrings including parameters and return values
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -31,10 +31,28 @@ class RedisTarget(Target): + """Target for a resource in Redis.""" marker_prefix = Parameter(default="luigi", config_path=dict(section="redis", name="marker-prefix")) def __init__(self, host, port, db, update_id, password=None, socket_timeout=None, expire=None): + ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/redis_store.py
Generate descriptive docstrings automatically
import inspect import logging import re from collections import OrderedDict from contextlib import closing from enum import Enum from time import sleep import luigi from luigi.contrib import rdbms from luigi.task_register import Register logger = logging.getLogger("luigi-interface") try: from pyhive.exc import D...
--- +++ @@ -30,6 +30,10 @@ class PrestoClient: + """ + Helper class wrapping `pyhive.presto.Connection` + for executing presto queries and tracking progress + """ def __init__(self, connection, sleep_time=1): self.sleep_time = sleep_time @@ -38,13 +42,26 @@ @property def perce...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/presto.py
Document functions with detailed explanations
# -*- coding: utf-8 -*- # # Copyright 2019 Spotify AB # # 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 a...
--- +++ @@ -31,6 +31,12 @@ class DataflowParamKeys(metaclass=abc.ABCMeta): + """ + Defines the naming conventions for Dataflow execution params. + For example, the Java API expects param names in lower camel case, whereas + the Python implementation expects snake case. + + """ @property @...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/beam_dataflow.py
Add docstrings for production code
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Implementation of Simple Storage Service support. +:py:class:`S3Target` is a subclass of the Target class to support S3 file +system operations. The `boto3` library is required to ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/s3.py
Generate descriptive docstrings automatically
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Apache Pig support. +Example configuration section in luigi.cfg:: + + [pig] + # pig home directory + home: /usr/share/pig +""" import logging import os @@ -38,21 +46,5...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/pig.py
Write docstrings for algorithm functions
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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 requ...
--- +++ @@ -16,6 +16,16 @@ # limitations under the License. # +""" +Since after Luigi 2.5.0, this is a private module to Luigi. Luigi users should +not rely on that importing this module works. Furthermore, "luigi mr streaming" +have been greatly superseeded by technologies like Spark, Hive, etc. + +The hadoop runn...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/mrrunner.py
Generate consistent docstrings
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,6 +15,10 @@ # limitations under the License. # +""" +Provides a database backend to the central scheduler. This lets you see historical runs. +See :ref:`TaskHistory` for information about how to turn out the task history feature. +""" # # Description: Added codes for visualization of how long each t...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/db_task_history.py
Write clean docstrings for readability
# -*- coding: utf-8 -*- import os import sys try: # Dill is used for handling pickling and unpickling if there is a deference # in server setups between the LSF submission node and the nodes in the # cluster import dill as pickle except ImportError: import pickle import logging from luigi.safe_e...
--- +++ @@ -1,5 +1,22 @@ # -*- coding: utf-8 -*- +""" +.. Copyright 2012-2015 Spotify AB + Copyright 2018 + Copyright 2018 EMBL-European Bioinformatics Institute + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may o...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/lsf_runner.py
Document helper functions with docstrings
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,28 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Light-weight remote execution library and utilities. + +There are some examples in the unittest but I added another that is more +luigi-specific in the examples directory (examples...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/ssh.py
Add docstrings that explain logic
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +A module containing classes used to simulate certain behaviors +""" import hashlib import logging @@ -27,6 +30,27 @@ class RunAnywayTarget(luigi.Target): + """ + A tar...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/simulate.py
Add docstrings to incomplete code
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,18 +15,50 @@ # limitations under the License. # +""" +``luigi.date_interval`` provides convenient classes for date algebra. +Everything uses ISO 8601 notation, i.e. YYYY-MM-DD for dates, etc. +There is a corresponding :class:`luigi.parameter.DateIntervalParameter` that you can use to parse date interv...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/date_interval.py
Fill in missing docstrings in my code
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -26,6 +26,9 @@ class FileWrapper: + """ + Wrap `file` in a "real" so stuff can be added to it after creation. + """ def __init__(self, file_object): self._subpipe = file_object @@ -50,6 +53,13 @@ class InputPipeProcessWrapper: def __init__(self, command, input_pipe=None): ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/format.py
Add docstrings for utility scripts
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,6 +15,22 @@ # limitations under the License. # +""" +The SunGrid Engine runner + +The main() function of this module will be executed on the +compute node by the submitted job. It accepts as a single +argument the shared temp folder containing the package archive +and pickled task to run, and carries ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/sge_runner.py
Create Google-style docstrings for my code
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -59,6 +59,9 @@ class ScaldingJobRunner(luigi.contrib.hadoop.JobRunner): + """ + JobRunner for `pyscald` commands. Used to run a ScaldingJobTask. + """ def __init__(self): conf = luigi.configuration.get_config() @@ -212,41 +215,83 @@ class ScaldingJobTask(luigi.contrib.hadoop....
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/scalding.py
Add professional docstrings to my codebase
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,6 +15,9 @@ # limitations under the License. # +""" +:class:`LocalTarget` provides a concrete implementation of a :py:class:`~luigi.target.Target` class that uses files on the local file system +""" import errno import io @@ -29,6 +32,9 @@ class atomic_file(AtomicLocalFile): + """Simple clas...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/local_target.py
Add docstrings to incomplete code
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +A common module for postgres like databases, such as postgres or redshift +""" from __future__ import annotations @@ -28,9 +31,68 @@ class _MetadataColumnsMixin: + """Pr...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/rdbms.py
Write reusable docstrings
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +This module contains the bindings for command line integration and dynamic loading of tasks + +If you don't want to run luigi from the command line. You may use the methods +define...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/interface.py
Write docstrings for utility functions
#!/usr/bin/env python # Finds all tasks and task outputs on the dependency paths from the given downstream task T # up to the given source/upstream task S (optional). If the upstream task is not given, # all upstream tasks on all dependency paths of T will be returned. # Terms: # if the execution of Task T depends ...
--- +++ @@ -65,21 +65,36 @@ class upstream(luigi.task.Config): + """ + Used to provide the parameter upstream-family + """ family = parameter.OptionalParameter(default=None) def find_deps(task, upstream_task_family): + """ + Finds all dependencies that start with the given task and have a...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/tools/deps.py
Write docstrings for utility functions
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Locking functionality when launching things from the command line. +Uses a pidfile. +This prevents multiple identical workflows to be launched simultaneously. +""" import errno ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/lock.py
Add docstrings including usage examples
from __future__ import annotations from typing import Callable, Dict, Final, Iterator, List, Literal, Optional from mypy.expandtype import expand_type, expand_type_by_instance from mypy.nodes import ( ARG_NAMED_OPT, ARG_POS, Argument, AssignmentStmt, Block, CallExpr, ClassDef, Context...
--- +++ @@ -1,3 +1,8 @@+"""Plugin that provides support for luigi.Task + +This Code reuses the code from mypy.plugins.dataclasses +https://github.com/python/mypy/blob/0753e2a82dad35034e000609b6e8daa37238bfaa/mypy/plugins/dataclasses.py +""" from __future__ import annotations @@ -64,6 +69,7 @@ return None ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/mypy.py
Add structured docstrings to improve clarity
import abc import importlib from enum import Enum class MetricsCollectors(Enum): custom = -1 default = 1 none = 1 datadog = 2 prometheus = 3 @classmethod def get(cls, which, custom_import=None): if which == MetricsCollectors.none: return NoMetricsCollector() el...
--- +++ @@ -43,6 +43,9 @@ class MetricsCollector(metaclass=abc.ABCMeta): + """Abstractable MetricsCollector base class that can be replace by tool + specific implementation. + """ @abc.abstractmethod def __init__(self): @@ -75,6 +78,7 @@ class NoMetricsCollector(MetricsCollector): + """E...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/metrics.py
Write clean docstrings for readability
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,6 +15,17 @@ # limitations under the License. # +"""Supports sending emails when tasks fail. + +This needs some more documentation. +See :doc:`/configuration` for configuration options. +In particular using the config `receiver` should set up Luigi so that it will send emails when tasks fail. + +.. cod...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/notifications.py
Add detailed docstrings explaining each function
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -31,10 +31,31 @@ class MSSqlTarget(luigi.Target): + """ + Target for a resource in Microsoft SQL Server. + This module is primarily derived from mysqldb.py. Much of MSSqlTarget, + MySqlTarget and PostgresTarget are similar enough to potentially add a + RDBMSTarget abstract base class to r...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/contrib/mssqldb.py
Add docstrings explaining edge cases
# -*- coding: utf-8 -*- # Copyright (c) 2014 Spotify AB # # 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...
--- +++ @@ -13,6 +13,17 @@ # License for the specific language governing permissions and limitations under # the License. +""" +Produces contiguous completed ranges of recurring tasks. + +See ``RangeDaily`` and ``RangeHourly`` for basic usage. + +Caveat - if gaps accumulate, their causes (e.g. missing dependencies) ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/tools/range.py
Generate consistent documentation across files
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +This module provides a class :class:`MockTarget`, an implementation of :py:class:`~luigi.target.Target`. +:class:`MockTarget` contains all data in-memory. +The main purpose is unit...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/mock.py
Write docstrings for utility functions
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -49,6 +49,7 @@ def get_config(parser=None): + """Get configs singleton for parser""" if parser is None: parser = _get_default_parser() parser_class = PARSERS[parser] @@ -57,6 +58,7 @@ def add_config_path(path): + """Select config parser by file extension and add path into par...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/configuration/core.py
Write docstrings for utility functions
from collections import OrderedDict try: from collections.abc import Mapping except ImportError: from collections import Mapping # type: ignore import functools import operator class FrozenOrderedDict(Mapping): def __init__(self, *args, **kwargs): self.__dict = OrderedDict(*args, **kwargs) ...
--- +++ @@ -1,3 +1,7 @@+"""Internal-only module with immutable data structures. + +Please, do not use it outside of Luigi codebase itself. +""" from collections import OrderedDict @@ -10,6 +14,10 @@ class FrozenOrderedDict(Mapping): + """ + It is an immutable wrapper around ordered dictionaries that impl...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/freezing.py
Document my Python code with docstrings
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +The system for scheduling tasks and executing them in order. +Deals with dependencies, priorities, resources, etc. +The :py:class:`~luigi.worker.Worker` pulls tasks from the schedu...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/scheduler.py
Add docstrings explaining edge cases
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Simple REST server that takes commands in a JSON payload +Interface to the :py:class:`~luigi.scheduler.Scheduler` class. +See :doc:`/central_scheduler` for more info. +""" # # De...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/server.py
Generate documentation strings for clarity
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Define the centralized register of all :class:`~luigi.task.Task` classes. +""" import abc import logging @@ -35,6 +38,15 @@ class Register(abc.ABCMeta): + """ + The Me...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/task_register.py
Help me write clear docstrings
# -*- coding: utf-8 -*- # # Copyright 2018 Vote Inc. # # 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 ag...
--- +++ @@ -14,6 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +This module contains helper classes for configuring logging for luigid and +workers via command line arguments and options from config files. +""" import logging import logging...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/setup_logging.py
Write docstrings for utility functions
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Implementation of the REST interface between the workers and the server. +rpc.py implements the client side of it, server.py implements the server side. +See :doc:`/central_schedul...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/rpc.py
Add docstrings with type hints explained
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,6 +15,10 @@ # limitations under the License. # +"""Parameters are one of the core concepts of Luigi. +All Parameters sit on :class:`~luigi.task.Task` classes. +See :ref:`Parameter` for more info on how to define parameters. +""" import abc import datetime @@ -59,6 +63,7 @@ class _NoValueType: ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/parameter.py
Add docstrings following best practices
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Abstract class for task history. +Currently the only subclass is :py:class:`~luigi.db_task_history.DbTaskHistory`. +""" import abc import logging @@ -22,6 +26,9 @@ class St...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/task_history.py
Help me write clear docstrings
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -15,27 +15,83 @@ # limitations under the License. # +""" +This module provides a class `SafeExtractor` that offers a secure way to extract tar files while +mitigating path traversal vulnerabilities, which can occur when files inside the archive are +crafted to escape the intended extraction directory. + +...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/safe_extractor.py
Replace inline comments with docstrings
# -*- coding: utf-8 -*- # # Copyright 2015-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +This module provide the function :py:func:`summary` that is used for printing +an `execution summary +<https://github.com/spotify/luigi/blob/master/examples/execution_summary_examp...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/execution_summary.py
Write proper docstrings for these functions
# -*- coding: utf-8 -*- # # Copyright 2015-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +Module containing the logic for exit codes for the luigi binary. It's useful +when you in a programmatic way need to know if luigi actually finished the +given task, and if not why...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/retcodes.py
Document functions with clear intent
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +The abstract :py:class:`Target` class. +It is a central concept of Luigi and represents the state of the workflow. +""" import abc import io @@ -28,70 +32,189 @@ class Targ...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/target.py
Create simple docstrings for beginners
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +The abstract :py:class:`Task` class. +It is a central concept of Luigi and represents the state of the workflow. +See :doc:`/tasks` for an overview. +""" import copy import fun...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/task.py
Create structured documentation for my script
# -*- coding: utf-8 -*- import sys import warnings from luigi.cmdline_parser import CmdlineParser from luigi.task import flatten class bcolors: OKBLUE = "\033[94m" OKGREEN = "\033[92m" ENDC = "\033[0m" def print_tree(task, indent="", last=True): # dont bother printing out warnings about tasks wit...
--- +++ @@ -1,4 +1,27 @@ # -*- coding: utf-8 -*- +""" +This module parses commands exactly the same as the luigi task runner. You must specify the module, the task and task parameters. +Instead of executing a task, this module prints the significant parameters and state of the task and its dependencies in a tree format...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/tools/deps_tree.py
Create docstrings for all classes and functions
#!/usr/bin/env python import argparse import json from collections import defaultdict from urllib.request import urlopen class LuigiGrep: def __init__(self, host, port): self._host = host self._port = port @property def graph_url(self): return "http://{0}:{1}/api/graph".format(se...
--- +++ @@ -16,6 +16,7 @@ return "http://{0}:{1}/api/graph".format(self._host, self._port) def _fetch_json(self): + """Returns the json representation of the dep graph""" print("Fetching from url: " + self.graph_url) resp = urlopen(self.graph_url).read() return json.load...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/tools/luigi_grep.py
Add docstrings to incomplete code
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,208 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +============================================================ +Using ``inherits`` and ``requires`` to ease parameter pain +=========================================================...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/util.py
Add docstrings explaining edge cases
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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...
--- +++ @@ -14,6 +14,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # +""" +The worker communicates with the scheduler and does two things: + +1. Sends all tasks that has to be run +2. Gets tasks from the scheduler that should be run + +When running in loc...
https://raw.githubusercontent.com/spotify/luigi/HEAD/luigi/worker.py
Expand my code with proper documentation strings
from enum import Enum, IntEnum class Stage(Enum): IDLE = 0 # Waiting for request REQUEST = 1 # Request headers being received HANDLER = 3 # Headers done, handler running RESPONSE = 4 # Response headers sent, body in progress FAILED = 100 # Unrecoverable state (error while sending response) ...
--- +++ @@ -2,6 +2,15 @@ class Stage(Enum): + """Enum for representing the stage of the request/response cycle + + | ``IDLE`` Waiting for request + | ``REQUEST`` Request headers being received + | ``HANDLER`` Headers done, handler running + | ``RESPONSE`` Response headers sent, body in progress +...
https://raw.githubusercontent.com/sanic-org/sanic/HEAD/sanic/http/constants.py
Write proper docstrings for these functions
from __future__ import annotations from collections.abc import Iterable, Sequence from datetime import datetime from operator import itemgetter from pathlib import Path from stat import S_ISDIR from typing import cast from urllib.parse import unquote from sanic.exceptions import NotFound from sanic.pages.directory_pa...
--- +++ @@ -15,6 +15,13 @@ def _is_path_within_root(path: Path, root: Path) -> bool: + """Check if a path (after resolution) is within the root directory. + + Returns False for: + - Broken symlinks (cannot be resolved) + - Paths that resolve outside the root directory + - Any errors during resolution...
https://raw.githubusercontent.com/sanic-org/sanic/HEAD/sanic/handlers/directory.py
Document classes and their methods
from abc import ABC, abstractmethod from shutil import get_terminal_size from textwrap import indent, wrap from sanic import __version__ from sanic.helpers import is_atty from sanic.log import logger class MOTD(ABC): def __init__( self, logo: str | None, serve_location: str, data...
--- +++ @@ -8,6 +8,7 @@ class MOTD(ABC): + """Base class for the Message of the Day (MOTD) display.""" def __init__( self, @@ -25,6 +26,7 @@ @abstractmethod def display(self): + """Display the MOTD.""" @classmethod def output( @@ -34,11 +36,23 @@ data: dict[s...
https://raw.githubusercontent.com/sanic-org/sanic/HEAD/sanic/application/motd.py
Write docstrings for data processing functions
from __future__ import annotations from abc import ABC, ABCMeta, abstractmethod from collections.abc import Sequence from inspect import getmembers, isclass, isdatadescriptor from os import environ from pathlib import Path from typing import Any, Callable, Literal from warnings import filterwarnings from sanic.consta...
--- +++ @@ -74,6 +74,7 @@ class DescriptorMeta(ABCMeta): + """Metaclass for Config.""" def __init__(cls, *_): cls.__setters__ = {name for name, _ in getmembers(cls, cls._is_setter)} @@ -84,14 +85,55 @@ class DetailedConverter(ABC): + """Base class for detailed converters that need addition...
https://raw.githubusercontent.com/sanic-org/sanic/HEAD/sanic/config.py
Add docstrings to clarify complex logic
from __future__ import annotations import re import string from datetime import datetime from typing import TYPE_CHECKING, Literal, cast from sanic.exceptions import ServerError if TYPE_CHECKING: from sanic.compat import Header SameSite = ( Literal["Strict"] | Literal["Lax"] | Literal["None"] ...
--- +++ @@ -31,6 +31,11 @@ def _quote(str): # no cov + r"""Quote a string for use in a cookie header. + If the string does not need to be double-quoted, then just return the + string. Otherwise, surround the string in doublequotes and quote + (with a \) special characters. + """ if str is None...
https://raw.githubusercontent.com/sanic-org/sanic/HEAD/sanic/cookies/response.py