Silence pycharm warnings in setup.py

This commit is contained in:
Davide Andreoli 2023-11-26 08:34:14 +01:00
parent a7464e66e6
commit 0b089a5623
1 changed files with 16 additions and 9 deletions

View File

@ -24,6 +24,7 @@ def read_file(rel_path):
with open(os.path.join(script_path, rel_path)) as fp: with open(os.path.join(script_path, rel_path)) as fp:
return fp.read() return fp.read()
def cmd_output(cmd): def cmd_output(cmd):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.wait() p.wait()
@ -35,6 +36,7 @@ def cmd_output(cmd):
return '' return ''
return p.stdout.read().decode('utf-8').strip() return p.stdout.read().decode('utf-8').strip()
def get_version(rel_path): def get_version(rel_path):
for line in read_file(rel_path).splitlines(): for line in read_file(rel_path).splitlines():
if line.startswith('__version__'): if line.startswith('__version__'):
@ -90,6 +92,7 @@ elif os.path.exists(os.path.join(script_path, 'Makefile')):
# === pkg-config helper === # === pkg-config helper ===
def pkg_config(name, require, min_vers=None): def pkg_config(name, require, min_vers=None):
ver = None
try: try:
sys.stdout.write('Checking for %s: ' % name) sys.stdout.write('Checking for %s: ' % name)
@ -103,7 +106,7 @@ def pkg_config(name, require, min_vers=None):
cflags = cmd_output('pkg-config --cflags %s' % require).split() cflags = cmd_output('pkg-config --cflags %s' % require).split()
libs = cmd_output('pkg-config --libs %s' % require).split() libs = cmd_output('pkg-config --libs %s' % require).split()
return (cflags, libs) return cflags, libs
except (OSError, subprocess.CalledProcessError): except (OSError, subprocess.CalledProcessError):
raise SystemExit('Did not find %s with pkg-config.' % name) raise SystemExit('Did not find %s with pkg-config.' % name)
except AssertionError: except AssertionError:
@ -130,7 +133,7 @@ if os.getenv('CFLAGS') is not None and '-fvisibility=' in os.environ['CFLAGS']:
os.environ['CFLAGS'] += ' -fvisibility=default' os.environ['CFLAGS'] += ' -fvisibility=default'
if set(('build', 'build_ext', 'install', 'bdist', 'bdist_wheel', 'sdist')) & set(sys.argv): if {'build', 'build_ext', 'install', 'bdist', 'bdist_wheel', 'sdist'} & set(sys.argv):
# === check cython version === # === check cython version ===
sys.stdout.write('Checking for Cython: ') sys.stdout.write('Checking for Cython: ')
if USE_CYTHON: if USE_CYTHON:
@ -139,7 +142,7 @@ if set(('build', 'build_ext', 'install', 'bdist', 'bdist_wheel', 'sdist')) & set
import Cython import Cython
import Cython.Compiler.Options import Cython.Compiler.Options
except ImportError: except ImportError:
raise SystemExit('not found! Needed >= %s' % (CYTHON_MIN_VERSION)) raise SystemExit('not found! Needed >= %s' % CYTHON_MIN_VERSION)
# check min version # check min version
if Version(Cython.__version__) < Version(CYTHON_MIN_VERSION): if Version(Cython.__version__) < Version(CYTHON_MIN_VERSION):
@ -304,8 +307,8 @@ if set(('build', 'build_ext', 'install', 'bdist', 'bdist_wheel', 'sdist')) & set
ext_modules, ext_modules,
include_path=['include'], include_path=['include'],
compiler_directives={ compiler_directives={
#'c_string_type': 'unicode', # 'c_string_type': 'unicode',
#'c_string_encoding': 'utf-8', # 'c_string_encoding': 'utf-8',
'embedsignature': True, 'embedsignature': True,
'binding': True, 'binding': True,
'language_level': 2, 'language_level': 2,
@ -377,13 +380,16 @@ class CleanGenerated(Command):
if fname.endswith(('.c', '.html')) and fname != 'e_dbus.c': if fname.endswith(('.c', '.html')) and fname != 'e_dbus.c':
self.remove(os.path.join(root, fname)) self.remove(os.path.join(root, fname))
def remove(self, fullpath): @staticmethod
def remove(fullpath):
print('removing %s' % fullpath.replace(script_path, '').lstrip('/')) print('removing %s' % fullpath.replace(script_path, '').lstrip('/'))
os.remove(fullpath) os.remove(fullpath)
# === setup.py uninstall command === # === setup.py uninstall command ===
RECORD_FILE = 'installed_files-%d.%d.txt' % sys.version_info[:2] RECORD_FILE = 'installed_files-%d.%d.txt' % (sys.version_info[0], sys.version_info[1])
class Uninstall(Command): class Uninstall(Command):
description = 'remove all the installed files recorded at installation time' description = 'remove all the installed files recorded at installation time'
user_options = [] user_options = []
@ -394,7 +400,8 @@ class Uninstall(Command):
def finalize_options(self): def finalize_options(self):
pass pass
def remove_entry(self, entry): @staticmethod
def remove_entry(entry):
if os.path.isfile(entry): if os.path.isfile(entry):
try: try:
print('removing file %s' % entry) print('removing file %s' % entry)
@ -404,7 +411,7 @@ class Uninstall(Command):
return return
directory = os.path.dirname(entry) directory = os.path.dirname(entry)
while os.listdir(directory) == []: while not os.listdir(directory):
try: try:
print('removing empty directory %s' % directory) print('removing empty directory %s' % directory)
os.rmdir(directory) os.rmdir(directory)