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

Extraction of the demo programs from the specs #662

Merged
merged 45 commits into from
Aug 1, 2022

Conversation

jvdp1
Copy link
Member

@jvdp1 jvdp1 commented Jun 19, 2022

This PR proposes to create small demo programs of the different features and to include them in the specs through the statement include in ford.
The main advantage is that the demo programs can be compiled and tested.

Using a small Fortran program, I extracted all demo programs from the specs, and generated small files for each of them. By doing that, I noticed that most of them still contained typos, missing statements, undeclared variables, ... I fixed most of them but still a few demo programs must be fixed.

So, the main advantage of this approach is that all demo programs that will be shown in the specs can be compiled (an issue that has been often mentioned).

Questions:

  • What do you think about this idea?
  • Is the structure OK (test/examples)?
  • Currently the demo programs are added to the tests. Is this ok (I don't think so)? what should it be done?

TO DO:

  • Fix remaining programs (currently commented in the CMakefile)
  • Check the generated website by ford
  • Add support of the demo programs to fpm

@jvdp1 jvdp1 requested review from a team, awvwgk and gareth-nx June 19, 2022 18:49
@urbanjost
Copy link

The intrinsics descriptions follow a simple pattern (example program starts with "program demo_$TOPIC" and ends with "end demo_$TOPIC") for a similar purpose (as well as do almost all my own repositories). I am interested in what develops and how it is implemented, as I have found that type of approach useful. fpm(1) is still lacking any supported documentation approach other than that ford(1) seems to be used frequently. Wondering if something might emerge that could be used by all the projects, like an option for ford(1) that could automatically generate man-pages as well as extract demo pages from source code and place them in the fpm example page if certain conventions are used. That is, place the documentation for a routine in the source code, and when ford(1) is run (or some simpler fpm-supported preprocessor) you would get the ford documentation, man-pages as real man-pages and as separate (HTML, LaTex, markdown, ...?) documents and any demo program in the documentation would be extracted and show in the ford(1) listing and in the example/ directory of fpm?

So if you follow some ford-like convention that has a man-page style using simple plain text in your source code

  • your code is well documented
  • demo programs are automatically generated and easily testable via fpm
  • the documentation for a user guide is automatically generated
  • and at least for Unix/GNU-Linux/WLS users you would have a CLI version of the procedures

CMakeLists.txt Outdated
@@ -68,6 +68,8 @@ endif()

add_subdirectory(src)

add_subdirectory(test)
Copy link
Member

Choose a reason for hiding this comment

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

Should we put this under just example. Fpm can pick up demo programs and run them as well, means we have to deploy this directory with fpm (maybe for a follow-up PR).

@jvdp1 jvdp1 changed the title Extraction of the demo programs from the specs WIP: Extraction of the demo programs from the specs Jun 21, 2022
@14NGiestas 14NGiestas linked an issue Jun 21, 2022 that may be closed by this pull request
@14NGiestas
Copy link
Member

  • Should all the examples be added to the CMake tests? Or is it possible to run them without including them in the tests, as with fpm?

It seems it is possible to create a custom target (let's say add_custom_target(examples ...), so you can run the tests and the examples in separate, with a make examples.

I don't know if it's applicable to stdlib.

  • Is the current structure (two different test directories (./test/ and ./src/tests)) fine?

I guess moving it into ./src/examples/ would be less surprising than two test and tests folders around the codebase.

@jvdp1
Copy link
Member Author

jvdp1 commented Jul 11, 2022

  • Should all the examples be added to the CMake tests? Or is it possible to run them without including them in the tests, as with fpm?

It seems it is possible to create a custom target (let's say add_custom_target(examples ...), so you can run the tests and the examples in separate, with a make examples.

I am not aware of that option. I will look at it. Thanks.

I don't know if it's applicable to stdlib.

  • Is the current structure (two different test directories (./test/ and ./src/tests)) fine?

I guess moving it into ./src/examples/ would be less surprising than two test and tests folders around the codebase.

Indeed, .src/examples/ makes more sense.

@awvwgk
Copy link
Member

awvwgk commented Jul 11, 2022

It seems it is possible to create a custom target (let's say add_custom_target(examples ...), so you can run the tests and the examples in separate, with a make examples.

I am not aware of that option. I will look at it. Thanks.

Let's not create a custom target for this purpose. Instead prefix the test names and use ctest -R '^example/' to select tests based on a regular expression.

@jvdp1
Copy link
Member Author

jvdp1 commented Jul 14, 2022

It seems it is possible to create a custom target (let's say add_custom_target(examples ...), so you can run the tests and the examples in separate, with a make examples.

I am not aware of that option. I will look at it. Thanks.

Let's not create a custom target for this purpose. Instead prefix the test names and use ctest -R '^example/' to select tests based on a regular expression.

@awvwgk This sounds a good idea. But I am not sure how to organize that. Any hints?

@jvdp1
Copy link
Member Author

jvdp1 commented Jul 22, 2022

@fortran-lang/stdlib This PR is ready for reviewing and merging.

@jvdp1 jvdp1 added the reviewers needed This patch requires extra eyes label Jul 22, 2022
Copy link
Member

@14NGiestas 14NGiestas left a comment

Choose a reason for hiding this comment

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

LGTM I've tested with both cmake and fpm (in which seems there is no way to run all of them at once AFAIK you need to provide a name).
Maybe it is worth mentioning in the README how to run only the examples.

@jvdp1
Copy link
Member Author

jvdp1 commented Jul 25, 2022

LGTM I've tested with both cmake and fpm (in which seems there is no way to run all of them at once AFAIK you need to provide a name). Maybe it is worth mentioning in the README how to run only the examples.

Thank you. I just added instructions to run the examples with fpm.

@jvdp1
Copy link
Member Author

jvdp1 commented Jul 31, 2022

@14NGiestas @awvwgk I moved the directory src/examples to example, as discussed during the last Fortran Monthly call.
I believe this is ready to be merged.

Copy link
Member

@14NGiestas 14NGiestas left a comment

Choose a reason for hiding this comment

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

LGTM. One step closer to fpm-ization of fortran & stdlib.

@jvdp1
Copy link
Member Author

jvdp1 commented Aug 1, 2022

Thank you for the review. I will merge this PR.

@jvdp1 jvdp1 merged commit c6b54e1 into fortran-lang:master Aug 1, 2022
@jvdp1 jvdp1 deleted the extract_demo branch August 1, 2022 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reviewers needed This patch requires extra eyes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Testing the example codes in the documentation
5 participants