-
Notifications
You must be signed in to change notification settings - Fork 9
Add multiplatform testing builds #438
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
Draft
Zeitsperre
wants to merge
26
commits into
master
Choose a base branch
from
add-platforms
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
0b24d87
add other platforms
Zeitsperre 7725a16
add a preload_test_data step for Windows builds
Zeitsperre f69ec05
do not build on Windows
Zeitsperre de6a3c2
add Windows PyPI/tox build
Zeitsperre e2a00d2
try using str instead of as_posix
Zeitsperre e14a48f
Merge branch 'master' into add-platforms
Zeitsperre e89ac9a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0202fb4
Merge branch 'master' into add-platforms
Zeitsperre 8c84a87
Merge branch 'master' into add-platforms
Zeitsperre cae0055
Merge branch 'master' into add-platforms
Zeitsperre 20d86f0
testing data adjustments
Zeitsperre accbfa4
add missing Path
Zeitsperre 15b7e4d
adjust teardown
Zeitsperre 0605351
adjustments
Zeitsperre ee007de
update registry mechanisms
Zeitsperre 6ff281c
address warnings from xarray
Zeitsperre d75a7e2
add caching for Windows builds
Zeitsperre 22c23a1
filepath fixes for multiplatform
Zeitsperre c5d6310
fix typo
Zeitsperre b87cfcb
set env later
Zeitsperre ad38b85
use bash
Zeitsperre e47919a
small fixes
Zeitsperre 6fd1ed6
fix cwd-dependent test
Zeitsperre 52aac5e
Apply suggestions from code review
Zeitsperre 15f8b85
address review comments
Zeitsperre dcb18d8
Merge remote-tracking branch 'refs/remotes/origin/add-platforms' into…
Zeitsperre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import glob | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
| import xarray as xr | ||
| from loguru import logger | ||
|
|
@@ -62,14 +63,15 @@ def _get_base_dirs_dict(): | |
| def _is_ds_id(dset): | ||
| return dset.count(".") > 1 | ||
|
|
||
| def _deduce_project(self, dset): | ||
| def _deduce_project(self, dset) -> str | None: | ||
| if isinstance(dset, str): | ||
| if dset.startswith("/"): | ||
| if os.path.isabs(dset): | ||
| # by default this returns c3s-cmip6 not cmip6 (as they have the same base_dir) | ||
| base_dirs_dict = self._get_base_dirs_dict() | ||
| for project, base_dir in base_dirs_dict.items(): | ||
| if dset.startswith(base_dir) and CONFIG[f"project:{project}"].get("is_default_for_path") is True: | ||
| return project | ||
| return None | ||
|
|
||
| elif self._is_ds_id(dset): | ||
| return dset.split(".")[0].lower() | ||
|
|
@@ -78,7 +80,8 @@ def _deduce_project(self, dset): | |
| elif dset.endswith(".nc") or os.path.isfile(dset): | ||
| dset = xr.open_dataset(dset, decode_times=xr.coders.CFDatetimeCoder(use_cftime=True)) | ||
| return get_project_from_ds(dset) | ||
|
|
||
| else: | ||
| return None | ||
| else: | ||
| raise InvalidProject(f"The format of {dset} is not known and the project name could not be found.") | ||
|
|
||
|
|
@@ -104,7 +107,7 @@ def _parse(self, force): | |
| self._base_dir = get_project_base_dir(self._project) | ||
|
|
||
| # if a file, group of files or directory to files - find files | ||
| if dset.startswith("/") or dset.endswith(".nc"): | ||
| if Path(dset).is_absolute() or dset.endswith(".nc"): | ||
| # if instance of FileMapper | ||
| if isinstance(self.dset, FileMapper): | ||
| self._files = self.dset.file_paths | ||
|
|
@@ -117,19 +120,19 @@ def _parse(self, force): | |
| self._files.append(dset) | ||
|
|
||
| # remove file extension to create data_path | ||
| self._data_path = "/".join(dset.split("/")[:-1]) | ||
| self._data_path = os.path.dirname(dset) | ||
|
|
||
| # if base_dir identified, insert into data_path | ||
| if self._base_dir: | ||
| self._ds_id = ".".join(self._data_path.replace(self._base_dir, self._project).strip("/").split("/")) | ||
| relative_path = os.path.relpath(self._data_path, self._base_dir) | ||
| self._ds_id = ".".join(relative_path.split(os.sep)) | ||
|
Comment on lines
126
to
+128
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot Can you propose a fix here? |
||
|
|
||
| # test if dataset id | ||
| elif self._is_ds_id(dset): | ||
| self._ds_id = dset | ||
|
|
||
| mappings = CONFIG.get(f"project:{self.project}", {}).get("fixed_path_mappings", {}) | ||
|
|
||
| # If the dataset uses a fixed path mapping (from the config file) then use it | ||
| if self._ds_id in mappings: | ||
| data_path = mappings[self._ds_id] | ||
| self._data_path = os.path.join(self._base_dir, data_path) | ||
|
|
@@ -139,7 +142,7 @@ def _parse(self, force): | |
|
|
||
| # Default mapping is done by converting '.' characters to '/' separators in path | ||
| else: | ||
| self._data_path = os.path.join(self._base_dir, "/".join(dset.split(".")[1:])) | ||
| self._data_path = os.path.join(self._base_dir, os.path.join(*dset.split(".")[1:])) | ||
|
|
||
| # use to data_path to find files if not set already | ||
| if len(self._files) < 1: | ||
|
|
@@ -330,7 +333,7 @@ def switch_dset(dset: xr.Dataset | xr.DataArray | str | FileMapper) -> str: | |
| str | ||
| The dataset path or dataset ID derived from the input dataset, switched from the input. | ||
| """ | ||
| if dset.startswith("/"): | ||
| if isinstance(dset, str) and (dset.startswith("/") or dset.startswith("\\")): | ||
|
Zeitsperre marked this conversation as resolved.
Outdated
|
||
| return datapath_to_dsid(dset) | ||
| else: | ||
| return dsid_to_datapath(dset) | ||
|
|
@@ -445,9 +448,10 @@ def get_project_base_dir(project: str) -> str: | |
| ------- | ||
| str | ||
| The base directory of the specified project. | ||
| The URI uses platform-dependent path encoding. | ||
| """ | ||
| try: | ||
| return CONFIG[f"project:{project}"]["base_dir"] | ||
| return str(Path(CONFIG[f"project:{project}"]["base_dir"])) | ||
| except KeyError: | ||
|
Zeitsperre marked this conversation as resolved.
|
||
| raise InvalidProject("The project supplied is not known.") | ||
|
|
||
|
|
@@ -491,12 +495,11 @@ def get_project_from_data_node_root(url: str) -> str: | |
| """ | ||
| data_node_dict = get_data_node_dirs_dict() | ||
| project = None | ||
|
|
||
| for proj, data_node_root in data_node_dict.items(): | ||
| if data_node_root in url: | ||
| project = proj | ||
|
|
||
| if not project: | ||
| if project is None: | ||
| raise InvalidProject( | ||
| f"The project could not be identified from the URL {url} so it could not be mapped to a file path." | ||
| ) | ||
|
|
@@ -519,8 +522,8 @@ def url_to_file_path(url: str) -> str: | |
| """ | ||
| project = get_project_from_data_node_root(url) | ||
|
|
||
| data_node_root = CONFIG.get(f"project:{project}", {}).get("data_node_root") | ||
| base_dir = CONFIG.get(f"project:{project}", {}).get("base_dir") | ||
| file_path = os.path.join(base_dir, url.partition(data_node_root)[2]) | ||
| data_node_root = str(Path(CONFIG.get(f"project:{project}", {}).get("data_node_root"))) | ||
| base_dir = str(Path(CONFIG.get(f"project:{project}", {}).get("base_dir"))) | ||
| file_path = str(Path(base_dir).joinpath(str(Path(url.partition(data_node_root)[2])))) | ||
|
|
||
|
Zeitsperre marked this conversation as resolved.
Outdated
|
||
| return file_path | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.