Plug-In | Usage |
---|---|
io.logbee.gradle.conda |
Setup a conda environment. |
io.logbee.gradle.python |
Build, test and assemble python projects. |
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.
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. |
Create a build.gradle
script as shown below:
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:
-
It applies the
io.logbee.gradle.python
plugin to the project. This will in turn also apply theio.logbee.gradle.conda
plugin. -
It declares a couple of dependencies.
-
It adds
protobuf
in version3.8.0
to theapi
-configuration using conda’sanaconda
channel. -
It adds
pytest
in version5.1.2
to thetest
-configuration using conda’sconda-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. |
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:
-
It downloads a suitable Miniconda distribution into the gradle cache.
-
It installs Miniconda into your gradle-home.
-
It setups a conda environment in the project’s
.gradle
directory. -
It installs the dependencies declared in the
build.gradle
into the project’s conda environment.
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. |
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.
.
├── build.gradle
├── src
│ └── example.py
└── test
└── test_example.py
sourceSets {
main {
python {
srcDir 'src'
}
}
test {
python {
srcDir 'test'
}
}
}