Pygradle source distribution


I am new to Gradle. I am trying to create a zip deployable package using python, gradle and setuptools. The zip archive file always generating with my source code files. My dependencies are installed in a vertual environment created under build direcotry. Python sdist plugin is not doing it’s job correctly to include dependencies as well in final zip. Could you please help me in doing it. Please find my script and build.gradle script as shown below
from future import print_function

import os
import sys
import pkg_resources
import platform

from setuptools import setup, find_packages, Command
from setuptools.command.install_egg_info import install_egg_info as _install_egg_info
from setuptools.dist import Distribution

class EntryPoints(Command):
description = ‘get entrypoints for a distribution’
user_options = [
(‘dist=’, None, ‘get entrypoints for specified distribution’),

def initialize_options(self):
self.dist = self.distribution.get_name()

def finalize_options(self):
“”“Abstract method that is required to be overwritten”""

def run(self):
req_entry_points = pkg_resources.get_entry_map(self.dist)
if req_entry_points and ‘console_scripts’ in req_entry_points:
for entry in list(req_entry_points[‘console_scripts’].values()):
print(entry, file=sys.stdout)

class install_egg_info(_install_egg_info): # noqa
“”"Override the setuptools namespace package templates.

Customizes the “nspkg.pth” files so that they’re compatible with
“–editable” packages.

See this pip issue for details:

Modifications to the original implementation are marked with CHANGED

_nspkg_tmpl = (
# CHANGED: Add the import of pkgutil needed on the last line.
“import sys, types, os, pkgutil”,
“p = os.path.join(sys._getframe(1).f_locals[‘sitedir’], *%(pth)r)”,
“ie = os.path.exists(os.path.join(p, ‘’))”,
"m = not ie and "
“sys.modules.setdefault(%(pkg)r, types.ModuleType(%(pkg)r))”,
“mp = (m or ) and m.dict.setdefault(‘path’, )”,
“(p not in mp) and mp.append§”,
# CHANGED: Fix the resulting path on the namespace packages to
# properly traverse “–editable” packages too.
“mp[:] = m and pkgutil.extend_path(mp, %(pkg)r) or mp”,
“lines for the namespace installer”

_nspkg_tmpl_multi = (
# CHANGED: Use “import” to ensure the parent package has been
# loaded before attempting to read it from sys.modules.
# This avoids a possible issue with nested namespace packages where the
# parent could be skipped due to an existing file.
‘m and import(%(parent)r) and setattr(sys.modules[%(parent)r], %(child)r, m)’,
“additional line(s) when a parent package is indicated”

class GradleDistribution(Distribution, object):

PINNED_TXT = ‘pinned.txt’

excluded_platform_packages = {}

def init(self, attrs):
attrs[‘name’] = os.getenv(‘PYGRADLE_PROJECT_NAME’)
attrs[‘version’] = os.getenv(‘PYGRADLE_PROJECT_VERSION’)
attrs[‘install_requires’] = list(self.load_pinned_deps())
super(GradleDistribution, self).init(attrs)

def get_command_class(self, command):
“”“Return a customized command class or the base one.”""
if command == ‘install_egg_info’:
return install_egg_info
elif command == ‘entrypoints’:
return EntryPoints

return super(GradleDistribution, self).get_command_class(command)

def excluded_packages(self):
platform_name = platform.system().lower()
if platform_name in self.excluded_platform_packages:
return set(pkg.lower() for pkg in self.excluded_platform_packages[platform_name])
return set()

def load_pinned_deps(self):
“”"Load a pinned.txt file.

The pinned.txt file contains a list of dependencies that this Python
project depends on. Although the PyGradle build system will ignore this
file and never install dependencies declared via this method, it is
important to declare the dependencies using this method to maintain
backwards compatibility with non-PyGradle build systems.

# calculate this only once
blacklisted = self.excluded_packages
reqs =
with open(self.PINNED_TXT) as fh:
reqs = fh.readlines()
# Don’t include the version information so that we don’t mistakenly
# introduce a version conflict issue.
for req in reqs:
if req:
name, version = req.split(’==’)
if name and name.lower() not in blacklisted:
yield name
except IOError:
raise StopIteration

package_dir={’’: ‘src’},

plugins {
id “com.linkedin.python-sdist” version “0.9.11”

apply from: “…/…/parent/build.gradle”

version ‘1.0’

project.tasks.findByName(‘installPythonRequirements’).sorted = false

dependencies {
python ‘pypi:requests:2.9.1’
python ‘pypi:pytz:2018.7’
python ‘pypi:py4j:0.10.7’
python ‘pypi:pyspark:2.4.0’

repositories {
ivy {
url ‘/home/srikanth/repo/pypi/’
layout ‘pattern’, {
artifact ‘py4j/0.10.7/’
ivy ‘py4j/0.10.7/py4j-0.10.7.ivy’

ivy {
url ‘/home/srikanth/repo/pypi/’
layout ‘pattern’, {
artifact ‘pyspark/2.4.0/pyspark-2.4.0.tar.gz’
ivy ‘pyspark/2.4.0/pyspark-2.4.0.ivy’