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

Add defaults tags for projects #113

Merged
merged 17 commits into from
Oct 11, 2016
Merged

Conversation

jbarnoud
Copy link
Contributor

Some projects are always used with the same tags. For instance, my
'python101' project should always have the 'teaching' tag attached to
it.

This commit adds a way to declare such default tags in the configuration
file, and have them applied. Default tags are expected to be declared in
a '[default_tags]' section:

[default_tags]
python101 = teaching
watson = contrib python

With the sample configuration above, the 'teaching' tag will always be
attached to the 'python101' project, and the tags 'contrib' and 'python'
will always be attached to the project 'watson'.

Projects that do not appear in the '[default_tags]' section of the
configuration will not be affected by the change.

Note that the tags added by the new mechanism do not show in the output
of watson start. However, they appear in the output of watson status, watson log, and of course watson report.

This pull request is still a work in progress. It still requires at least:

  • to update the documentation
  • to be properly tested

@jbarnoud jbarnoud changed the title Add defaults tags for projects [WIP] Add defaults tags for projects Apr 12, 2016
@SpotlightKid
Copy link
Contributor

Please note that tags can contain spaces. You should probably either change the format of values in the default_tags section to be comma-separated lists (but then commas in tags would not work), or use the split function from stdlib shlex module to parse option values into tag lists (which would allow to put tags with spaces in them in quotes).

@jbarnoud
Copy link
Contributor Author

@SpotlightKid I did not notice you could have spaces in tags. I'll see how I can solve this.

@jbarnoud
Copy link
Contributor Author

I added the doc and the tests, so the PR should be ready for review. Should I rebase now to squash my commits now, or after the review?


```ini
[default_tags]
voyager2 = nana 'space mission'
Copy link
Contributor

Choose a reason for hiding this comment

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

s/nana/nasa

jbarnoud added a commit to jbarnoud/Watson that referenced this pull request Apr 13, 2016

These automatically attached tags are defined in the `[default_tags]` section
of the configuration. Each option bellow that section is a project to which
tags should be attached.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would have written something like:

Default tags are defined in the [default_tags] section. Each entry should follow the pattern: project = tag1 tag2.

same tags are always attached to a project.

These automatically attached tags are defined in the `[default_tags]` section
of the configuration. Each option bellow that section is a project to which
Copy link
Contributor

Choose a reason for hiding this comment

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

s/bellow/below/

But "Each option in this section" is better, IMHO.

jbarnoud added a commit to jbarnoud/Watson that referenced this pull request Apr 13, 2016
Include changes suggested by @SpotlightKid in jazzband#113
default_tags = []
if default_tags_raw is not None:
default_tags = shlex.split(default_tags_raw)
return default_tags
Copy link
Contributor

Choose a reason for hiding this comment

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

I would factor this out into a new method of the config.ConfigParser class.

    def getlist(self, section, option, default=None):
        if not self.has_option(section, option):
            return [] if default is None else default

        value = self.get(section, option)

        if '\n' in value:
            return [item for item in value.splitlines() if item]
        else:
            return shlex.split(value)

This also allows an alternative syntax for lists of tags, some of which have spaces in them:

[default_tags]
interstellar travel = solar sail
    cryogenics
    fusion
watson =
    issue 113
    python

I'll prepare a separate PR for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My local version is now based on #114. I'll push when #114 get merged.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, this took quite some time, but #114 is now merged. Please update our PR, rebase it on the current master and squash the commits. Then it can be merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take care of this latter this week.

@SpotlightKid
Copy link
Contributor

Ping...

Some projects are always used with the same tags. For instance, my
'python101' project should always have the 'teaching' tag attached to
it.

This commit adds a way to declare such default tags in the configuration
file, and have them applied. Default tags are expected to be declared in
a '[default_tags]' section:

    [default_tags]
    python101 = teaching
    watson = contrib python

With the sample configuration above, the 'teaching' tag will always be
attached to the 'python101' project, and the tags 'contrib' and 'python'
will always be attached to the project 'watson'.

Projects that do not appear in the '[default_tags]' section of the
configuration will not be affected by the change.

Note that the tags added by the new mechanism do not show in the output
of `watson start`. However, they appear in the output of `watson
status`, `watson log`, and of course `watson report`.
Use shlex to split the default tags from the configuration file. This
allows to have quotes around tags, therefore allowing spaces. This is
now valid:

    [default_tags]
    super project = fun 'random tag with spaces'
The output of `watson start` now displays the tags from the newly
created frame rather than the tags from the input. This way, if default
tags are added, they appears in the output of `watson start`.
`watson.start` has now a `restart` argument that let it know if it is
called by `watson restart`. This allows to avoid tags to accumulate when
restarting a project that has default tags.
@jbarnoud
Copy link
Contributor Author

Here it is. Sorry for the delay.


def deduplicate(sequence):
"""
Return the input sequence without duplicate, keep the order.
Copy link
Contributor

Choose a reason for hiding this comment

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

More accurately:

Return a list with all items of the input sequence but duplicates removed.

Keeps the order of items in the input sequence.

@SpotlightKid
Copy link
Contributor

Thanks!

Can you address the few new comments I made, then I'll merge.

You can squash you commits or I'll do it when merging.

@jmaupetit
Copy link
Contributor

@jbarnoud : Hacktoberfest starts tomorrow 😉

@jmaupetit
Copy link
Contributor

@jbarnoud please let me know if you don't have time to finish this: I can give a hand! Once this PR has been merged, thanks to @SpotlightKid, we will release Watson 1.4.0 and prepare a RC for 2.0 (FTR, see this comment in #115).

@jbarnoud
Copy link
Contributor Author

jbarnoud commented Oct 4, 2016

It get's to the top of my todo list. They are only a few items remaining
on top of it, so it will be done soon.

On 04-10-16 09:40, Julien Maupetit wrote:

@jbarnoud https://github.com/jbarnoud please let me know if you
don't have time to finish this: I can give a hand! Once this PR has
been merged, thanks to @SpotlightKid
https://github.com/SpotlightKid, we will release Watson 1.4.0 and
prepare a RC for 2.0 (FTR, see this comment
#115 (comment)
in #115 #115).


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#113 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABUWuguO00Rkmym3MiujFGnyi8JBYbpWks5qwgLrgaJpZM4IFkuV.

@jmaupetit
Copy link
Contributor

@SpotlightKid what is your feeling about postponing this feature to the 2.0 release?

@SpotlightKid
Copy link
Contributor

The PR is almost ready. We could also just fix these minor issues I commented on above ourselves.

@jbarnoud
Copy link
Contributor Author

No need to postpone anything anymore. Sorry for the delay, my TODO list was going out of hands.

@jmaupetit
Copy link
Contributor

Thank you @jbarnoud ; I felt bad about fixing your stuff myself.
@SpotlightKid I am letting you review and merge this PR, thanks!

@SpotlightKid SpotlightKid merged commit 155da2b into jazzband:master Oct 11, 2016
@SpotlightKid SpotlightKid changed the title [WIP] Add defaults tags for projects Add defaults tags for projects Oct 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants