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

Allow namespaces to be set to python module #2000

Merged
merged 2 commits into from
Feb 3, 2017

Conversation

Tarrasch
Copy link
Contributor

@Tarrasch Tarrasch commented Jan 25, 2017

This have been a problem I've thought about for years. And also
consciously gradually refactored the code base in previous patches
towards making this relatively short path.

Coming up with the final syntax and implementation also took me a while.
Initially I imagined there would be a [config] parameter one could set,
or specify by command line. But it turned out to be quite troublesome:

  • It's not clear how much it should affect. Should it also affect the
    things luigi exports?
  • It's hard to transition into it. Imagining a company with independent
    teams, the auto_namespace function can be applied package by
    package, luigi-version by luigi-version to whoever chooses to apply
    this new convention.

This solution came out to be pretty clean, and with readable tests and
detailed and a bit opinionated documentation.

Have you tested this? If so, how?

I'm going for a week-long no computer vacation soon. After that I'll try running this in production.

@mention-bot
Copy link

@Tarrasch, thanks for your PR! By analyzing the history of the files in this pull request, we identified @jcrobak, @steenzout and @freider to be potential reviewers.

@Tarrasch Tarrasch force-pushed the allow_namespace_as_module_path branch from 1cbe481 to 9db6af3 Compare January 25, 2017 09:29
@Tarrasch
Copy link
Contributor Author

Rendered docs screenshots:

selection_097

selection_098

@Tarrasch
Copy link
Contributor Author

Tarrasch commented Jan 25, 2017

@ulzha @sisidra, I know you (Spotify) are one of the biggest Luigi users and that you've wanted something similar to this last time I heard from you. What do you think about this patch?

@Tarrasch
Copy link
Contributor Author

Tarrasch commented Feb 2, 2017

Anyone wants to review? @erikbern @dlstadther

@erikbern
Copy link
Contributor

erikbern commented Feb 2, 2017

lgtm but are namespaces widely used? idk

Copy link
Collaborator

@dlstadther dlstadther left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I don't use (nor fully understand) namespaces, I focused my review on docstrings and their clarity.

I've made note of some spelling and english grammar changes.

luigi/task.py Outdated
``scope=__name__``.

The ``scope`` keyword makes so this call is only affective for task classes
with a matching [*]_ ``__module__``. The default value for ``scope`` is the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English correction (if understand correctly):

The scope keyword makes it so that this call is only effective for task classes with a matching [*]___module__.

luigi/task.py Outdated

.. code-block:: python

class Task2(luigi.Task):
task_namespace = 'namespace2'

This explicit setting takes priority over whatever is set in
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

over whatever is set in the

luigi/task.py Outdated
reasons:

* Two tasks with the same name will not have conflicting task families
* It's more pythonic, as modules are pythons recommended way to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python's

luigi/task.py Outdated
* Two tasks with the same name will not have conflicting task families
* It's more pythonic, as modules are pythons recommended way to
do namespacing.
* It's traceable, when you see the full name of a task, you can immedietly
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's traceable. When you see the full name of a task, you can immediately

luigi/task.py Outdated
* It's traceable, when you see the full name of a task, you can immedietly
identify where it is defined.

We recommend to call this function from your package's outermost
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recommend calling this function...

@Tarrasch
Copy link
Contributor Author

Tarrasch commented Feb 3, 2017

@erikbern, that's a really good concern actually. I'm not sure either if people use namespaces. But here's some related facts and thoughts:

  • At Spotify I thought it was hard to know where tasks are defined when there's no namespace. Compare the task family IngestUsersToDbTask vs discover_weekly.ingestions.IngestUsersToDbTask. Also the problem when two different teams have a task named IngestUsersToDbTask, the luigi server cannot distinguish the task families then.
  • I've recently improved documentation about what namespaces is.
  • In an follow up PR I'll try to make it so that instead of luigi --module hello.world hello.world.MyTask --my-param 123 you'll just write luigi hello.world.MyTask --my-param 123. The increased readability and enforced consistency I find to be great wins. Also I tend to like frameworks with conventions so that I don't need to think for myself.
  • There have also been a few others sending PRs about namespaces, so I think some people use them.

@dlstadther, thanks. I'll fix these lingual issues right away. :)

This have been a problem I've thought about for years. And also
consciously gradually refactored the code base in previous patches
towards making this relatively short path.

Coming up with the final syntax and implementation also took me a while.
Initially I imagined there would be a [config] parameter one could set,
or specify by command line. But it turned out to be quite troublesome:

 * It's not clear how much it should affect. Should it also affect the
   things luigi exports?
 * It's hard to transition into it. Imagining a company with independent
   teams, the `auto_namespace` function can be applied package by
   package, luigi-version by luigi-version to whoever chooses to apply
   this new convention.

This solution came out to be pretty clean, and with readable tests and
detailed and a bit opinionated documentation.
@Tarrasch Tarrasch force-pushed the allow_namespace_as_module_path branch from 9db6af3 to 8550df4 Compare February 3, 2017 03:18
@erikbern
Copy link
Contributor

erikbern commented Feb 3, 2017

sounds good!

@Tarrasch Tarrasch dismissed dlstadther’s stale review February 3, 2017 07:08

I've adressed all the errors in the latest commit :) (also, this is first time im pressing dismiss)

@Tarrasch Tarrasch merged commit 10e296f into spotify:master Feb 3, 2017
@Tarrasch Tarrasch deleted the allow_namespace_as_module_path branch February 3, 2017 07:08
kreczko pushed a commit to kreczko/luigi that referenced this pull request Mar 28, 2017
This have been a problem I've thought about for years. And also
consciously gradually refactored the code base in previous patches
towards making this relatively short path.

Coming up with the final syntax and implementation also took me a while.
Initially I imagined there would be a [config] parameter one could set,
or specify by command line. But it turned out to be quite troublesome:

 * It's not clear how much it should affect. Should it also affect the
   things luigi exports?
 * It's hard to transition into it. Imagining a company with independent
   teams, the `auto_namespace` function can be applied package by
   package, luigi-version by luigi-version to whoever chooses to apply
   this new convention.

This solution came out to be pretty clean, and with readable tests and
detailed and a bit opinionated documentation.
@Tarrasch Tarrasch mentioned this pull request Jul 2, 2017
This was referenced Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants