Skip to content

Create a module for the frontend of the endpoint function#33

Merged
nabobalis merged 16 commits intoHelioviewer-Project:mainfrom
akash5100:init_facade
Jul 7, 2022
Merged

Create a module for the frontend of the endpoint function#33
nabobalis merged 16 commits intoHelioviewer-Project:mainfrom
akash5100:init_facade

Conversation

@akash5100
Copy link
Collaborator

@akash5100 akash5100 commented Jul 1, 2022

Fixes #27

@akash5100 akash5100 self-assigned this Jul 1, 2022
@akash5100 akash5100 changed the title initialize facade.py Create a module for the frontend of the endpoint function Jul 1, 2022
@akash5100 akash5100 requested a review from nabobalis July 1, 2022 11:26
@nabobalis nabobalis marked this pull request as draft July 1, 2022 14:54
Co-authored-by: Nabil Freij <nabil.freij@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Jul 2, 2022

Codecov Report

Merging #33 (acaa047) into main (2953bb3) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main       #33   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            4         6    +2     
  Lines           59        79   +20     
=========================================
+ Hits            59        79   +20     
Impacted Files Coverage Δ
hvpy/api_groups/jpeg2000/get_jp2_image.py 100.00% <ø> (ø)
hvpy/facade.py 100.00% <100.00%> (ø)
hvpy/utils.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2953bb3...acaa047. Read the comment docs.

@akash5100 akash5100 requested a review from nabobalis July 2, 2022 16:41
hvpy/facade.py Outdated
+ "\n".join(input_class.__doc__.split("\n")[2:])
+ "\n".join(func.__doc__.split("\n")[2:])
)
return func
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

current code result:

    Retrieve a JP2000 image from the helioviewer.org API.

    Attributes
    ----------
    date : datetime.datetime
        Desired date/time of the JP2 image.
    sourceId : int
        Unique image datasource identifier.
    jpip : bool, optional
        Returns a JPIP URI instead of the binary data of the image if set to `True`, defaults to `False`.
    json : bool, optional
        Returns the JSON if set to `True`, defaults to `False`.

    References
    ----------
    * `<https://api.helioviewer.org/docs/v2/api/api_groups/jpeg2000.html#getjp2image>`__
    
    Example:

        >>> getJP2Image(date=datetime(2019,1,1), sourceId=1, jpip=True)
        'jpip://helioviewer.org:8090/EIT/2013/08/07/195/2013_08_07__01_13_50_146__SOHO_EIT_EIT_195.jp2'

Copy link
Collaborator

@dgarciabriseno dgarciabriseno Jul 5, 2022

Choose a reason for hiding this comment

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

This is what I would call arcane magic code. Difficult to read. It enforces a strict code style on docstrings, but no one would know the style enforcement exists unless they knew this code exists and read it first.

As I understand it, it reads something like:
Start with a new line
Take the 2nd & 3rd lines from the wrapped function’s doc string
Insert the data from the 3rd line on from the input class’s doctoring
Take the remaining lines from the wrapped function’s docstring.

This will be error prone if we forget to follow these string line numbers while writing comments. It's too strict.

Don't split by new line characters, we can't easily enforce that a docstring is only one line long. Put markers in the comment instead.

For example, for getJP2Image add something like this

"""
    Retrieve a JP2000 image from the helioviewer.org API.

    {{Insert Shared Docstring}}

    Example:
        >>> getJP2Image(date=datetime(2019,1,1), sourceId=1, jpip=True)
        'jpip://helioviewer.org:8090/EIT/2013/08/07/195/2013_08_07__01_13_50_146__SOHO_EIT_EIT_195.jp2'
    """

And in getJP2ImageInputParameters add something like

"""
Words words words about input parameters

{{Shared}}
Attributes
-----
...

References
----
...
{{End Shared}}

Then _copy_docstring can extract the text between {{Shared}} and {{End Shared}} and insert into the docstring at {{Insert Shared Docstring}}. This gives us more control about the docstrings being shared, and for anyone writing docstrings, they will see these markers in other docstrings and will know there's some post processing going on to adhere to.

And it doesn't force us to stick to specific line numbers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great idea, easy, clean. But this will affect documentation for <endpoint>InputParameters,
See the docs below that I tried to build using this.

Screenshot from 2022-07-05 19-56-07

Copy link
Collaborator

Choose a reason for hiding this comment

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

I suppose we could make another decorator that clears these out. Or instead of {{Shared}} we can use other less intrusive markers.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this is why the sunpy version is more complex.

We could just copy that function wholesale and hope that is enough to get this working?

Copy link
Member

Choose a reason for hiding this comment

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

Ah no, the sunpy function doesnt do what I thought it did. Ignore me.

Copy link
Collaborator Author

@akash5100 akash5100 Jul 6, 2022

Choose a reason for hiding this comment

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

I suppose we could make another decorator that clears these out.

If we do this, the docstring of the <endpoint>InputParameters class will get updated at runtime, and we will lose {{Shared}} and {{End Shared}} and the other decorator (_copy_docstring) will not be able to find them.

Copy link
Member

Choose a reason for hiding this comment

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

I pushed a change that I think solves the problem expect one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Which problem is left?

Copy link
Member

Choose a reason for hiding this comment

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

hvpy/facade.py Outdated
+ "\n".join(input_class.__doc__.split("\n")[2:])
+ "\n".join(func.__doc__.split("\n")[2:])
)
return func
Copy link
Collaborator

@dgarciabriseno dgarciabriseno Jul 5, 2022

Choose a reason for hiding this comment

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

This is what I would call arcane magic code. Difficult to read. It enforces a strict code style on docstrings, but no one would know the style enforcement exists unless they knew this code exists and read it first.

As I understand it, it reads something like:
Start with a new line
Take the 2nd & 3rd lines from the wrapped function’s doc string
Insert the data from the 3rd line on from the input class’s doctoring
Take the remaining lines from the wrapped function’s docstring.

This will be error prone if we forget to follow these string line numbers while writing comments. It's too strict.

Don't split by new line characters, we can't easily enforce that a docstring is only one line long. Put markers in the comment instead.

For example, for getJP2Image add something like this

"""
    Retrieve a JP2000 image from the helioviewer.org API.

    {{Insert Shared Docstring}}

    Example:
        >>> getJP2Image(date=datetime(2019,1,1), sourceId=1, jpip=True)
        'jpip://helioviewer.org:8090/EIT/2013/08/07/195/2013_08_07__01_13_50_146__SOHO_EIT_EIT_195.jp2'
    """

And in getJP2ImageInputParameters add something like

"""
Words words words about input parameters

{{Shared}}
Attributes
-----
...

References
----
...
{{End Shared}}

Then _copy_docstring can extract the text between {{Shared}} and {{End Shared}} and insert into the docstring at {{Insert Shared Docstring}}. This gives us more control about the docstrings being shared, and for anyone writing docstrings, they will see these markers in other docstrings and will know there's some post processing going on to adhere to.

And it doesn't force us to stick to specific line numbers.

akash5100 and others added 3 commits July 5, 2022 21:05
Co-authored-by: Nabil Freij <nabil.freij@gmail.com>
@nabobalis nabobalis marked this pull request as ready for review July 7, 2022 05:07
@nabobalis nabobalis requested a review from dgarciabriseno July 7, 2022 17:06
@nabobalis nabobalis merged commit d83d2ce into Helioviewer-Project:main Jul 7, 2022
@akash5100 akash5100 deleted the init_facade branch July 8, 2022 10:31
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.

Create user facing function for getJP2Image

4 participants