Giter Site home page Giter Site logo

gradle-conda-plugin's Introduction

Gradle Conda Plug-in

Overview

Plug-In Usage

io.logbee.gradle.conda

Setup a conda environment.

io.logbee.gradle.python

Build, test and assemble python projects.

Getting Started

This section is a quick start guide to show you how to use the io.logbee.gradle.python plugin to build and test a simple python project. You can find more examples in the examples directory.

Layout

Given the following example project:

example
├── build.gradle
├── src
│   └── example.py
└── test
    └── test_example.py
Note
Project Layout

The layout of the project can be changed according to your preferences, see Project Layout.

Configuration

Create a build.gradle script as shown below:

build.gradle
plugins {
  id "io.logbee.gradle.python" version "0.2.0" <1>
}

dependencies { <2>
    api 'anaconda:protobuf:3.8.0' <3>
    test 'conda-forge:pytest:5.1.2' <4>
}

The script does the following things:

  1. It applies the io.logbee.gradle.python plugin to the project. This will in turn also apply the io.logbee.gradle.conda plugin.

  2. It declares a couple of dependencies.

  3. It adds protobuf in version 3.8.0 to the api-configuration using conda’s anaconda channel.

  4. It adds pytest in version 5.1.2 to the test-configuration using conda’s conda-forge channel.

Note
Conda Channels

Conda packages are downloaded from remote channels, which are URLs to directories containing conda packages. Read more about channels here.

Usage

Now you can invoke gradle in the root of the project. Most of the things are done during the evaluation of the project. Therefore it doesn’t matter which task you run. A simple $ gradle call will also work.

The conda plugin is gonging to do the following things:

  1. It downloads a suitable Miniconda distribution into the gradle cache.

  2. It installs Miniconda into your gradle-home.

  3. It setups a conda environment in the project’s .gradle directory.

  4. It installs the dependencies declared in the build.gradle into the project’s conda environment.

Testing

To run the tests simply call: $ gradle test

Important
PyTestTask

The PyTestTask uses pytest to run the tests. PyTest is not automatically installed. It has to be added as dependency to the project. This may change in later versions.

Project Layout

By using SourceSets, the project’s directory structure (layout) can be adjusted to your needs/preferences.

The io.logbee.gradle.python plugin uses a main and a test source-set to manage the sources. The location of the sources can be specified by passing a path to the directory.

Default Layout

Layout
.
├── build.gradle
├── src
│   └── example.py
└── test
    └── test_example.py
build.gradle
sourceSets {
    main {
        python {
            srcDir 'src'
        }
    }
    test {
        python {
            srcDir 'test'
        }
    }
}

Maven Layout

Layout
.
├── build.gradle
└── src
    ├── main
    │   └── python
    │       └── example.py
    └── test
        └── python
            └── test_example.py
build.gradle
sourceSets {
    main {
        python {
            srcDir 'src/main/python'
        }
    }
    test {
        python {
            srcDir 'src/test/python'
        }
    }
}

Contributions

All contributions are welcome: ideas, patches, documentation, bug reports, complaints.

gradle-conda-plugin's People

Contributors

kkdh avatar

Stargazers

Ole Christian Langfjæran avatar Eugene Akhmetkhanov avatar Andre White avatar

Watchers

James Cloos avatar  avatar Reimar avatar

Forkers

jamezz

gradle-conda-plugin's Issues

Is it possible to add pytest command line flags?

I want to use a plugin for pytest, pytest-html, to generate HTML reports of test results.

I'm able to install the plugin from conda for the test task:

dependencies {
    test 'conda-forge:pytest:5.1.2'
    test 'conda-forge:pytest-html:2.0.1'
}

In order to generate HTML reports, I need to add the command line flag --html path/to/report.html, but I can't see how to pass through any extra flags to pytest, or any other way to run this plugin. The pytest documentation at https://docs.pytest.org/en/latest/customize.html indicates that extra command line flags can be configured via the Python setup.cfg, pytest.ini, or a PYTEST_ADDOPTS environment variable. I've tried each of these and it doesn't seem to have any effect. I noticed that this plugin creates it's own pytest.ini in the build directory, but adding options in there is no good, as it gets overwritten with an empty config file on each run.

Similarly, I'd quite like to change the path that the JUnit XML tests are written to to match the path that my Java test reports get written to. This is less important as I can handle the different path elsewhere in my build pipeline, but if I were able to override the --junitreport flag then I could modify it in my build.

I might be going about this the wrong way (Both gradle and pytest are pretty new to me), but I can't figure out any way of passing through command line flags or otherwise configuring the pytest run. I can see that command line flags and pytest.ini contents are defined in src/main/java/io/logbee/gradle/conda/python/test/PyTestTask.java, so I guess at worst I can fork the code and add my own custom options in there, but I'd prefer to stick with the published plugin if possible.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.