esm-tools / esm_master

GNU General Public License v2.0
2 stars 2 forks source link

fixed the >>>cp: are the same file<<< error #21

Closed denizural closed 3 years ago

denizural commented 3 years ago

As Laurent Oziel mentioned during the workshop today, FESOM compilation (esm_master comp-fesom-1.4) ends with an error like subprocess.CalledProcessError: Command '['cp', 'fesom-2.0/bin/fesom.x', 'fesom-2.0/bin']' returned non-zero exit status 1.

Although this is not a real error, subprocess.run() raises an exception since the shell return status ($?) is not 0. The reason is FESOM executables are hard linked and they share the same inode numbers. Therefore, copying these files on each other causes non-zero return.

I solved this issue by wrapping the subprocess.run() inside a try-except block and simply ignore the CalledProcessError exception.

Now the compilation completes without any errors but only the message:

cp: ‘fesom-1.4/bin/fesom’ and ‘fesom-1.4/bin/fesom’ are the same file

This can also be avoided (if you want) by adding 2>/dev/null to the copy command in task.py.

denizural commented 3 years ago

I made another commit after the discussion. I checked the compilation using FESOM 1.4.

Here are what I did

1) additon of pathlib

2) More meaningful variable names for readability:

3) More "Pythonic" code:

denizural commented 3 years ago

I think the Pathlib stuff will need to be a general overhaul at some point. We have another big overhaul with the logging changes @seb-wahl wanted...

Only two small thing: I'd remove the line continuations (something we can automatically solve if we all agree to a code-formatter), and maybe the should_copy_files can be defined in one go.

Yes, but quite recently I switched to the PEP 8 standards and obey the Benevolent Dictator For Life: https://www.python.org/dev/peps/pep-0008/#maximum-line-length

pgierz commented 3 years ago

Here's an example of what I had in mind regarding code formatting: https://black.readthedocs.io/en/stable/index.html

denizural commented 3 years ago

Here's an example of what I had in mind regarding code formatting: https://black.readthedocs.io/en/stable/index.html

Black formatting looks really cool!

pgierz commented 3 years ago

@denizural, if you want, we can add it to automatically: here's how to put it into automatic testing for code style compliance. We could add that to all the esm sub packages.

https://github.com/esm-tools/esm_version_checker/blob/master/.github/workflows/python-package.yml

mandresm commented 3 years ago

I fixed an issue with recompilation of fesom. Now it should all work. I also passed again black to make sure my edits were well formatted.