diff --git a/doc/conf.py b/doc/conf.py index 2a5f16a85..b1e5d6993 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -98,7 +98,9 @@ rediraffe_redirects = { # Removal of the developer testing page - 'developer_guide/testing': 'developer_guide/index', + 'developer_guide/testing': 'developer_guide', + # Removal of the developer_guide folder + 'developer_guide/index': 'developer_guide', } html_context.update( # noqa diff --git a/doc/developer_guide.md b/doc/developer_guide.md new file mode 100644 index 000000000..653cbd892 --- /dev/null +++ b/doc/developer_guide.md @@ -0,0 +1,240 @@ +(devguide-setup)= + +# Developer Guide + +The hvPlot library is a project that provides a wide range of data interfaces and an extensible set of plotting backends, which means the development and testing process involves a broad set of libraries. + +This guide describes how to install and configure development environments. + +If you have any problems with the steps here, please reach out in the `dev` channel on [Discord](https://discord.gg/rb6gPXbdAr) or on [Discourse](https://discourse.holoviz.org/). + +## TL;DR + +0. Open an [issue on Github](https://github.com/holoviz/hvplot/issues) if needed +1. Fork and clone [hvPlot's Github repository](https://github.com/holoviz/hvplot) +2. Install [`pixi`](https://pixi.sh) +3. Run `pixi run install-dev` to create your development environment +4. Make some changes and run: + - `pixi run test-unit` if you updated the source code to run the unit tests + - `pixi run test-example` if you updated the notebooks to run them + - `pixi run docs-build-dev` if you need to build the website locally +5. Open a Pull Request + +## Preliminaries + +### Basic understanding of how to contribute to Open Source + +If this is your first open-source contribution, please study one +or more of the below resources. + +- [How to Get Started with Contributing to Open Source | Video](https://youtu.be/RGd5cOXpCQw) +- [Contributing to Open-Source Projects as a New Python Developer | Video](https://youtu.be/jTTf4oLkvaM) +- [How to Contribute to an Open Source Python Project | Blog post](https://www.educative.io/blog/contribue-open-source-python-project) + +### Git + +The hvPlot source code is stored in a [Git](https://git-scm.com) source control repository. The first step to working on hvPlot is to install Git onto your system. There are different ways to do this, depending on whether you use Windows, Mac, or Linux. + +To install Git on any platform, refer to the [Installing Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) section of the [Pro Git Book](https://git-scm.com/book/en/v2). + +To contribute to hvPlot, you will also need [Github account](https://github.com/join) and knowledge of the [_fork and pull request workflow_](https://docs.github.com/en/get-started/quickstart/contributing-to-projects). + +### Pixi + +Developing all aspects of hvPlot requires a wide range of packages in different environments, but for new contributors the `default` environment will be more than enough. + +To make this more manageable, Pixi manages the developer experience. To install Pixi, follow [this guide](https://pixi.sh/latest/#installation). + +#### Glossary + +- *Tasks*: A task is what can be run with `pixi run `. Tasks can be anything from installing packages to running tests. +- *Environments*: An environment is a set of packages installed in a virtual environment. Each environment has a name; you can run tasks in a specific environment with the `-e` flag. For example, `pixi run -e test-core test-unit` will run the `test-unit` task in the `test-core` environment. +- *Lock-file*: A lock-file is a file that contains all the information about the environments. + +For more information, see the [Pixi documentation](https://pixi.sh/latest/). + +:::{admonition} Note +:class: info + +The first time you run `pixi`, it will create a `.pixi` directory in the source directory. +This directory will contain all the files needed for the virtual environments. +The `.pixi` directory can be large, so it is advised not to put the source directory into a cloud-synced directory. + +::: + +## Installing the Project + +### Cloning the Project + +The source code for the hvPlot project is hosted on [GitHub](https://github.com/holoviz/hvplot). The first thing you need to do is clone the repository. + +1. Go to [github.com/holoviz/hvplot](https://github.com/holoviz/hvplot) +2. [Fork the repository](https://docs.github.com/en/get-started/quickstart/contributing-to-projects#forking-a-repository) +3. Run in your terminal: `git clone https://github.com//hvplot` + +The instructions for cloning above created a `hvplot` directory at your file system location. +This `hvplot` directory is the _source checkout_ for the remainder of this document, and your current working directory is this directory. + +## Start developing + +To start developing, run the following command, this will create an environment called `default` (in `.pixi/envs`), install hvPlot in [editable mode](https://pip.pypa.io/en/stable/topics/local-project-installs/#editable-installs), download test datasets, and install `pre-commit`: + +```bash +pixi run install-dev +``` + +:::{admonition} Note +:class: info + +The first time you run it, it will create a `pixi.lock` file with information for all available environments. +This command will take a minute or so to run. +::: + +All available tasks can be found by running `pixi task list`, the following sections will give a brief introduction to the most common tasks. + +### Syncing Git tags with upstream repository + +If you are working from a forked repository of hvPlot, you will need to sync the tags with the upstream repository. +This is needed because the hvPlot version number depends on [`git tags`](https://git-scm.com/book/en/v2/Git-Basics-Tagging). +Syncing the git tagsĀ can be done with: + +```bash +pixi run sync-git-tags +``` + +## Developer Environment + +The `default` environment is meant to provide all the tools needed to develop hvPlot. + +This environment is created by running `pixi run install-dev`. Run `pixi shell` to activate it; this is equivalent to `source venv/bin/activate` in a Python virtual environment or `conda activate` in a conda environment. + +If you need to run a command directly instead of via `pixi`, activate the environment and run the command (e.g. `pixi shell` and `pytest hvplot/tests/`). + +### VS Code + +This environment can also be selected in your IDE. In VS Code, this can be done by running the command `Python: Select Interpreter` and choosing `{'default': Pixi}`. + +

+ 001 + 002 +

+ +To confirm you are using this dev environment, check the bottom right corner: + +![003](https://assets.holoviews.org/static/dev_guide/003.png) + +### Jupyter Lab + +You can launch Jupyter lab with the `default` environment with `pixi run lab`. This can be advantageous when you need to edit the documentation or debug an example notebook. + +## Linting + +hvPlot uses [`pre-commit`](https://pre-commit.com/) to lint and format the source code. `pre-commit` is installed automatically when running `pixi run install-dev`; it can also be installed with `pixi run lint-install`. +`pre-commit` runs all the linters when a commit is made locally. Linting can be forced to run for all the files with: + +```bash +pixi run lint +``` + +:::{admonition} Note +:class: info + +Alternatively, if you have `pre-commit` installed elsewhere you can run: + +```bash +pre-commit install # To install +pre-commit run --all-files # To run on all files +``` + +::: + +## Testing + +To help keep hvPlot maintainable, all Pull Requests (PR) with code changes should typically be accompanied by relevant tests. While exceptions may be made for specific circumstances, the default assumption should be that a Pull Request without tests will not be merged. + +There are three types of tasks and five environments related to tests. + +### Unit tests + +Unit tests are usually small tests executed with [pytest](https://docs.pytest.org). They can be found in `hvplot/tests/`. +Unit tests can be run with the `test-unit` task: + +```bash +pixi run test-unit +``` + +:::{admonition} Advanced usage +:class: tip + +The task is available in the following environments: `test-39`, `test-310`, `test-311`, `test-312`, and `test-core`. Where the first ones have the same environments except for different Python versions, and `test-core` only has a core set of dependencies. + +You can run the task in a specific environment with the `-e` flag. For example, to run the `test-unit` task in the `test-39` environment, you can run: + +```bash +pixi run -e test-39 test-unit +``` + +::: + +:::{admonition} Advanced usage +:class: tip + +Currently, an editable install needs to be run in each environment. So, if you want to install in the `test-core` environment, you can add `--environment` / `-e` to the command: + +```bash +pixi run -e test-core install +``` + +::: + +### Example tests + +hvPlot's documentation consists mainly of Jupyter Notebooks. The example tests execute all the notebooks and fail if an error is raised. Example tests are possible thanks to [nbval](https://nbval.readthedocs.io/) and can be found in the `doc/` folder. +Example tests can be run with the following command: + +```bash +pixi run test-example +``` + +## Documentation + +The documentation can be built with the command: + +```bash +pixi run docs-build-dev +``` + +As hvPlot uses notebooks for much of the documentation, this takes a little while. You can disable building the gallery by setting the environment variable `HVPLOT_REFERENCE_GALLERY` to `false`. + +A development version of hvPlot can be found [here](https://holoviz-dev.github.io/hvplot/). You can ask a maintainer if they want to make a dev release for your PR, but there is no guarantee they will say yes. + +## Build + +hvPlot has two build tasks to build a Python (for pypi.org) and a Conda package (for anaconda.org). + +```bash +pixi run build-pip +pixi run build-conda +``` + +## Continuous Integration + +Every push to the `main` branch or any PR branch on GitHub automatically triggers a test build with [GitHub Actions](https://github.com/features/actions). + +You can see the list of all current and previous builds at [this URL](https://github.com/holoviz/hvplot/actions) + +### Etiquette + +GitHub Actions provides free build workers for open-source projects. A few considerations will help you be considerate of others needing these limited resources: + +- Run the tests locally before opening or pushing to an opened PR. + +- Group commits to meaningful chunks of work before pushing to GitHub (i.e., don't push on every commit). diff --git a/doc/developer_guide/index.md b/doc/developer_guide/index.md deleted file mode 100644 index 92808eea8..000000000 --- a/doc/developer_guide/index.md +++ /dev/null @@ -1,176 +0,0 @@ -(devguide-setup)= - -# Developer Guide - -```{contents} -:depth: 3 -:local: true -``` - -## Set up - -The hvPlot library is a complex project which provides a wide range -of data interfaces and an extensible set of plotting backends, which -means the development and testing process involves a wide set of -libraries. - -If you have any problems with the steps here, please contact the developers on [Discord](https://discord.gg/AXRHnJU6sP). - -### Preliminaries - -#### Git - -The hvPlot source code is stored in a [Git](https://git-scm.com) source control repository. -The first step to working on hvPlot is to install Git on to your system. -There are different ways to do this depending on whether, you are using -Windows, OSX, or Linux. - -To install Git on any platform, refer to the [Installing Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) section of -the [Pro Git Book](https://git-scm.com/book/en/v2). - -#### Conda (optional) - -Developing hvPlot requires a wide range of dependencies that can all be installed with -the [conda package manager](https://conda.io). Using `conda` is sometimes the easiest way to install -a dependency (e.g. `graphviz`, Firefox drivers). However, these days most of the dependencies -required to develop hvPlot can be installed with `pip`. - -Follow [these instructions](https://conda.io/projects/conda/user-guide/install/index.html) to download conda. - -### Cloning the Repository - -The source code for the hvPlot project is hosted on GitHub. To clone the -source repository, issue the following command: - -```sh -git clone https://github.com/holoviz/hvplot.git -``` - -This will create a `hvplot` directory at your file system -location. This `hvplot` directory is referred to as the *source -checkout* for the remainder of this document. - -(dev-guide-installing-dependencies)= - -### Installing Dependencies - -hvPlot requires many additional packages for development and -testing. - -::::{tab-set} - -:::{tab-item} pip - -Start by creating a virtual environment with `venv`: - -``` -python -m venv .venv -``` - -Activate it: - -``` -# Linux/MacOs -source .venv/bin/activate -# Windows -.venv\Scripts\activate -``` - -Install the test dependencies: - -``` bash -pip install --prefer-binary -e '.[tests, examples-tests, geo, hvdev, hvdev-geo, dev-extras]' -``` - -::: - -:::{tab-item} conda - -Create a development conda environment using one of the environment files present -in the `./envs` folder, and activate it: - -``` bash -conda env create --file envs/py3.10-tests.yaml -conda activate hvplottests -``` - -::: - -:::: - - -### Setting up pre-commit - -hvPlot uses `pre-commit` to automatically apply linting to hvPlot code. -If you intend to contribute to hvPlot we recommend you enable it with: - -```sh -pre-commit install -``` - -This will ensure that every time you make a commit linting will automatically be applied. - - -## Testing - -This chapter describes how to run various tests locally in a -development environment, guidelines for writing tests, and information -regarding the continuous testing infrastructure. - -### Running Tests Locally - -Before attempting to run hvPlot tests, make sure you have successfully -run through all of the instructions in the {ref}`devguide-setup` -section of the Developer's Guide. - -Currently hvPlot uses linting two types of tests: regular unit tests -which are run with `pytest` and notebook example tests run with `pytest` and `nbval`: - -Run the unit tests with: - -```bash -pytest hvplot -pytest -v hvplot --geo # include the test that require geo dependencies -``` - -Run the example tests with: - -```sh -pytest -n auto --dist loadscope --nbval-lax -p no:python -``` - -### Writing Tests - -In order to help keep hvPlot maintainable, all Pull Requests that touch -code should normally be accompanied by relevant tests. While -exceptions may be made for specific circumstances, the default -assumption should be that a Pull Request without tests may not be -merged. - -Python unit tests maintain the basic functionality of the Python -portion of the hvPlot library. A few general guidelines will help you -write Python unit tests: - -In order to ensure that hvPlot's unit tests as relocatable and unambiguous -as possible, always prefer absolute imports in test files. When convenient, -import and use the entire module under test: - -- **Good**: `import hvplot.pandas` -- **Good**: `from hvplot.plotting import HvPlotTabular` -- **Bad**: `from ..plotting import HvPlotTabular` - -### Continuous Integration (CI) - -Every push to the `main` branch or any Pull Request branch on GitHub -automatically triggers a full test build on the [Github Action](https://github.com/holoviz/hvplot/actions) continuous -integration service. This is most often useful for running the full hvPlot -test suite continuously, but also triggers automated scripts for publishing -releases when a tagged branch is pushed. - -When in doubt about what command to run, you can always inspect the Github -workflow files in the `./github/workflows` folder so see what commands -are running on the CI. - -Github Action provides a limited number free build workers to Open Source projects. -Please be considerate of others and group commits into meaningful chunks of -work before pushing to GitHub (i.e. don't push on every commit). diff --git a/doc/index.md b/doc/index.md index 1f9396819..2b5bb7206 100644 --- a/doc/index.md +++ b/doc/index.md @@ -425,7 +425,7 @@ Getting Started User Guide Reference Gallery Topics -Developer Guide +Developer Guide Releases Roadmap About diff --git a/pixi.toml b/pixi.toml index dcd3aa00f..2c315f343 100644 --- a/pixi.toml +++ b/pixi.toml @@ -3,25 +3,53 @@ name = "hvplot" channels = ["pyviz/label/dev", "conda-forge"] platforms = ["linux-64", "osx-arm64", "osx-64", "win-64"] -[tasks] -download-data = 'python scripts/download_data.py' -install = 'python -m pip install --no-deps --disable-pip-version-check -e .' +[environments] +default = [ + "py312", + "required", + "test-core", + "test", + "example", + "geo", + "graphviz", + "test-example", + "lint", + "dev", +] -[activation.env] -PYTHONIOENCODING = "utf-8" +[environments.test-39] +features = ["py39", "required", ] +no-default-feature = true -[environments] -test-39 = ["py39", "test-core", "test", "example", "geo", "graphviz", "test-example"] -test-310 = ["py310", "test-core", "test", "example", "geo", "graphviz", "test-example"] -test-311 = ["py311", "test-core", "test", "example", "geo", "graphviz", "test-example"] -test-312 = ["py312", "test-core", "test", "example", "geo", "graphviz", "test-example"] -# test-313 = ["py313", "test-core", "test", "example", "geo", "graphviz", "test-example"] -test-core = ["py313", "test-core"] -docs = ["py311", "doc", "example", "geo", "graphviz"] -build = ["py311", "build"] -lint = ["py311", "lint"] - -[dependencies] +[environments.test-310] +features = ["py310", "required", "test-core", "test", "example", "geo", "graphviz", "test-example"] +no-default-feature = true + +[environments.test-311] +features = ["py311", "required", "test-core", "test", "example", "geo", "graphviz", "test-example"] +no-default-feature = true + +[environments.test-312] +features = ["py312", "required", "test-core", "test", "example", "geo", "graphviz", "test-example"] +no-default-feature = true + +[environments.test-core] +features = ["py313", "required", "test-core"] +no-default-feature = true + +[environments.docs] +features = ["py311", "required", "doc", "example", "geo", "graphviz"] +no-default-feature = true + +[environments.build] +features = ["py311", "required", "build"] +no-default-feature = true + +[environments.lint] +features = ["lint"] +no-default-feature = true + +[feature.required.dependencies] nomkl = "*" pip = "*" # Required @@ -34,6 +62,15 @@ pandas = ">=1.3" panel = ">=1.0" param = ">=1.12.0,<3.0" +[feature.required.tasks] +download-data = 'python scripts/download_data.py' +install = 'python -m pip install --no-deps --disable-pip-version-check -e .' +install-dev = { cmd = "pre-commit install", depends-on = ["install", "download-data"] } +sync-git-tags = 'python scripts/sync_git_tags.py hvplot' + +[feature.required.activation.env] +PYTHONIOENCODING = "utf-8" + [feature.py39.dependencies] python = "3.9.*" @@ -59,6 +96,16 @@ bokeh_sampledata = "*" [feature.py313.activation.env] COVERAGE_CORE = "sysmon" +# =================== DEV =================== + +[feature.dev.dependencies] +jupyterlab = "*" +jupyterlab-myst = "*" +setuptools_scm = ">=6" + +[feature.dev.tasks] +lab = 'jupyter lab' + # =================== SHARED DEPS =================== # Dependencies required to run the notebooks @@ -183,6 +230,10 @@ DISPLAY = ":99.0" [feature.doc.tasks] docs-build = 'sphinx-build -b html doc builtdocs' +# docs-build-dev = { cmd = "pre-commit install", depends-on = ["install", "docs-build"] } +_docs-install = 'python -m pip install --no-deps --disable-pip-version-check -e .' +docs-build-dev = { depends-on = ["_docs-install", "docs-build"] } + # ================== BUILD ==================== diff --git a/scripts/download_data.py b/scripts/download_data.py index 0a3e5279e..dbbaff4ed 100644 --- a/scripts/download_data.py +++ b/scripts/download_data.py @@ -5,6 +5,7 @@ import bokeh.sampledata bokeh.sampledata.download() + print('bokeh data downloaded.') try: import pooch # noqa: F401 @@ -13,5 +14,6 @@ xr.tutorial.open_dataset('air_temperature') xr.tutorial.open_dataset('rasm') + print('xarray data downloaded.') except ModuleNotFoundError as e: print(f'ModuleNotFoundError when attempting to download xarray datasets : {e}') diff --git a/scripts/sync_git_tags.py b/scripts/sync_git_tags.py new file mode 100644 index 000000000..9d217860f --- /dev/null +++ b/scripts/sync_git_tags.py @@ -0,0 +1,31 @@ +""" +Script to sync tags from upstream repository to forked repository +""" + +import sys +from subprocess import run + + +def main(package: str) -> None: + origin = run(['git', 'remote', 'get-url', 'origin'], check=True, capture_output=True) + upstream = run(['git', 'remote', 'get-url', 'upstream'], check=False, capture_output=True) + url = ( + f'https://github.com/holoviz/{package}.git' + if origin.stdout.startswith(b'http') + else f'git@github.com:holoviz/{package}.git' + ) + + if url == origin.stdout.strip().decode(): + print('Not a forked repository, exiting.') + return + elif upstream.returncode: + print(f'Adding {url!r} as remote upstream') + run(['git', 'remote', 'add', 'upstream', url], check=True, capture_output=True) + + print(f'Syncing tags from {package} repository with your forked repository') + run(['git', 'fetch', '--tags', 'upstream'], check=True, capture_output=True) + run(['git', 'push', '--tags'], check=True, capture_output=True) + + +if __name__ == '__main__': + main(sys.argv[1])