2021-05-06 22:10:49 -07:00
plugins {
2023-02-21 09:50:03 -05:00
id 'base'
2021-05-06 22:10:49 -07:00
}
ext {
python_executable = 'python3'
venv_name = 'venv'
}
2022-11-11 15:04:36 -05:00
if ( ! project . hasProperty ( "extra_pip_requirements" ) ) {
ext . extra_pip_requirements = ""
}
2023-03-24 12:40:45 +05:30
def get_coverage_arg ( test_name ) {
return "--cov-report term --cov-report xml:coverage_${test_name}.xml "
}
2021-05-06 22:10:49 -07:00
task checkPythonVersion ( type: Exec ) {
2023-03-17 09:34:00 +05:30
commandLine python_executable , '-c' ,
'import sys; assert (3, 11) > sys.version_info >= (3, 7), f"Python version {sys.version_info[:2]} not allowed"'
2021-05-06 22:10:49 -07:00
}
task environmentSetup ( type: Exec , dependsOn: checkPythonVersion ) {
2021-11-30 18:01:56 -08:00
inputs . file file ( 'setup.py' )
outputs . dir ( "${venv_name}" )
2023-03-15 03:02:30 +05:30
commandLine 'bash' , '-c' , "${python_executable} -m venv ${venv_name} && ${venv_name}/bin/python -m pip install --upgrade pip wheel 'setuptools>=63.0.0'"
2021-05-06 22:10:49 -07:00
}
2021-12-01 20:16:32 +01:00
task runPreFlightScript ( type: Exec , dependsOn: environmentSetup ) {
2023-03-17 09:34:00 +05:30
def sentinel_file = ".preflight_sentinel"
outputs . file ( sentinel_file )
2021-12-01 20:16:32 +01:00
commandLine "scripts/datahub_preflight.sh"
2023-03-17 09:34:00 +05:30
commandLine 'bash' , '-c' , "touch ${sentinel_file}"
2021-12-01 20:16:32 +01:00
}
2023-03-17 09:34:00 +05:30
task installPackageOnly ( type: Exec , dependsOn: runPreFlightScript ) {
def sentinel_file = "${venv_name}/.build_install_package_only_sentinel"
inputs . file file ( 'setup.py' )
outputs . dir ( "${venv_name}" )
outputs . file ( sentinel_file )
commandLine 'bash' , '-x' , '-c' , "${venv_name}/bin/pip install -e ."
commandLine 'bash' , '-c' , "touch ${sentinel_file}"
}
task installPackage ( type: Exec , dependsOn: installPackageOnly ) {
2021-11-30 18:01:56 -08:00
inputs . file file ( 'setup.py' )
outputs . dir ( "${venv_name}" )
2022-11-11 15:04:36 -05:00
commandLine 'bash' , '-x' , '-c' , "${venv_name}/bin/pip install -e . ${extra_pip_requirements}"
2021-05-06 22:10:49 -07:00
}
task codegen ( type: Exec , dependsOn: [ environmentSetup , installPackage , ':metadata-events:mxe-schemas:build' ] ) {
2021-11-30 18:01:56 -08:00
inputs . files ( project . fileTree ( dir: "../metadata-events/mxe-schemas/src/" , include: "**/*.avsc" ) )
outputs . dir ( 'src/datahub/metadata' )
2021-05-06 22:10:49 -07:00
commandLine 'bash' , '-c' , "source ${venv_name}/bin/activate && ./scripts/codegen.sh"
}
task install ( dependsOn: [ installPackage , codegen ] )
2021-06-03 20:33:25 -07:00
task installDev ( type: Exec , dependsOn: [ install ] ) {
2023-03-17 09:34:00 +05:30
def sentinel_file = "${venv_name}/.build_install_dev_sentinel"
2021-11-30 18:01:56 -08:00
inputs . file file ( 'setup.py' )
outputs . dir ( "${venv_name}" )
2023-03-17 09:34:00 +05:30
outputs . file ( sentinel_file )
2022-11-17 19:07:05 -05:00
commandLine 'bash' , '-c' ,
"source ${venv_name}/bin/activate && set -x && " +
"${venv_name}/bin/pip install -e .[dev] ${extra_pip_requirements} && " +
"./scripts/install-sqlalchemy-stubs.sh && " +
2023-03-17 09:34:00 +05:30
"touch ${sentinel_file}"
2021-05-06 22:10:49 -07:00
}
2021-12-05 12:22:17 -08:00
2023-03-15 21:07:30 +05:30
task installAll ( type: Exec , dependsOn: [ install ] ) {
2023-03-17 09:34:00 +05:30
def sentinel_file = "${venv_name}/.build_install_all_sentinel"
2023-03-15 21:07:30 +05:30
inputs . file file ( 'setup.py' )
outputs . dir ( "${venv_name}" )
2023-03-17 09:34:00 +05:30
outputs . file ( sentinel_file )
2023-03-15 21:07:30 +05:30
commandLine 'bash' , '-c' ,
"source ${venv_name}/bin/activate && set -x && " +
"${venv_name}/bin/pip install -e .[all] ${extra_pip_requirements} && " +
"./scripts/install-sqlalchemy-stubs.sh && " +
2023-03-17 09:34:00 +05:30
"touch ${sentinel_file}"
2023-03-15 21:07:30 +05:30
}
2022-05-02 00:18:15 -07:00
2022-02-18 09:45:45 -08:00
task modelDocGen ( type: Exec , dependsOn: [ codegen ] ) {
inputs . files (
file ( 'scripts/modeldocgen.py' ) ,
project . fileTree ( dir: "../metadata-models/docs/entities/" , include: "**/*.md" ) ,
project . fileTree ( dir: "examples/" , include: "**/*.py" ) ,
project . fileTree ( dir: "../metadata-events/mxe-schemas/src/" , include: "**/*.avsc" )
)
2022-05-02 00:18:15 -07:00
outputs . dir ( '../docs/generated/metamodel' )
2022-02-18 09:45:45 -08:00
commandLine 'bash' , '-c' , "source ${venv_name}/bin/activate && ./scripts/modeldocgen.sh"
2021-12-05 12:22:17 -08:00
}
task modelDocUpload ( type: Exec , dependsOn: [ modelDocGen ] ) {
commandLine 'bash' , '-c' , "source ${venv_name}/bin/activate && ./scripts/modeldocupload.sh"
}
2021-05-06 22:10:49 -07:00
task lint ( type: Exec , dependsOn: installDev ) {
2021-10-26 11:25:04 -07:00
/ *
The find / sed combo below is a temporary work - around for the following mypy issue with airflow 2.2 . 0 :
"venv/lib/python3.8/site-packages/airflow/_vendor/connexion/spec.py:169: error: invalid syntax" .
* /
2022-07-26 23:37:46 +00:00
commandLine 'bash' , '-c' ,
2021-10-26 11:25:04 -07:00
"find ${venv_name}/lib -path *airflow/_vendor/connexion/spec.py -exec sed -i.bak -e '169,169s/ # type: List\\[str\\]//g' {} \\; && " +
2022-11-11 15:04:36 -05:00
"source ${venv_name}/bin/activate && set -x && " +
"black --check --diff src/ tests/ examples/ && " +
"isort --check --diff src/ tests/ examples/ && " +
"flake8 --count --statistics src/ tests/ examples/ && " +
"mypy --show-traceback --show-error-codes src/ tests/ examples/"
2021-05-06 22:10:49 -07:00
}
task lintFix ( type: Exec , dependsOn: installDev ) {
2022-07-26 23:37:46 +00:00
commandLine 'bash' , '-c' ,
"source ${venv_name}/bin/activate && set -x && " +
2022-11-11 15:04:36 -05:00
"./scripts/install-sqlalchemy-stubs.sh && " +
2022-03-30 01:55:51 +05:30
"black src/ tests/ examples/ && " +
"isort src/ tests/ examples/ && " +
"flake8 src/ tests/ examples/ && " +
2022-11-11 15:04:36 -05:00
"mypy --show-traceback --show-error-codes src/ tests/ examples/"
2021-05-06 22:10:49 -07:00
}
2023-02-19 08:43:13 -08:00
task testQuick ( type: Exec , dependsOn: [ installDev , ':metadata-models:generateJsonSchema' ] ) {
2021-07-02 20:26:00 -07:00
// We can't enforce the coverage requirements if we run a subset of the tests.
2021-11-30 18:01:56 -08:00
inputs . files ( project . fileTree ( dir: "src/" , include: "**/*.py" ) )
inputs . files ( project . fileTree ( dir: "tests/" ) )
outputs . dir ( "${venv_name}" )
2023-03-24 12:40:45 +05:30
def cvg_arg = get_coverage_arg ( "quick" )
2022-07-26 23:37:46 +00:00
commandLine 'bash' , '-c' ,
2023-03-24 12:40:45 +05:30
"source ${venv_name}/bin/activate && pytest ${cvg_arg} --durations=20 -m 'not integration and not integration_batch_1 and not slow_integration' -vv --continue-on-collection-errors --junit-xml=junit.quick.xml"
2021-07-02 20:26:00 -07:00
}
2021-11-30 18:01:56 -08:00
2022-06-17 18:05:10 +05:30
task installDevTest ( type: Exec , dependsOn: [ install ] ) {
2023-03-17 09:34:00 +05:30
def sentinel_file = "${venv_name}/.build_install_dev_test_sentinel"
2021-11-30 18:01:56 -08:00
inputs . file file ( 'setup.py' )
outputs . dir ( "${venv_name}" )
2023-03-17 09:34:00 +05:30
outputs . file ( sentinel_file )
2022-07-26 23:37:46 +00:00
commandLine 'bash' , '-c' ,
2023-03-17 09:34:00 +05:30
"${venv_name}/bin/pip install -e .[dev,integration-tests] ${extra_pip_requirements} && touch ${sentinel_file}"
2021-07-14 20:02:48 -07:00
}
2021-11-30 18:01:56 -08:00
def testFile = hasProperty ( 'testFile' ) ? testFile : 'unknown'
task testSingle ( dependsOn: [ installDevTest ] ) {
doLast {
if ( testFile ! = 'unknown' ) {
2022-07-26 23:37:46 +00:00
exec {
commandLine 'bash' , '-c' ,
"source ${venv_name}/bin/activate && pytest ${testFile}"
2021-11-30 18:01:56 -08:00
}
} else {
throw new GradleException ( "No file provided. Use -PtestFile=<test_file>" )
}
}
}
2022-06-17 18:05:10 +05:30
task testIntegration ( type: Exec , dependsOn: [ installDevTest ] ) {
2023-03-24 12:40:45 +05:30
def cvg_arg = get_coverage_arg ( "int" )
2022-07-26 23:37:46 +00:00
commandLine 'bash' , '-c' ,
2023-03-24 12:40:45 +05:30
"source ${venv_name}/bin/activate && pytest ${cvg_arg} --durations=50 -m 'integration' -vv --continue-on-collection-errors --junit-xml=junit.integration.xml"
2022-06-20 21:08:37 +05:30
}
task testIntegrationBatch1 ( type: Exec , dependsOn: [ installDevTest ] ) {
2023-03-24 12:40:45 +05:30
def cvg_arg = get_coverage_arg ( "intBatch1" )
2022-07-26 23:37:46 +00:00
commandLine 'bash' , '-c' ,
2023-03-24 12:40:45 +05:30
"source ${venv_name}/bin/activate && pytest ${cvg_arg} --durations=50 -m 'integration_batch_1' -vv --continue-on-collection-errors --junit-xml=junit.integrationbatch1.xml"
2022-06-17 18:05:10 +05:30
}
task testFull ( type: Exec , dependsOn: [ installDevTest ] ) {
2022-07-26 23:37:46 +00:00
commandLine 'bash' , '-c' ,
2022-06-17 18:05:10 +05:30
"source ${venv_name}/bin/activate && pytest --durations=50 -vv --continue-on-collection-errors --junit-xml=junit.full.xml"
2021-12-09 04:26:31 +05:30
}
2022-06-17 18:05:10 +05:30
task testSlowIntegration ( type: Exec , dependsOn: [ installDevTest ] ) {
2023-03-24 12:40:45 +05:30
def cvg_arg = get_coverage_arg ( "intSlow" )
2022-07-26 23:37:46 +00:00
commandLine 'bash' , '-c' ,
2023-03-24 12:40:45 +05:30
"source ${venv_name}/bin/activate && pytest ${cvg_arg} --durations=20 -m 'slow_integration' -vv --continue-on-collection-errors --junit-xml=junit.slow.integration.xml"
2021-05-06 22:10:49 -07:00
}
2022-05-02 00:18:15 -07:00
task docGen ( type: Exec , dependsOn: [ codegen , installDevTest ] ) {
commandLine 'bash' , '-c' , "source ${venv_name}/bin/activate && ./scripts/docgen.sh"
}
2023-03-22 21:31:32 +05:30
task buildWheel ( type: Exec , dependsOn: [ install , codegen ] ) {
commandLine 'bash' , '-c' , "source ${venv_name}/bin/activate && " + 'pip install build && RELEASE_VERSION="\${RELEASE_VERSION:-0.0.0.dev1}" RELEASE_SKIP_TEST=1 RELEASE_SKIP_UPLOAD=1 ./scripts/release.sh'
}
2022-05-02 00:18:15 -07:00
2021-07-08 17:08:35 -07:00
task cleanPythonCache ( type: Exec ) {
2022-07-15 06:08:32 -04:00
commandLine 'bash' , '-c' ,
"find src tests -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete -o -type d -empty -delete"
2021-07-08 17:08:35 -07:00
}
2021-05-06 22:10:49 -07:00
build . dependsOn install
check . dependsOn lint
2021-07-02 20:26:00 -07:00
check . dependsOn testQuick
2021-05-06 22:10:49 -07:00
clean {
delete venv_name
delete 'build'
delete 'dist'
2021-11-30 18:01:56 -08:00
delete 'src/datahub/metadata'
2022-02-18 09:45:45 -08:00
delete '../docs/generated'
2022-07-15 06:08:32 -04:00
delete 'generated'
delete '.mypy_cache'
delete '.pytest_cache'
2023-03-17 09:34:00 +05:30
delete '.preflight_sentinel'
2021-05-06 22:10:49 -07:00
}
2021-07-08 17:08:35 -07:00
clean . dependsOn cleanPythonCache
2023-02-21 09:50:03 -05:00
idea {
module {
sourceDirs + = file ( 'src' )
testSourceDirs + = file ( 'tests' )
}
}