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

Fix Windows CI builds #361

Merged
merged 23 commits into from Jun 5, 2021
Merged

Conversation

duckontheweb
Copy link
Contributor

@duckontheweb duckontheweb commented May 25, 2021

Related Issues:

Description:

  • Fix Windows CI jobs
    Uses shell: bash to ensure we're running a bash shell, even on Windows.
  • Fix dependency caching in CI jobs
    The cache keys are now specific to Python version and OS and point to the correct cache directories for each OS.
  • Create temp directories in current working directory
    In the GitHub Actions Windows runner the default TMPDIR directory is on a different drive (C:\\) than the code and test data files (D:\\). This was causing failures in os.path.relpath on Windows.
  • Separates lint and test jobs
    The lint and type checking jobs only need to run once per Python version since they are not platform-specific.
  • Use safe joins and parsing for all paths
    In pystac.utils renames _urlparse -> safe_urlparse and _join -> join_path_or_url and uses these functions throughout the codebase and tests to ensure we are joining paths properly. There were a number of places where os.path.join was being used to join URL paths, which caused failures on Windows. Also changes the signature of join_path_or_url to take a JoinType enum as the first argument to make the usage more clear.
  • Preserves the case of the drive in Windows paths.
    When using functions like pystac.utils.make_absolute_href, the drive letter was being converted to lowercase. The safe_urlparse function now preserves the original casing from the start path (see the changes to the tests in 8e9455 for an example)
  • Uses explicit utf-8 encoding for all file I/O operations
    The default encoding on Windows is not necessarily UTF-8, which was causing decoding errors when trying to read test data files. This uses encoding="utf-8" for all file read/write operations to avoid conflicts
  • Creates separate functions for handling URL v. path cases in make_absolute_href and make_relative_href
    When debugging the Windows issues, it was pretty difficult to reason through how a URL would be handled in those functions vs. a local path. This PR creates distinct internal functions to handle each case. The result is some redundancy in the code, but I think the trade-off in clarity is worth it.

UPDATE 2021-06-03

  • Adds setup.py to linting and auto-formatting
  • Moves version config from setup.py to setup.cfg. This means we no longer have to use the deprecated imp module.

PR Checklist:

  • Code is formatted (run scripts/format)
  • Tests pass (run scripts/test) (see comments above)
  • This PR maintains or improves overall codebase code coverage.
  • Changes are added to the CHANGELOG. See the docs for information about adding to the changelog.

@codecov-commenter
Copy link

codecov-commenter commented May 25, 2021

Codecov Report

Merging #361 (d23be0a) into main (4658999) will increase coverage by 0.04%.
The diff coverage is 97.77%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #361      +/-   ##
==========================================
+ Coverage   89.64%   89.69%   +0.04%     
==========================================
  Files          39       39              
  Lines        5169     5209      +40     
==========================================
+ Hits         4634     4672      +38     
- Misses        535      537       +2     
Impacted Files Coverage Δ
pystac/utils.py 96.12% <96.72%> (-0.91%) ⬇️
pystac/layout.py 92.93% <100.00%> (+0.49%) ⬆️
pystac/stac_io.py 72.46% <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 4658999...d23be0a. Read the comment docs.

@duckontheweb duckontheweb changed the title [WIP] Fix Windows CI builds Fix Windows CI builds May 25, 2021
@duckontheweb
Copy link
Contributor Author

There are still a number of path-related failures on Windows. I opened #362 to track fixes to those rather than try to fix them as part of this PR.

Actually, I think I have some fixes to most of these. I'll update the PR shortly.

- OS-specific dependency caching in GitHub Actions
- Separate test requirements for faster builds
- Separate lint and test CI jobs
These tests have test cases which are specific to posix
paths and will cause failures when run on Windows.
The default encoding on Windows is not necessarily utf-8,
which can lead to problems when reading/writing across
platforms. This explicitly uses utf-8 for all file encoding &
decoding.
The default temp directory in GitHub Actions Windows
runners is on the C: drive, but the test code and data
files are on the D: drive. This was leading to CI failures
due to an error in ntpath when trying to determine
relative paths.
This makes the utils for safely parsing and joining URLs "public"
and uses them throughout the code base and tests to ensure
that we don't use platform-specific separators when it's not
appropriate (i.e. for URLs).
Fixes some issues where relative and absolute hrefs were
not being constructed correctly for URLs on Windows. Also
creates separate internal functions for handling these 2
cases to make the logic more clear.
…clean

# Conflicts:
#	requirements-dev.txt
#	scripts/test
#	tests/extensions/test_label.py
#	tests/test_catalog.py
#	tests/test_layout.py
#	tests/test_utils.py
#	tests/test_writing.py
@duckontheweb duckontheweb marked this pull request as ready for review June 1, 2021 17:38
@duckontheweb
Copy link
Contributor Author

@volaya I would be interested in your review of this since I think it addresses some of the issue you were finding in #271 .

@l0b0 I would also be interested in your review since you've been thinking about pre-commit hooks and CI in #366 .

.github/workflows/continuous-integration.yml Show resolved Hide resolved
scripts/lint Outdated Show resolved Hide resolved
scripts/lint Show resolved Hide resolved
.github/workflows/continuous-integration.yml Outdated Show resolved Hide resolved
.github/workflows/continuous-integration.yml Show resolved Hide resolved
@duckontheweb duckontheweb mentioned this pull request Jun 3, 2021
4 tasks
l0b0 added a commit to l0b0/pystac that referenced this pull request Jun 3, 2021
l0b0 added a commit to l0b0/pystac that referenced this pull request Jun 3, 2021
pystac/utils.py Show resolved Hide resolved
pystac/utils.py Outdated Show resolved Hide resolved
pystac/utils.py Outdated Show resolved Hide resolved
pystac/utils.py Show resolved Hide resolved
pystac/utils.py Outdated Show resolved Hide resolved
pystac/utils.py Outdated Show resolved Hide resolved
setup.cfg Outdated Show resolved Hide resolved
Copy link
Member

@lossyrob lossyrob left a comment

Choose a reason for hiding this comment

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

LGTM. Added a couple of test cases I was curios about in duckontheweb#1, these passed.

tests/data-files/get_examples.py Outdated Show resolved Hide resolved
pystac/utils.py Outdated Show resolved Hide resolved
tests/utils/__init__.py Outdated Show resolved Hide resolved
@duckontheweb
Copy link
Contributor Author

@l0b0 I think I've addressed all of your comments. Let me know what you think.

@l0b0
Copy link
Contributor

l0b0 commented Jun 4, 2021

@l0b0 I think I've addressed all of your comments. Let me know what you think.

LGTM, cheers!

@duckontheweb duckontheweb merged commit 50c6ee8 into stac-utils:main Jun 5, 2021
@duckontheweb duckontheweb deleted the windows-ci-fixes branch June 9, 2021 14:44
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.

None yet

4 participants