Skip to content

Latest commit

 

History

History
64 lines (51 loc) · 2.93 KB

python.md

File metadata and controls

64 lines (51 loc) · 2.93 KB

com.linkedin.python

About

The com.linkedin.python plugin adds an extension called python to the project. It also configures a python project to setup a virtual env and run the tests. There are no artifacts produced by this plugin alone, you should check out other plugins to generate artifacts for the project.

python {
   docsDir = project.file('docs').path // The location of this project's Sphinx documentation directory
   testDir = project.file('test').path // The location of this project's tests directory.
   srcDir = project.file('src').path // The location of this project's source directory.
   setupCfg = project.file('src').path // The location of this project's setup.cfg file.
   pinnedFile = project.file('pinned.txt') // A file generated by the build for pip install to consume in no pygradle builds
   pythonEnvironment = [:] // Environment variables that will be passed to python commands. This will overwrite any existing env variables.
   pipConfig = [:] // A Map of Maps to build a pip configuration file in your venv
   
   details {
       virtualEnvPrompt = "(${project.name})"
       activateLink = project.file("activate") // File you can source to activate the virtual env
       // pythonVersion = '2.6' // Sets the version of python to use, will search your PATH to get the location
       // systemPythonInterpreter = file("/path/to/python2.7") // used to force an interpreter to be used to build the venv
   }
}

Usage

plugins {
    id 'com.linkedin.python', version <latest version>
}

pipConfig Examples

Sometimes you need to configure pip inside of the venv itself. The most common use cases are when you don't use pypi.python.com, but you use your own internal pypi server, or you need to set a proxy. Typically, you can configure this with an operating system level pip.* file as documented on the pip web site. But occasionally you need to configure this on a per-project basis. This is where this setting comes in. Take this example

python{
     pipConfig = ['global':['index-url': 'https://<login>:<password>@your.repo.com/custom/url', 'timeout': '60']]
}

This is a map of maps. The above will result in a pip.conf (or pip.ini on windows) of

[global]
index-url = https://<login>:<password>@your.repo.com/custom/url
timeout = 60

All of the standard pip configurations will work, this is simply a way of generating the file in the venv

Conditional Task Disabling

PyGradle will automatically disable tasks if certain conditions are present.

  • Product install will abort if no projectRoot/setup.py file is present
  • pytest will skip if the configured python.testDir doesn't exist
  • coverage will skip if the configured python.testDir doesn't exist
  • flake8 will skip if both python.testDir and python.srcDir doesn't exist
  • both Sphinx Documentation tasks will skip if the configured python.docsDir doesn't exist