xcube Developer Guide¶
Version 0.2, draft
IMPORTANT NOTE: Any changes to this doc must be reviewed by dev-team through pull requests.
Preface¶
Gedacht ist nicht gesagt.
Gesagt ist nicht gehört.
Gehört ist nicht verstanden.
Verstanden ist nicht einverstanden.
Einverstanden ist nicht umgesetzt.
Umgesetzt ist nicht beibehalten.
by Konrad Lorenz (translation is left to the reader)
Table of Contents¶
Versioning¶
We adhere to PEP-440.
Therefore, the xcube software version uses the format
<major>.<minor>.<micro>
for released versions and
<major>.<minor>.<micro>.dev<n>
for versions in development.
<major>
is increased for major enhancements. CLI / API changes may introduce incompatibilities with former version.<minor>
is increased for new features and and minor enhancements. CLI / API changes are backward compatible with former version.<micro>
is increased for bug fixes and micro enhancements. CLI / API changes are backward compatible with former version.<n>
is increased whenever the team (internally) deploys new builds of a development snapshot.
The current software version is in xcube/version.py
.
Main Packages¶
xcube.core
- Hosts core API functions. Code in here should be maintained w.r.t. backward compatibility. Therefore think twice before adding new or change existing core API.xcube.cli
- Hosts CLI commands. CLI command implementations should be lightweight. Move implementation code either intocore
orutil
.
CLI commands must be maintained w.r.t. backward compatibility. Therefore think twice before adding new or change existing CLI commands.xcube.webapi
- Hosts Web API functions. Web API command implementations should be lightweight. Move implementation code either intocore
orutil
.
Web API interface must be maintained w.r.t. backward compatibility. Therefore think twice before adding new or change existing web API.xcube.util
- Mainly implementation helpers. Comprises classes and functions that are used bycli
,core
,webapi
in order to maximize modularisation and testability but to minimize code duplication.
The code in here must not be dependent on any ofcli
,core
,webapi
. The code in here may change often and in any way as desired by code implementing thecli
,core
,webapi
packages.
The following sections will guide you through extending or changing the main packages that form xcube’s public interface.
Package xcube.cli
¶
Checklist¶
Make sure your change
is covered by unit-tests (package
test/cli
);is reflected by the CLI’s doc-strings and tools documentation (currently in
README.md
);follows existing xcube CLI conventions;
follows PEP8 conventions;
is reflected in API and WebAPI, if desired;
is reflected in
CHANGES.md
.
Hints¶
Make sure your new CLI command is in line with the others commands regarding command name, option names, as well as metavar arguments names. The CLI command name shall ideally be a verb.
Avoid introducing new option arguments if similar options are already in use for existing commands.
In the following common arguments and options are listed.
Input argument:
@click.argument('input')
If input argument is restricted to an xcube dataset:
@click.argument('cube')
Output (directory) option:
@click.option('--output', '-o', metavar='OUTPUT',
help='Output directory. If omitted, "INPUT.levels" will be used.')
Output format:
@click.option('--format', '-f', metavar='FORMAT', type=click.Choice(['zarr', 'netcdf']),
help="Format of the output. If not given, guessed from OUTPUT.")
Output parameters:
@click.option('--param', '-p', metavar='PARAM', multiple=True,
help="Parameter specific for the output format. Multiple allowed.")
Variable names:
@click.option('--variable',--var', metavar='VARIABLE', multiple=True,
help="Name of a variable. Multiple allowed.")
For parsing CLI inputs, use helper functions that are already in use.
In the CLI command implementation code, raise
click.ClickException(message)
with a clear message
for users.
Common xcube CLI options like -f
for FORMAT should be lower case
letters and specific xcube CLI options like -S
for SIZE in xcube gen
are recommended to be uppercase letters.
Extensively validate CLI inputs to avoid that API functions raise
ValueError
, TypeError
, etc. Such errors and their message texts are
usually hard to understand by users. They are actually dedicated to
to developers, not CLI users.
There is a global option --traceback
flag that user can set to dump
stack traces. You don’t need to print stack traces from your code.
Package xcube.core
¶
Checklist¶
Make sure your change
is covered by unit-tests (package
test/core
);is covered by API documentation;
follows existing xcube API conventions;
follows PEP8 conventions;
is reflected in xarray extension class
xcube.core.xarray.DatasetAccessor
;is reflected in CLI and WebAPI if desired;
is reflected in
CHANGES.md
.
Hints¶
Create new module in xcube.core
and add your functions.
For any functions added make sure naming is in line with other API.
Add clear doc-string to the new API. Use Sphinx RST format.
Decide if your API methods requires xcube datasets as
inputs, if so, name the primary dataset argument cube
and add a
keyword parameter cube_asserted: bool = False
.
Otherwise name the primary dataset argument dataset
.
Reflect the fact, that a certain API method or function operates only
on datasets that conform with the xcube dataset specifications by
using cube
in its name rather than dataset
. For example
compute_dataset
can operate on any xarray datasets, while
get_cube_values_for_points
expects a xcube dataset as input or
read_cube
ensures it will return valid xcube datasets only.
In the implementation, if not cube_asserted
,
we must assert and verify the cube
is a cube.
Pass True
to cube_asserted
argument of other API called later on:
from xcube.core.verify import assert_cube
def frombosify_cube(cube: xr.Dataset, ..., cube_asserted: bool = False):
if not cube_asserted:
assert_cube(cube)
...
result = bibosify_cube(cube, ..., cube_asserted=True)
...
If import xcube.core.xarray
is imported in client code, any xarray.Dataset
object will have an extra property xcube
whose interface is defined
by the class xcube.core.xarray.DatasetAccessor
. This class is an
xarray extension
that is used to reflect xcube.core
functions and make it directly
applicable to the xarray.Dataset
object.
Therefore any xcube API shall be reflected in this extension class.
Package xcube.webapi
¶
Checklist¶
Make sure your change
is covered by unit-tests (package
test/webapi
);is covered by Web API specification and documentation (currently in
webapi/res/openapi.yml
);follows existing xcube Web API conventions;
follows PEP8 conventions;
is reflected in CLI and API, if desired;
is reflected in
CHANGES.md
.
Hints¶
The Web API is defined in
webapi.app
which defines mapping from resource URLs to handlersAll handlers are implemented in
webapi.handlers
. Handler code just delegates to dedicated controllers.All controllers are implemented in
webapi.controllers.*
. They might further delegate intocore.*
Development Process¶
Make sure there is an issue ticket for your code change work item
Select issue, priorities are as follows
“urgent” and (“important” and “bug”)
“urgent” and (“important” or “bug”)
“urgent”
“important” and “bug”
“important” or “bug”
others
Make sure issue is assigned to you, if unclear agree with team first.
Add issue label “in progress”.
Create development branch named “
- - ” or “ - - -fix” (see below). Develop, having in mind the checklists and implementation hints above.
In your first commit, refer the issue so it will appear as link in the issue history
Develop, test, and push to the remote branch as desired.
In your last commit, utilize checklists above. (You can include the line “closes #
” in your commit message to auto-close the issue once the PR is merged.)
Create PR if build servers succeed on your branch. If not, fix issue first.
For the PR assign the team for review, agree who is to merge. Also reviewers should have checklist in mind.Merge PR after all reviewers are accepted your change. Otherwise go back.
Remove issue label “in progress”.
Delete the development branch.
If the PR is only partly solving an issue:
Make sure the issue contains a to-do list (checkboxes) to complete the issue.
Do not include the line “closes #
” in your last commit message. Add “relates to issue#” in PR.
Make sure to check the corresponding to-do items (checkboxes) after the PR is merged.
Remove issue label “in progress”.
Leave issue open.
Branches and Releases¶
Target Branches¶
The
master
branch contains latest developments, including new features and fixes. It is used to generate<major>.<minor>.0
releases. That is, either<major>
or<minor>
is increased.The
<major>.<minor>.x
branch is the maintenance branch for a former release taggedv<major>.<minor>.0
. It is used to generate maintenance<major>.<minor>.<fix>
releases. That is, only<fix>
is increased. Most changes to<major>.<minor>.x
branch must obviously be merged intomaster
branch too.
The software version string on all active branches is always
<major>.<minor>.<micro>.dev<n>
. Only for a release, we remove the
.dev<n>
suffix.
Development Branches¶
Development branches that target the <major>.<minor>.x
branch
should indicate that by using the suffix -fix
,
e.g. coolguy-7633-div_by_zero_in_mean-fix
. After a pull request,
the development branch will first be merged into the
<major>.<minor>.x
branch then into master
.
Release Process¶
xcube¶
Check issues in progress, close any open issues that have been fixed.
In
xcube/version.py
remove the.dev
suffix from version name.Make sure
CHANGES.md
is complete. Remove the suffix(in development)
from the last version headline.Push changes to either master or a new maintenance branch (see above).
Await results from Travis CI and ReadTheDocs builds. If broken, fix.
Goto xcube/releases and press button “Draft a new Release”.
Tag version is:
v${version}
(with a “v” prefix)Release title is:
${version}
Paste latest changes from
CHANGELOG.md
into field “Describe this release”Press “Publish release” button
After the release on GitHub, if the branch was
master
, create a new maintenance branch (see above)In
xcube/version.py
increase version number and append a.dev0
suffix to version name so that it is still PEP-440 compatible.In
CHANGES.md
add a new version headline and attach(in development)
to it.Push changes to either master or a new maintenance branch (see above).
Activate new doc version on ReadTheDocs.
Go through the same procedure for all xcube plugin packages dependent on this version of xcube.
TODO: Describe deployment to xcube conda package after release TODO: Describe deployment of xcube Docker image after release
If any changes apply to xcube serve
and the xcube Web API:
Make sure changes are reflected in xcube/webapi/res/openapi.yml
.
If there are changes, sync xcube/webapi/res/openapi.yml
with
xcube Web API docs on SwaggerHub.
Check if changes affect the xcube-viewer code. If so make sure changes are reflected in xcube-viewer code and test viewer with latest xcube Web API. Then release a new xcube viewer.
xcube Viewer¶
Cd into viewer project directory (
.../xcube-viewer/.
).Remove the
-dev
suffix fromversion
property inpackage.json
.Remove the
-dev
suffix fromVIEWER_VERSION
constant insrc/config.ts
.Make sure
CHANGELOG.md
is complete. Remove the suffix(in development)
from the last version headline.Build the app and test the build using a local http-server, e.g.:
$ npm install -g http-server $ cd build $ http-server -p 3000
Push changes to either master or a new maintenance branch (see above).
Goto xcube-viewer/releases and press button “Draft a new Release”.
Tag version is:
v${version}
(with a “v” prefix).Release title is:
${version}
.Paste latest changes from
CHANGELOG.md
into field “Describe this release”.Press “Publish release” button.
Deploy build contents to any relevant web content providers.
After the release on GitHub, if the branch was
master
, create a new maintenance branch (see above).In
package.json
andVIEWER_VERSION
constant insrc/config.ts
append-dev.0
suffix . to version name so it is SemVer compatible.In
CHANGELOG.md
add a new version headline and attach(in development)
to it.Push changes to either master or a new maintenance branch (see above).