Cleanup: reformat setup.py with Black

No functional changes.
This commit is contained in:
Sybren A. Stüvel 2021-02-16 11:51:36 +01:00
parent dd00bc9cb5
commit 1a6f54b473

155
setup.py
View File

@ -32,12 +32,14 @@ from distutils.command.install import install, INSTALL_SCHEMES
from distutils.command.install_egg_info import install_egg_info from distutils.command.install_egg_info import install_egg_info
from setuptools import setup, find_packages from setuptools import setup, find_packages
requirement_re = re.compile('[><=]+') requirement_re = re.compile("[><=]+")
sys.dont_write_bytecode = True sys.dont_write_bytecode = True
# Download wheels from pypi. The specific versions are taken from requirements.txt # Download wheels from pypi. The specific versions are taken from requirements.txt
wheels = [ wheels = [
'lockfile', 'pillarsdk', 'blender-asset-tracer', "lockfile",
"pillarsdk",
"blender-asset-tracer",
] ]
@ -55,9 +57,9 @@ class BuildWheels(Command):
description = "builds/downloads the dependencies as wheel files" description = "builds/downloads the dependencies as wheel files"
user_options = [ user_options = [
('wheels-path=', None, "wheel file installation path"), ("wheels-path=", None, "wheel file installation path"),
('deps-path=', None, "path in which dependencies are built"), ("deps-path=", None, "path in which dependencies are built"),
('cachecontrol-path=', None, "subdir of deps-path containing CacheControl"), ("cachecontrol-path=", None, "subdir of deps-path containing CacheControl"),
] ]
def initialize_options(self): def initialize_options(self):
@ -70,22 +72,23 @@ class BuildWheels(Command):
self.my_path = pathlib.Path(__file__).resolve().parent self.my_path = pathlib.Path(__file__).resolve().parent
package_path = self.my_path / self.distribution.get_name() package_path = self.my_path / self.distribution.get_name()
self.wheels_path = set_default_path(self.wheels_path, package_path / 'wheels') self.wheels_path = set_default_path(self.wheels_path, package_path / "wheels")
self.deps_path = set_default_path(self.deps_path, self.my_path / 'build/deps') self.deps_path = set_default_path(self.deps_path, self.my_path / "build/deps")
self.cachecontrol_path = set_default_path(self.cachecontrol_path, self.cachecontrol_path = set_default_path(
self.deps_path / 'cachecontrol') self.cachecontrol_path, self.deps_path / "cachecontrol"
self.bat_path = self.deps_path / 'bat' )
self.bat_path = self.deps_path / "bat"
def run(self): def run(self):
log.info('Storing wheels in %s', self.wheels_path) log.info("Storing wheels in %s", self.wheels_path)
# Parse the requirements.txt file # Parse the requirements.txt file
requirements = {} requirements = {}
with open(str(self.my_path / 'requirements.txt')) as reqfile: with open(str(self.my_path / "requirements.txt")) as reqfile:
for line in reqfile.readlines(): for line in reqfile.readlines():
line = line.strip() line = line.strip()
if not line or line.startswith('#'): if not line or line.startswith("#"):
# comments are lines that start with # only # comments are lines that start with # only
continue continue
@ -97,37 +100,45 @@ class BuildWheels(Command):
self.wheels_path.mkdir(parents=True, exist_ok=True) self.wheels_path.mkdir(parents=True, exist_ok=True)
for package in wheels: for package in wheels:
pattern = package.replace('-', '_') + '*.whl' pattern = package.replace("-", "_") + "*.whl"
if list(self.wheels_path.glob(pattern)): if list(self.wheels_path.glob(pattern)):
continue continue
self.download_wheel(requirements[package]) self.download_wheel(requirements[package])
# Build CacheControl. # Build CacheControl.
if not list(self.wheels_path.glob('CacheControl*.whl')): if not list(self.wheels_path.glob("CacheControl*.whl")):
log.info('Building CacheControl in %s', self.cachecontrol_path) log.info("Building CacheControl in %s", self.cachecontrol_path)
# self.git_clone(self.cachecontrol_path, # self.git_clone(self.cachecontrol_path,
# 'https://github.com/ionrock/cachecontrol.git', # 'https://github.com/ionrock/cachecontrol.git',
# 'v%s' % requirements['CacheControl'][1]) # 'v%s' % requirements['CacheControl'][1])
# FIXME: we need my clone until pull request #125 has been merged & released # FIXME: we need my clone until pull request #125 has been merged & released
self.git_clone(self.cachecontrol_path, self.git_clone(
'https://github.com/sybrenstuvel/cachecontrol.git', self.cachecontrol_path,
'sybren-filecache-delete-crash-fix') "https://github.com/sybrenstuvel/cachecontrol.git",
"sybren-filecache-delete-crash-fix",
)
self.build_copy_wheel(self.cachecontrol_path) self.build_copy_wheel(self.cachecontrol_path)
# Ensure that the wheels are added to the data files. # Ensure that the wheels are added to the data files.
self.distribution.data_files.append( self.distribution.data_files.append(
('blender_cloud/wheels', (str(p) for p in self.wheels_path.glob('*.whl'))) ("blender_cloud/wheels", (str(p) for p in self.wheels_path.glob("*.whl")))
) )
def download_wheel(self, requirement): def download_wheel(self, requirement):
"""Downloads a wheel from PyPI and saves it in self.wheels_path.""" """Downloads a wheel from PyPI and saves it in self.wheels_path."""
subprocess.check_call([ subprocess.check_call(
sys.executable, '-m', 'pip', [
'download', '--no-deps', sys.executable,
'--dest', str(self.wheels_path), "-m",
requirement[0] "pip",
]) "download",
"--no-deps",
"--dest",
str(self.wheels_path),
requirement[0],
]
)
def git_clone(self, workdir: pathlib.Path, git_url: str, checkout: str = None): def git_clone(self, workdir: pathlib.Path, git_url: str, checkout: str = None):
if workdir.exists(): if workdir.exists():
@ -136,24 +147,25 @@ class BuildWheels(Command):
workdir.mkdir(parents=True) workdir.mkdir(parents=True)
subprocess.check_call(['git', 'clone', git_url, str(workdir)], subprocess.check_call(
cwd=str(workdir.parent)) ["git", "clone", git_url, str(workdir)], cwd=str(workdir.parent)
)
if checkout: if checkout:
subprocess.check_call(['git', 'checkout', checkout], subprocess.check_call(["git", "checkout", checkout], cwd=str(workdir))
cwd=str(workdir))
def build_copy_wheel(self, package_path: pathlib.Path): def build_copy_wheel(self, package_path: pathlib.Path):
# Make sure no wheels exist yet, so that we know which one to copy later. # Make sure no wheels exist yet, so that we know which one to copy later.
to_remove = list((package_path / 'dist').glob('*.whl')) to_remove = list((package_path / "dist").glob("*.whl"))
for fname in to_remove: for fname in to_remove:
fname.unlink() fname.unlink()
subprocess.check_call([sys.executable, 'setup.py', 'bdist_wheel'], subprocess.check_call(
cwd=str(package_path)) [sys.executable, "setup.py", "bdist_wheel"], cwd=str(package_path)
)
wheel = next((package_path / 'dist').glob('*.whl')) wheel = next((package_path / "dist").glob("*.whl"))
log.info('copying %s to %s', wheel, self.wheels_path) log.info("copying %s to %s", wheel, self.wheels_path)
shutil.copy(str(wheel), str(self.wheels_path)) shutil.copy(str(wheel), str(self.wheels_path))
@ -163,19 +175,19 @@ class BlenderAddonBdist(bdist):
def initialize_options(self): def initialize_options(self):
super().initialize_options() super().initialize_options()
self.formats = ['zip'] self.formats = ["zip"]
self.plat_name = 'addon' # use this instead of 'linux-x86_64' or similar. self.plat_name = "addon" # use this instead of 'linux-x86_64' or similar.
self.fix_local_prefix() self.fix_local_prefix()
def fix_local_prefix(self): def fix_local_prefix(self):
"""Place data files in blender_cloud instead of local/blender_cloud.""" """Place data files in blender_cloud instead of local/blender_cloud."""
for key in INSTALL_SCHEMES: for key in INSTALL_SCHEMES:
if 'data' not in INSTALL_SCHEMES[key]: if "data" not in INSTALL_SCHEMES[key]:
continue continue
INSTALL_SCHEMES[key]['data'] = '$base' INSTALL_SCHEMES[key]["data"] = "$base"
def run(self): def run(self):
self.run_command('wheels') self.run_command("wheels")
super().run() super().run()
@ -184,7 +196,7 @@ class BlenderAddonFdist(BlenderAddonBdist):
"""Ensures that 'python setup.py fdist' creates a plain folder structure.""" """Ensures that 'python setup.py fdist' creates a plain folder structure."""
user_options = [ user_options = [
('dest-path=', None, 'addon installation path'), ("dest-path=", None, "addon installation path"),
] ]
def initialize_options(self): def initialize_options(self):
@ -198,12 +210,12 @@ class BlenderAddonFdist(BlenderAddonBdist):
filepath = self.distribution.dist_files[0][2] filepath = self.distribution.dist_files[0][2]
# if dest_path is not specified use the filename as the dest_path (minus the .zip) # if dest_path is not specified use the filename as the dest_path (minus the .zip)
assert filepath.endswith('.zip') assert filepath.endswith(".zip")
target_folder = self.dest_path or filepath[:-4] target_folder = self.dest_path or filepath[:-4]
print('Unzipping the package on {}.'.format(target_folder)) print("Unzipping the package on {}.".format(target_folder))
with zipfile.ZipFile(filepath, 'r') as zip_ref: with zipfile.ZipFile(filepath, "r") as zip_ref:
zip_ref.extractall(target_folder) zip_ref.extractall(target_folder)
@ -213,8 +225,8 @@ class BlenderAddonInstall(install):
def initialize_options(self): def initialize_options(self):
super().initialize_options() super().initialize_options()
self.prefix = '' self.prefix = ""
self.install_lib = '' self.install_lib = ""
class AvoidEggInfo(install_egg_info): class AvoidEggInfo(install_egg_info):
@ -229,34 +241,37 @@ class AvoidEggInfo(install_egg_info):
setup( setup(
cmdclass={'bdist': BlenderAddonBdist, cmdclass={
'fdist': BlenderAddonFdist, "bdist": BlenderAddonBdist,
'install': BlenderAddonInstall, "fdist": BlenderAddonFdist,
'install_egg_info': AvoidEggInfo, "install": BlenderAddonInstall,
'wheels': BuildWheels}, "install_egg_info": AvoidEggInfo,
name='blender_cloud', "wheels": BuildWheels,
description='The Blender Cloud addon allows browsing the Blender Cloud from Blender.', },
version='1.17', description="The Blender Cloud addon allows browsing the Blender Cloud from Blender.",
author='Sybren A. Stüvel', version="1.17",
author_email='sybren@stuvel.eu', author="Sybren A. Stüvel",
packages=find_packages('.'), author_email="sybren@stuvel.eu",
packages=find_packages("."),
data_files=[ data_files=[
('blender_cloud', ['README.md', 'README-flamenco.md', 'CHANGELOG.md']), ("blender_cloud", ["README.md", "README-flamenco.md", "CHANGELOG.md"]),
('blender_cloud/icons', glob.glob('blender_cloud/icons/*')), ("blender_cloud/icons", glob.glob("blender_cloud/icons/*")),
('blender_cloud/texture_browser/icons', (
glob.glob('blender_cloud/texture_browser/icons/*')) "blender_cloud/texture_browser/icons",
glob.glob("blender_cloud/texture_browser/icons/*"),
),
], ],
scripts=[], scripts=[],
url='https://developer.blender.org/diffusion/BCA/', url="https://developer.blender.org/diffusion/BCA/",
license='GNU General Public License v2 or later (GPLv2+)', license="GNU General Public License v2 or later (GPLv2+)",
platforms='', platforms="",
classifiers=[ classifiers=[
'Intended Audience :: End Users/Desktop', "Intended Audience :: End Users/Desktop",
'Operating System :: OS Independent', "Operating System :: OS Independent",
'Environment :: Plugins', "Environment :: Plugins",
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)', "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
'Programming Language :: Python', "Programming Language :: Python",
'Programming Language :: Python :: 3.5', "Programming Language :: Python :: 3.5",
], ],
zip_safe=False, zip_safe=False,
) )