Replies: 6 comments 16 replies
-
I have a similar issue with the current design of First, one issue is that you don't know the current working directory, for fpm it is currently always the project root, but for most other build systems it is usually the build directory, which might be somewhere. For fpm itself the working directory might also change at some point, so it is dangerous to rely on this. So far, the design of fpm, cargo, stack, ... seem to not consider passing command line arguments to an executable or invoking them with a runner by default, it is left as an exercise to the user. |
Beta Was this translation helpful? Give feedback.
-
I would suggest that hard-coding filenames and paths is generally bad practice in almost any scenario. The most common solution (and IMHO preferable) is to pass filenames/paths as command line arguments. As you noticed, we don't currently have a method of setting the default runner or command line options for a given executable (or test or example), but this would probably be the "right" way to do it. However, this doesn't answer the follow up question of, what is the current working directory when an executable is run? Right now it's the project root, but as @awvwgk pointed out, we haven't set that in stone, and so that probably shouldn't be relied on. Probably fpm should have some "variables" defined that can be used for such things. Off the top of my head I would suggest the following, but there are probably more:
|
Beta Was this translation helpful? Give feedback.
-
This is a very common case that we need to have a solution for and document how to do it. When I implemented the Rust prototype for So if you change your code to:
It should start working. |
Beta Was this translation helpful? Give feedback.
-
The accepted answer in rust is to base paths against the manifest directory: https://stackoverflow.com/questions/30003921/how-can-i-locate-resources-for-testing-with-cargo I couldn't find an answer to what were the design decisions behind Cargo. They seem to have some open issues around things such as "Provide access to project paths for tests". One case which might conflict with running the tests from the root directory is if the root-directory is read only. An example would be an fpm package located in a shared folder on a HPC system. In that case I should still be able to navigate to the fpm package and build it in a target directory under my own user path, e.g. |
Beta Was this translation helpful? Give feedback.
-
I like the idea for those who have to have a pre-defined path or who might have output files generated that if a directory called run/ exists that the Entries in the manifest file or a --rundir option on the Currently we are not depending on the CHDIR() extension (extremely common in Fortran implementations) or on POSIX interfaces but this could be easily implemented currently, as Perhaps instead of run/ tmp/ would be a good name. On second thought, I like run/ as it is clearly associated with running programs. but in general I do think if you use the |
Beta Was this translation helpful? Give feedback.
-
A related use case:no input files, but output files in the current directoryI thought I would describe a related use-case that is quite far along. In this case a bunch of example programs are intentionally very simple and just create an output file in the current directory (a graphics file -- gif, svg, PostScript, ...). When the examples are run as-is in So to simulate this you can set up something like
where each example program does a "write(LUN,*)'output for',LUN" where demo10 writes to LUN=10, etc.. So if I run that now I end up with something like "fort.10" and "fort.20" in the project root (names are compiler-specific and I argue non-standard but all compilers allow it, probably for historical reasons). That is ugly ( * and requires I have write access to the project home, nit 1I nit 2
So for this case having a run/ directory for the developer helps manage the mess while developing. So that is the related part and how the real caseIn the real case, I am really jdeveloping a library that is installed as a "normal" library in an HPC environment, and the user is unaware of
So it would be helpful to the developer to have a guaranteed/controlled point of execution and some environment variables So far As part of a solution for that I can pull my dependencies separately and look though them that way. I have been finding (using a slightly customized So But if I do not know the other packages residency and how to use them, not having a searchable repository with a standard way to access documentation (perhaps just a required link or flat text file a registered package would potentially be required to provide) I find it hard to use anything but my own packages, but that is a topic being discussed a bit already. So I thought I would share a production use of nit 3Maybe not a general issue, but I use a custom preprocessor for documentation purposes. Since I only edit these ".ff" files I have to Regarding this particular package, I wish I could share some of the high-level graphics (in Fortran) that use the base library but that is not possible. It is hard to believe that Fortran + a little machine code once dominated the world of graphics. In the wider world it is hard to find a Fortran-based graphics package now-adays that is available as Open Source. |
Beta Was this translation helpful? Give feedback.
-
I am assembling an fpm package with an example program that needs to load data from a file.
The file tree is something like:
The file "example.f90" contains the command
open(newunit=unit,file='dataset.dat',action="write")
, which obviously fails when I runfpm run example
. What would be good package practice in this case? Should I modify the example to read the line command line input for the file?Will in this case a command like
fpm run example ./example/dataset.dat
work?Beta Was this translation helpful? Give feedback.
All reactions