Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More pylint fixes #133

Merged
merged 19 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Contributors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Contributors

Mikael Koli - creator of Rocketry
Mark Mayo - fixes and clean up of repo with python 3 updates, pylint issues
1 change: 1 addition & 0 deletions docs/code/conds/api/cron_kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def do_simple():
"Run at every 5th minute"
...

marksmayo marked this conversation as resolved.
Show resolved Hide resolved

@app.task(cron(minute="*/2", hour="7-18", day_of_month="1,2,3", month="Feb-Aug/2"))
def do_complex():
"""Run at:
Expand Down
1 change: 1 addition & 0 deletions docs/code/conds/api/crontime_kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def do_simple():
"Run at every 5th minute"
...
marksmayo marked this conversation as resolved.
Show resolved Hide resolved


@app.task(crontime(minute="*/2", hour="7-18", day_of_month="1,2,3", month="Feb-Aug/2"))
def do_complex():
"""Run at:
Expand Down
1 change: 0 additions & 1 deletion docs/code/conds/api/pipe_with_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

@app.task(daily)
def do_first():
...
return 'Hello World'

@app.task(after_success(do_first))
Expand Down
4 changes: 2 additions & 2 deletions docs/code/conds/api/task_running.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ def do_if_runs_less_than():

@app.task(running(do_things).between("2 mins", "5 mins"))
def do_if_runs_between():
...
# Starts if do_things is running
...
# Starts if do_things is running
# less than 2 mins but no more than 5 minutes
4 changes: 2 additions & 2 deletions docs/code/conds/api/task_running_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

@app.task(running <= 4, multilanch=True)
def do_parallel_limited():
... # Allows 4 parallel runs
... # Allows 4 parallel runs

@app.task(~running, multilanch=True)
def do_non_parallel():
... # Allows no parallel runs

@app.task(running(do_parallel_limited) >= 2)
def do_if_runs_parallel():
... # Runs if the other has at least two parallel runs
... # Runs if the other has at least two parallel runs
2 changes: 1 addition & 1 deletion docs/code/conds/syntax/pipe_with_return.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@app.task("daily")
def do_first():
...

return 'Hello World'

@app.task("after task 'do_first'")
Expand Down
3 changes: 3 additions & 0 deletions docs/code/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ def do_daily():
"This function runs once a day"
...
marksmayo marked this conversation as resolved.
Show resolved Hide resolved


@app.task('daily between 07:00 and 10:00 | daily between 16:00 and 20:00')
def do_twice_a_day():
"This function runs twice a day (in the morning and in the afternoon)"
# The '|' means OR operator. Fully supports logical operations.
...
marksmayo marked this conversation as resolved.
Show resolved Hide resolved


@app.task("after task 'do_daily'")
def do_after_another(arg=Return('do_daily')):
"Run after 'do_daily' task"
# The parameter 'arg' has the return value of the function 'do_daily'
...
marksmayo marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
# Start the scheduler
app.run()
3 changes: 2 additions & 1 deletion docs/code/demos/advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ def do_custom():
"""This task runs once a day and when is_foo returns True
This task runs on separate thread"""
...
marksmayo marked this conversation as resolved.
Show resolved Hide resolved


@app.task('(true & true) | (false & True & ~True)')
def do_complex():
"""Notice the logical expression in the task start condition"""
...
marksmayo marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == "__main__":
app.run()
2 changes: 1 addition & 1 deletion docs/code/demos/minimal_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async def do_things():
async def main():
"Launch Rocketry app (and possibly something else)"
rocketry_task = asyncio.create_task(app.serve())
... # Start possibly other async apps
# Start possibly other async apps
await rocketry_task

if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions docs/code/parameter/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@

@app.task("every 10 seconds")
def do_things(arg=Arg('my_arg')):
...

# Argument 'arg' has value 'hello'
assert arg == 'hello'
return 'stuff'

@app.task("after task 'do_things'")
def do_with_return(arg=Return('do_things')):
...

# Argument 'arg' is the return value of the task 'do_things'
assert arg == 'stuff'

@app.task("after task 'do_things'")
def do_with_funcarg(arg=FuncArg(lambda: 'hello world')):
...

# Argument 'arg' is the return value of the task 'do_things'
assert arg == 'stuff'

Expand Down
6 changes: 3 additions & 3 deletions docs/code/parameter/pipelining.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

@app.task("every 10 seconds")
def do_things():
...

return 'hello'

@app.task("after task 'do_things'")
def do_after(arg=Return('do_things')):
...

assert arg == 'hello'
return 'world'

@app.task("after task 'do_things', 'do_stuff'")
def do_after_all(arg1=Return('do_things'), arg2=Return('do_stuff')):
...

assert arg1 == 'hello'
assert arg2 == 'world'
2 changes: 1 addition & 1 deletion docs/code/params/return.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@app.task()
def do_first():
...

return 'Hello World'

@app.task()
Expand Down
4 changes: 2 additions & 2 deletions docs/code/snippets/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

@app.task(daily)
def do_first():
...

return 'Hello World'

@app.task(after_success(do_first))
def do_second(arg=Return(do_first)):
...

return 'Hello Python'
2 changes: 1 addition & 1 deletion rocketry/args/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def get_value(self, task=None, session=None, **kwargs) -> Any:
return task.session

def __repr__(self):
return f'session'
return 'session'

class Task(BaseArgument):
"An argument that represents a task"
Expand Down
5 changes: 2 additions & 3 deletions rocketry/conditions/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,15 @@ def observe(self, **kwargs):
def __call__(self, task=None, more_than=None, less_than=None):
if more_than is not None or less_than is not None or task is None:
warnings.warn(
"running(more_than=..., less_than=...) and running() are derpecated. "
"running(more_than=..., less_than=...) and running() are derpecated. "
"Please use running.more_than, running.less_than, running.between or just running instead.",
DeprecationWarning
)
period = None
if more_than is not None or less_than is not None:
period = TimeSpanDelta(near=more_than, far=less_than)
return TaskRunning(task=task, period=period)
else:
return RunningWrapper(task)
return RunningWrapper(task)

def more_than(self, delta):
"Get condition the wrapper represents"
Expand Down
86 changes: 43 additions & 43 deletions rocketry/conditions/task/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,54 +172,54 @@ def get_measurement(self, task=Task(), session=Session()):
if allow_optimization:
task = session[self.task] if self.task is not None else task
runs = [
run.start
run.start
for run in task._run_stack
if run.is_alive() and start <= datetime.datetime.fromtimestamp(run.start) <= end
]
return runs
else:
records = task.logger.get_records(
created=between(to_timestamp(start), to_timestamp(end)),
)
records = sorted(records, key=lambda x: get_field_value(x, "created"))
runs = []
has_run_id = True
try:
finishes = [
get_field_value(record, "run_id")
for record in records
if get_field_value(record, "run_id") and get_field_value(record, "action") != "run"
]
except (KeyError, AttributeError):
# Logs have no run_id
finishes = [
get_field_value(record, "created")
for record in records
if get_field_value(record, "action") != "run"
]
has_run_id = False

for record in records:
action = get_field_value(record, "action")
is_run = action == "run"
if not is_run:
continue
if has_run_id:
run_id = get_field_value(record, "run_id")
if run_id not in finishes:
runs.append(run_id)

records = task.logger.get_records(
created=between(to_timestamp(start), to_timestamp(end)),
)
records = sorted(records, key=lambda x: get_field_value(x, "created"))
runs = []
has_run_id = True
try:
finishes = [
get_field_value(record, "run_id")
for record in records
if get_field_value(record, "run_id") and get_field_value(record, "action") != "run"
]
except (KeyError, AttributeError):
# Logs have no run_id
finishes = [
get_field_value(record, "created")
for record in records
if get_field_value(record, "action") != "run"
]
has_run_id = False

for record in records:
action = get_field_value(record, "action")
is_run = action == "run"
if not is_run:
continue
if has_run_id:
run_id = get_field_value(record, "run_id")
if run_id not in finishes:
runs.append(run_id)
else:
# Less optimized, tries to guess which is the finish
created = get_field_value(record, "created")
for finish in finishes.copy():
if finish >= created:
# match
finishes.remove(finish)
break
else:
# Less optimized, tries to guess which is the finish
created = get_field_value(record, "created")
for finish in finishes.copy():
if finish >= created:
# match
finishes.remove(finish)
break
else:
# No finishes
runs.append(created)
return runs
# No finishes
runs.append(created)
return runs

def __str__(self):
if hasattr(self, "_str"):
Expand Down
14 changes: 7 additions & 7 deletions rocketry/core/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,14 @@ async def startup(self):
Starting up includes setting up attributes and
running tasks that have ``on_startup`` as ``True``."""
#self.setup_listener()
self.logger.info(f"Starting up...", extra={"action": "setup"})
self.logger.info("Starting up...", extra={"action": "setup"})
hooker = _Hooker(self.session.hooks.scheduler_startup)
hooker.prerun(self)

self.n_cycles = 0
self.startup_time = datetime.datetime.fromtimestamp(time.time())

self.logger.debug(f"Beginning startup sequence...")
self.logger.debug("Beginning startup sequence...")
for task in self.tasks:
if task.on_startup:
if isinstance(task.start_cond, AlwaysFalse) and not task.disabled:
Expand All @@ -320,7 +320,7 @@ async def startup(self):
await self.run_task(task)

hooker.postrun()
self.logger.info(f"Startup complete.")
self.logger.info("Startup complete.")

def has_free_processors(self) -> bool:
"""Whether the Scheduler has free processors to
Expand Down Expand Up @@ -396,7 +396,7 @@ async def shut_down(self, traceback=None, exception=None):
tasks to finish their termination.
"""

self.logger.debug(f"Beginning shutdown sequence...")
self.logger.debug("Beginning shutdown sequence...")
hooker = _Hooker(self.session.hooks.scheduler_shutdown)
hooker.prerun(self)

Expand All @@ -410,7 +410,7 @@ async def shut_down(self, traceback=None, exception=None):
finally:
# Tasks are shut down/waited for shut down regardless if running shutdown
# tasks failed
self.logger.debug(f"Shutting down tasks...")
self.logger.debug("Shutting down tasks...")
await self._shut_down_tasks(traceback, exception)
finally:
# Processes/threads are wait to shut down regardless if there has been any
Expand All @@ -425,7 +425,7 @@ async def shut_down(self, traceback=None, exception=None):
# Running hooks and finalize the shutdown
hooker.postrun()
self.is_alive = False
self.logger.info(f"Shutdown completed. Good bye.")
self.logger.info("Shutdown completed. Good bye.")

if isinstance(exception, SchedulerRestart):
# Clean up finished, restart is finally
Expand All @@ -438,7 +438,7 @@ async def _restart(self):
process is started.
"""
# https://stackoverflow.com/a/35874988
self.logger.debug(f"Restarting...", extra={"action": "restart"})
self.logger.debug("Restarting...", extra={"action": "restart"})
python = sys.executable

restarting = self.session.config.restarting
Expand Down