Skip to content

anaconda/anaconda-linter

Repository files navigation

Anaconda Linter

Table of Contents

Anaconda Linter is a utility to validate that a recipe for a conda package will render correctly.

The package is currently a very rough draft of a pure Python linter specifically to make sure that packages' meta.yaml files adhere to certain Anaconda standards.

Installation

From conda (into your current environment)

$ conda install -c distro-tooling anaconda-linter

From the repository

$ cd anaconda-linter
$ make environment
$ conda activate anaconda-linter

For developers

$ cd anaconda-linter
$ make dev
$ conda activate anaconda-linter

Usage

usage: conda-lint [-h] [-V] [-m VARIANT_CONFIG_FILES] [-e EXCLUSIVE_CONFIG_FILES] [-s SUBDIRS] [--severity {INFO,WARNING,ERROR}] [-v] [-f] RECIPE_PATH

positional arguments:
  RECIPE_PATH           Path to recipe directory.

options:
  -h, --help            show this help message and exit
  -V, --version         The version of anaconda-linter
  -m VARIANT_CONFIG_FILES, --variant-config-files VARIANT_CONFIG_FILES
                        Additional variant config files to add. These yaml files can contain keys such as `c_compiler` and `target_platform` to form a
                        build matrix.
  -e EXCLUSIVE_CONFIG_FILES, --exclusive-config-files EXCLUSIVE_CONFIG_FILES, --exclusive-config-file EXCLUSIVE_CONFIG_FILES
                        Exclusive variant config files to add. Providing files here disables searching in your home directory and in cwd. The files
                        specified here come at the start of the order, as opposed to the end with --variant-config-files. Any config files in recipes and
                        any config files specified with --variant-config-files will override values from these files.
  -s SUBDIRS, --subdirs SUBDIRS
                        List subdir to lint. Example: linux-64, win-64...
  --severity {INFO,WARNING,ERROR}
                        The minimum severity level displayed in the output.
  -v, --verbose         Enable verbose output. This displays all of the checks that the linter is running.
  -f, --fix             Attempt to fix issues.

The usage is similar to conda-build.

  1. Navigate into the folder of your main conda_build_config.yaml file: cd <path/to/aggregate/>
  2. Run conda-lint with: conda-lint <path_to_feedstock>

Concrete example:

cd ~/work/recipes/aggregate/
conda-lint -v ../wip/airflow-feedstock

Full usage details can be found under the help menu (conda-lint -h). New users may find it easier to run the script with the verbose flag, -v which will provide additional context for linting errors.

Skipping Lints

In order to force the linter to ignore a certain type of lint, you can use the top-level extra key in a meta.yaml file. To skip lints individually, add lints from this list of current lints to the extra key as a list with a skip-lints key. For example:

extra:
  skip-lints:
    - unknown_selector
    - invalid_url

You can also do the opposite of this, and skip all other lints except the lints you want, with only-lint. For example:

extra:
  only-lint:
    - missing_license
    - incorrect_license

Note: if you have both skip-lints and only-lint, any lints in skip-lint will override identical lints in only-lint.

Testing the Anaconda Linter

Make sure that your anaconda-linter environment is activated, then:

make test

Contributing

We welcome contributions for bug fixes, enhancements, or new tests. For a list of projects, please see the Issues page

Before submitting a PR, please make sure to:

  1. Add unit tests for new functionality. To print a coverage report, run make test-cov.
  2. Run make pre-commit to format your code using isort and black and validate your code with our automated checks.

If you would like to develop in a hosted linux environment, a gitpod instance is available to test linter changes with real life packages, without having to download them to your own machine.

Development setup

To get started as a developer:

$ make dev
$ conda activate anaconda-linter

This will automatically configure pre-commit for the anaconda-linter environment. Our automated tooling will run when you make a commit in this environment. Running make dev will also blow away any existing environments for a clean install, every time.

Running make help will show all of the available commands. Here are some that may be immediately useful:

  1. make test: Runs all the unit tests
  2. make test-cov: Reports the current test coverage percentage and indicates which lines are currently untested.
  3. make lint: Runs our pylint configuration, based on Google's Python standards.
  4. make format: Automatically formats code
  5. make analyze: Runs the static analyzer, mypy.
  6. make pre-commit: Runs all the pre-commit checks

Release process

Here is a rough outline of how to conduct a release of this project:

  1. Update CHANGELOG.md
  2. Update the version number in anaconda_linter/__init__.py
  3. Ensure environment.yaml aligns with recipe/meta.yaml found in the feedstock
  4. Create a new release on GitHub with a version tag.
  5. The Anaconda packaging team will need to update the feedstock and aggregate and publish to distro-tooling

Contributions

This package is inspired by bioconda's linter.

Some of the code for suggesting hints comes from Peter Norvig.

License

BSD-3-Clause