setup.py cleanup and bugfix
parent
bc96f37531
commit
a64c661e22
23
setup.py
23
setup.py
|
@ -25,6 +25,7 @@ PKG_NAME = 'bot_z'
|
|||
VERSION = '0.1.0'
|
||||
AUTHOR = 'blallo'
|
||||
AUTHOR_EMAIL = 'blallo@autistici.org'
|
||||
BIN_PATH = 'bin/geckodriver'
|
||||
|
||||
with open('README.md') as readme_file:
|
||||
readme = readme_file.read()
|
||||
|
@ -98,11 +99,13 @@ def verify_if_superuser() -> bool:
|
|||
return _uid == 0 or _euid == 0
|
||||
|
||||
|
||||
def create_local_folder() -> None:
|
||||
def ensure_local_folder() -> None:
|
||||
"""
|
||||
Create a bin/ folder in the current package installation path.
|
||||
"""
|
||||
bin_path = pkg_resources.resource_filename(PKG_NAME, BIN_PATH)
|
||||
print("[LOCAL_FOLDER] ensuring local folder: {}".format(bin_path))
|
||||
pkg_resources.ensure_directory(bin_path)
|
||||
|
||||
|
||||
def assemble_driver_uri(
|
||||
|
@ -157,14 +160,14 @@ def download_driver_bin(uri: str, path: str) -> None:
|
|||
os.remove(filepath)
|
||||
|
||||
|
||||
def postinstall(platform: T.Optional[str]=None) -> None:
|
||||
def preinstall(platform: T.Optional[str]=None) -> None:
|
||||
"""
|
||||
Performs all the postintallation flow, donwloading in the
|
||||
right place the geckodriver binary.
|
||||
"""
|
||||
# target_path = os.path.join(os.path.abspath(os.path.curdir), 'bot_z', 'bin')
|
||||
target_path = pkg_resources.resource_filename('bot_z', 'bin')
|
||||
pkg_resources.ensure_directory(os.path.join(target_path, 'target'))
|
||||
ensure_local_folder()
|
||||
version = os.environ.get('BOTZ_GECKO_VERSION')
|
||||
gecko_uri = assemble_driver_uri(version, platform)
|
||||
print("[POSTINSTALL] gecko_uri: {}".format(gecko_uri))
|
||||
|
@ -176,6 +179,9 @@ def translate_platform_to_gecko_vers(plat: str) -> str:
|
|||
Map appropriately the platform provided on the command line
|
||||
to the one used by PEP 513.
|
||||
"""
|
||||
if plat is None:
|
||||
return None
|
||||
|
||||
PLATS = {
|
||||
"win32": "win32",
|
||||
"win-amd64": "win64",
|
||||
|
@ -194,21 +200,22 @@ def translate_platform_to_gecko_vers(plat: str) -> str:
|
|||
class CustomDevelopCommand(develop):
|
||||
"""Custom installation for development mode."""
|
||||
def run(self):
|
||||
super().run()
|
||||
print("POSTINSTALL")
|
||||
postinstall()
|
||||
preinstall()
|
||||
super().run()
|
||||
|
||||
|
||||
class CustomInstallCommand(install):
|
||||
"""Custom installation for installation mode."""
|
||||
def run(self):
|
||||
super().run()
|
||||
opts = self.distribution.get_cmdline_options()
|
||||
platform = None
|
||||
if 'bdist_wheel' in opts:
|
||||
platform = translate_platform_to_gecko_vers(
|
||||
opts['bdist_wheel'].get('plat-name')
|
||||
)
|
||||
postinstall(platform)
|
||||
preinstall(platform)
|
||||
super().run()
|
||||
|
||||
|
||||
# From: https://stackoverflow.com/a/45150383
|
||||
|
@ -246,7 +253,7 @@ setup(
|
|||
'bot_z=bot_z.cli:main'
|
||||
]
|
||||
},
|
||||
package_data = {'bot_z': ['bot_z/bin/geckodriver']},
|
||||
package_data = {'bot_z': ['bin/geckodriver']},
|
||||
include_package_data=True,
|
||||
install_requires=requirements,
|
||||
license="GLWTS Public Licence",
|
||||
|
|
Loading…
Reference in New Issue