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

Add tests for .py utilities #835

Merged
merged 19 commits into from
Nov 13, 2023
Merged

Conversation

plimkilde
Copy link
Contributor

Checklist

  • Used a personal fork of the feedstock to propose changes
  • Bumped the build number (if the version is unchanged)
  • Reset the build number to 0 (if the version changed)
  • Re-rendered with the latest conda-smithy (Use the phrase @conda-forge-admin, please rerender in a comment in this PR for automated rerendering)
  • Ensured the license file is being packaged.

This adds tests for the Python-based GDAL utilities (gdal_calc.py, gdal_fillnodata.py etc.), see #834.

Interestingly, local testing revealed spotty support for both --help and --version.

@conda-forge-webservices
Copy link
Contributor

Hi! This is the friendly automated conda-forge-linting service.

I just wanted to let you know that I linted all conda-recipes in your PR (recipe) and found it was in an excellent condition.

@xylar
Copy link
Contributor

xylar commented Nov 7, 2023

@plimkilde, run_test.sh and run_test.bat get run when building libgdal, not gdal so the python tools aren't available. I think you want to add these tests directly in meta.yaml here:
https://github.com/plimkilde/gdal-feedstock/blob/py-utility-tests/recipe/meta.yaml#L285-L286

      commands:
        - python run_test.py
        - rgb2pct.py --help
        - pct2rgb.py --help
        - gdalattachpct.py --help
...

This should work for all architectures.

This reverts commit f60d0ef.
recipe/meta.yaml Outdated Show resolved Hide resolved
recipe/meta.yaml Outdated
- gdal_merge.py --version
- gdal2tiles.py --help
- gdal2xyz.py --help
- gdal_retile.py --version
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, dear. Seeing:

gdal_retile.py --version
GDAL 3.7.3, released 2023/10/30

but then it seems like it's exiting with an error code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep 😩

Copy link
Contributor

Choose a reason for hiding this comment

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

will be addressed per OSGeo/gdal#8676

rouault added a commit to rouault/gdal that referenced this pull request Nov 7, 2023
…layer_algebra return 0 error code when invoked with --version switch

Fixes conda-forge/gdal-feedstock#835 (review)
rouault added a commit to rouault/gdal that referenced this pull request Nov 7, 2023
…layer_algebra return 0 error code when invoked with --version switch

Fixes conda-forge/gdal-feedstock#835 (review)
rouault added a commit to OSGeo/gdal that referenced this pull request Nov 8, 2023
…layer_algebra return 0 error code when invoked with --version switch

Fixes conda-forge/gdal-feedstock#835 (review)
@xylar
Copy link
Contributor

xylar commented Nov 8, 2023

Finally passing for Linux. Let's see what happens with OSX and Windows.

@xylar
Copy link
Contributor

xylar commented Nov 8, 2023

Aaargh! Windows testing is just saying:

Tests failed for gdal-3.7.3-py312hb5f3cee_3.conda - moving package to D:\bld\broken

but not telling us why. Anyone from @conda-forge/gdal have an suggestions for how to get more helpful output here? I really don't speak Windows.

@plimkilde
Copy link
Contributor Author

Aaargh! Windows testing is just saying:

Tests failed for gdal-3.7.3-py312hb5f3cee_3.conda - moving package to D:\bld\broken

but not telling us why. Anyone from @conda-forge/gdal have an suggestions for how to get more helpful output here? I really don't speak Windows.

Hm, I don't see any of the Windows builds successfully running to completion. I'm wondering if we are checking for existence in the correct directory?

@xylar
Copy link
Contributor

xylar commented Nov 8, 2023

I'm wondering if we are checking for existence in the correct directory?

I believe so.

recipe/meta.yaml Outdated
- rgb2pct.py --help
- pct2rgb.py --help
# Neither --help nor --version seem to work
# - if not exist %PREFIX%\\Library\\bin\\gdalattachpct.py exit 1 # [win]
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe try this next:

Suggested change
# - if not exist %PREFIX%\\Library\\bin\\gdalattachpct.py exit 1 # [win]
# - if not exist %LIBRARY_BIN%\\gdalattachpct.py exit 1 # [win]

Copy link
Contributor

Choose a reason for hiding this comment

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

But I believe that's the same.

@zklaus
Copy link

zklaus commented Nov 8, 2023

If we need more info about how things are failing, we could put the tests in their own scripts, say test_python_scripts.{sh,bat} and add set -xe and @echo on, respectively.

@xylar
Copy link
Contributor

xylar commented Nov 8, 2023

@zklaus, that's a great suggestion.

@gillins
Copy link
Contributor

gillins commented Nov 8, 2023

I think on Windows, you'll need to run:

%PYTHON% %LIBRARY_BIN%\rgb2pct.py --help  # [win]

etc. It's probably popped up a dialog box wanting to know how to execute a .py file and that's why the build if failing (?). Windows doesn't have the shebang thing so needs to be told how to execute the file....

@plimkilde
Copy link
Contributor Author

I think on Windows, you'll need to run:

%PYTHON% %LIBRARY_BIN%\rgb2pct.py --help  # [win]

etc. It's probably popped up a dialog box wanting to know how to execute a .py file and that's why the build if failing (?). Windows doesn't have the shebang thing so needs to be told how to execute the file....

Trouble is, then we're not testing the documented commands 😕

@gillins
Copy link
Contributor

gillins commented Nov 8, 2023

Trouble is, then we're not testing the documented commands 😕

What's documented has never worked on Windows as-is. This has been a source of much confusion when I've been helping Windows users. I've always had to tell people to prefix everything with python and then hardcode the path to the script (which then breaks when they change envs).
Entry points would be the way forward for cross platform (conda can generate these if asked: https://docs.conda.io/projects/conda-build/en/stable/resources/define-metadata.html#python-entry-points). But then we'd have to lose the extension, which again, wouldn't match the docs. Argghh.

@plimkilde
Copy link
Contributor Author

plimkilde commented Nov 8, 2023

Trouble is, then we're not testing the documented commands 😕

What's documented has never worked on Windows as-is. This has been a source of much confusion when I've been helping Windows users. I've always had to tell people to prefix everything with python and then hardcode the path to the script (which then breaks when they change envs). Entry points would be the way forward for cross platform (conda can generate these if asked: https://docs.conda.io/projects/conda-build/en/stable/resources/define-metadata.html#python-entry-points). But then we'd have to lose the extension, which again, wouldn't match the docs. Argghh.

I don't feel inclined to write a passing test for something that doesn't work, so maybe we should limit the scope of this PR to simply adding tests of what works (i.e. Unix), then enabling Windows testing in a later PR when a solution is ready.

@conda-forge-webservices
Copy link
Contributor

Hi! This is the friendly automated conda-forge-linting service.

I wanted to let you know that I linted all conda-recipes in your PR (recipe) and found some lint.

Here's what I've got...

For recipe:

  • Selectors are suggested to take a <two spaces>#<one space>[<expression>] form. See lines [323]

@plimkilde
Copy link
Contributor Author

Hm, it seems to pass on Windows with existence checks disabled. As suggested above, I've tried to move them into a separate .bat file to have more details.

recipe/meta.yaml Outdated Show resolved Hide resolved
Co-authored-by: Xylar Asay-Davis <[email protected]>
@conda-forge-webservices
Copy link
Contributor

Hi! This is the friendly automated conda-forge-linting service.

I just wanted to let you know that I linted all conda-recipes in your PR (recipe) and found it was in an excellent condition.

REM script checks only for the existence of the .py files below.

echo Test existence of gdalattachpct.py...
if not exist %PREFIX%\\Library\\bin\\gdalattachpct.py exit 1
Copy link
Contributor

Choose a reason for hiding this comment

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

We could tidy up with %LIBRARY_BIN% but let's see if this works first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That does not seem to make any difference

Copy link
Contributor

Choose a reason for hiding this comment

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

As I said, it's just tidier. If the file isn't one place, it isn't the other because they point the same place. If the test is failing, the file presumably really isn't installed there.

@echo on

echo Test existence of gdalattachpct.py...
if not exist %LIBRARY_BIN%\\gdalattachpct.py exit 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Single back slash should do it. You just need double in the yaml.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, though it should work in practice in most cases.

@plimkilde
Copy link
Contributor Author

It's passing! I believe this is about the best that can be done without changes to GDAL itself, so I'm marking this PR as ready.

@plimkilde plimkilde marked this pull request as ready for review November 9, 2023 13:14
@@ -0,0 +1,21 @@
@echo off
REM As a workaround for GDAL apps unexpectedly returning error codes, this
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: GDAL 3.8.0RC2 has been issued with the fix for that issue

Copy link
Contributor

Choose a reason for hiding this comment

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

@rouault, is there also a plan to move from scripts to entry points to better support Windows?

Copy link
Contributor

Choose a reason for hiding this comment

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

@xylar I'm waiting for feedback. See #834 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, sorry, I had noticed that comment and just forgot. Thanks!

Copy link
Contributor

@xylar xylar left a comment

Choose a reason for hiding this comment

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

@plimkilde, thanks for persisting through this one! Nice work!

@gillins gillins merged commit 6cf10f7 into conda-forge:main Nov 13, 2023
7 checks passed
@gillins
Copy link
Contributor

gillins commented Nov 13, 2023

Thanks @plimkilde !

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.

5 participants