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

ENH: add support for calendar name #312

Closed
wants to merge 12 commits into from
Closed

Conversation

tupui
Copy link

@tupui tupui commented Feb 4, 2022

Closes #307

  • Add NAME and X-WR-CALNAME support.
  • X-WR-CALNAME is converted to NAME and X-WR-CALNAME is added in extras.
  • Default name is used when the field is not present.

(For the backstory, I talked about this with @stefanv)

@tupui
Copy link
Author

tupui commented Feb 4, 2022

Right now it fails to register. Although I can see that CalendarNameConverter.populate was called and modified component. It then fails when calling the AttributeValueConverter.post_populate. And I am stuck for now. Can anyone help?

    def post_populate(self, component: Component, context: ContextDict):
        if self.is_required and not context[(self, "current_value_count")]:
>           raise ValueError("attribute %s is required but got no value" % self.ics_name)
E           ValueError: attribute NAME is required but got no value

@tupui
Copy link
Author

tupui commented Feb 10, 2022

@N-Coder @C4ptainCrunch could you have a look? 😃

stefanv added a commit to scientific-python/yaml2ics that referenced this pull request Feb 11, 2022
Also move timezone to root of yaml file

This will eventually be supported through ics-py/ics-py#312, but this is a quick workaround in the interim.
stefanv added a commit to scientific-python/yaml2ics that referenced this pull request Feb 11, 2022
Also move timezone to root of yaml file

This will eventually be supported through ics-py/ics-py#312, but this is a quick workaround in the interim.
stefanv added a commit to scientific-python/yaml2ics that referenced this pull request Feb 11, 2022
Also move timezone to root of yaml file

This will eventually be supported through ics-py/ics-py#312, but this is a quick workaround in the interim.
@C4ptainCrunch
Copy link
Member

C4ptainCrunch commented Feb 13, 2022

Hi @tupui 👋

Sorry for the delay. First, thanks a lot for taking the time to submit a PR, you rock 🤘

I did not have a lot of time to look at your PR yet but i do have a question: Why do you add a default value for the calendar name ? Shouldn't we just keep it null if we did not get any data (and not writing a NAME property when serializing it back)

UPDATE: I had a closer look and fiddled a bit with your code. My changes are available in 8761dfc if you want. I hope it unsticks you :)

@tupui
Copy link
Author

tupui commented Feb 14, 2022

Hi @tupui 👋

Sorry for the delay. First, thanks a lot for taking the time to submit a PR, you rock 🤘

No worries!

I did not have a lot of time to look at your PR yet but i do have a question: Why do you add a default value for the calendar name ? Shouldn't we just keep it null if we did not get any data (and not writing a NAME property when serializing it back)

I thought a calendar should be named, but no problem to make this completely optional and not present if not specified.

UPDATE: I had a closer look and fiddled a bit with your code. My changes are available in 8761dfc if you want. I hope it unsticks you :)

Oh thanks! I will apply your changes then 😃

@tupui tupui marked this pull request as ready for review February 14, 2022 08:10
@@ -62,4 +63,24 @@ def serialize(self, component: Component, output: Container, context: ContextDic
context["VTIMEZONES_AFTER"] = len(output)


class CalendarNameConverter(GenericConverter):
Copy link
Author

@tupui tupui Feb 14, 2022

Choose a reason for hiding this comment

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

I suppose we can then remove all changes to this file then? Actually this still required for X-WR-CALNAME rewrite to point to NAME.

Sorry I did not get the optional validator. I had trouble to understand how these were working together.

Copy link
Member

Choose a reason for hiding this comment

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

I suppose we can then remove all changes to this file then?

yes, please do so

Copy link
Author

@tupui tupui Mar 8, 2022

Choose a reason for hiding this comment

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

But then we don't have X-WR-CALNAME at all if we do this. Shouldn't we try to always add X-WR-CALNAME to have both fields?

To me what is missing here is just adding NAME to an extra field X-WR-CALNAME

Copy link
Author

@tupui tupui Mar 8, 2022

Choose a reason for hiding this comment

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

I would have this in CalendarNameConverter.populate

if item.name == "NAME":
    component.extra_params["X-WR-CALNAME"] = item.value
    return True

Copy link
Author

Choose a reason for hiding this comment

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

I can make the tests pass, but I am probably not doing it right, you're probably better of doing this yourself at this point 😄

Comment on lines 43 to 44
# FIXME: what behavior should we expect here?
# FIXME: In both cases, we need a test and we need to document it.
Copy link
Author

Choose a reason for hiding this comment

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

Since the RFC is only referring to NAME, I suppose one could say that if both fields are present, it should take NAME instead of X-WR-CALNAME. This is what I've done now.

@C4ptainCrunch
Copy link
Member

Great ! This looks in good shape to be merged 🎉

But first, could you :

  • Add yourself to AUTHORS.rst
  • Reference this change in CHANGELOG.rst
  • Add documentation about the feature (and insist on the NAME vs X-WR-CALNAME precedence as well as the behaviour when X-WR-CALNAME is in the input and we serialize the output with NAME)

@tupui
Copy link
Author

tupui commented Feb 16, 2022

Thanks @C4ptainCrunch! Where do you want me do document this? I am not sure as to where this would fit better.

Copy link
Member

@N-Coder N-Coder left a comment

Choose a reason for hiding this comment

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

Thanks a lot for making the effort to get your way around my Converter system and creating this PR - and sorry for taking my time to reply! Unfortunately, your code doesn't quite do what you intended, see my reviews. I see this as another argument for the Converter system being in desperate need of some refactoring and especially bigger simplifications. I guess the simplest way forward here would be using the following implementation for your propagate, adding handling of conflicting specifications later on once the Converter system makes that easier to do:

     def populate(self, component: Component, item: ContainerItem, context: ContextDict) -> bool:
            component.name = item.value
            return False

One thing that should be noted: with this PR, the library will now throw an exception when it sees multiple values for name, e.g. because they were localized, while before the multiple values could be stored to the extra properties just fine. This the second big "construction site", where the library is too strict in many cases. But I guess supporting one one name for now is okay.

src/ics/converter/types/calendar.py Show resolved Hide resolved
src/ics/converter/types/calendar.py Show resolved Hide resolved
src/ics/converter/types/calendar.py Show resolved Hide resolved
src/ics/icalendar.py Outdated Show resolved Hide resolved
Copy link
Author

@tupui tupui left a comment

Choose a reason for hiding this comment

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

Thanks for the review @N-Coder!

As I said bellow, I just came across the fact that we would need X-WR-CALNAME for practical reason.

@C4ptainCrunch @N-Coder Let me know what should be the behaviour. I personally would go with providing both fields (either another attribute or in extra) and NAME would take precedence over X-WR-CALNAME to follow a bit more the RFC.

src/ics/converter/types/calendar.py Show resolved Hide resolved
src/ics/icalendar.py Outdated Show resolved Hide resolved
@N-Coder N-Coder mentioned this pull request Mar 4, 2022
21 tasks
@N-Coder
Copy link
Member

N-Coder commented Mar 4, 2022

As I said bellow, I just came across the fact that we would need X-WR-CALNAME for practical reason.

I guess the best way to support this would be parsing both values into the same field name, and allowing the user to select a compatibility level for serialization (i.e. RFC5545, RFC7986, Google, Outlook, ...) that would then decide whether the value is written out as NAME or X-WR-CALNAME.

Unfortunately, we don't have that yet and it only adds to the complexity of refactoring the (de-)serialization system, so it will probably also take a while. In the meantime, I'd say the sanest thing to do is add a name field that only maps to NAME in the ics and let X-WR-CALNAME go entirely separate via the extras. Adding a comment to the name field about Google and X-WR-CALNAME and not doing any incomplete translation between both properties would then probably cause the least suprises for users.

@tupui
Copy link
Author

tupui commented Mar 8, 2022

Unfortunately, we don't have that yet and it only adds to the complexity of refactoring the (de-)serialization system, so it will probably also take a while. In the meantime, I'd say the sanest thing to do is add a name field that only maps to NAME in the ics and let X-WR-CALNAME go entirely separate via the extras. Adding a comment to the name field about Google and X-WR-CALNAME and not doing any incomplete translation between both properties would then probably cause the least suprises for users.

@N-Coder This is the current behaviour implemented in this PR no?

@N-Coder
Copy link
Member

N-Coder commented Mar 8, 2022

If you remove the added CalendarNameConverter by reverting the changes to src/ics/converter/types/calendar.py that should be it. Then we simply add the name field and letting its Converter be autogenerated without ever touching the X-WR-CALNAME.

src/ics/icalendar.py Outdated Show resolved Hide resolved
@C4ptainCrunch C4ptainCrunch added the merge-before-black We should merge this PR before running Black label Jul 4, 2022
@C4ptainCrunch
Copy link
Member

@tupui: are you still interested in working on this PR ? Could you have a look at the failing test ? :)

@tupui
Copy link
Author

tupui commented Jul 15, 2022

I am interested but as you've seen, you or @N-Coder would just be faster finishing this up vs discussing what I should do. I am afraid I don't have much time to focus on the architecture of the package to make this right.

@C4ptainCrunch C4ptainCrunch removed the merge-before-black We should merge this PR before running Black label Jul 22, 2022
@C4ptainCrunch
Copy link
Member

I'm closing this due to the previous comment. Anybody can reopen if they have time to work on this :)

@stefanv
Copy link

stefanv commented Dec 15, 2022

This felt like an important issue. We can work around it, as we've been doing, but calendars without names are much less useful for importing on eg Google Calendar. If the PR is closed, shouldn't an issue at least be opened?

@C4ptainCrunch
Copy link
Member

@stefanv You are totally right ! I opened #375 to track this :)

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.

Consider adding fields from RFC-7986
4 participants