add install-chromedriver v0.1.0 package code
This commit is contained in:
commit
0057426e23
63
.gitignore
vendored
Normal file
63
.gitignore
vendored
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
# Python
|
||||||
|
*.pyc
|
||||||
|
*.pyo
|
||||||
|
*.pyd
|
||||||
|
__pycache__/
|
||||||
|
*.pdb
|
||||||
|
*.cover
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Poetry
|
||||||
|
.poetry/
|
||||||
|
*.toml.lock
|
||||||
|
|
||||||
|
# Virtual Environment
|
||||||
|
venv/
|
||||||
|
env/
|
||||||
|
.env/
|
||||||
|
.venv/
|
||||||
|
|
||||||
|
# PyInstaller
|
||||||
|
/dist/
|
||||||
|
/build/
|
||||||
|
/*.spec
|
||||||
|
|
||||||
|
# Coverage
|
||||||
|
.coverage
|
||||||
|
.coverage.*
|
||||||
|
|
||||||
|
# IDEs and editors
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
*~
|
||||||
|
*.bak
|
||||||
|
|
||||||
|
# macOS
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Windows
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Jupyter Notebooks
|
||||||
|
.ipynb_checkpoints/
|
||||||
|
|
||||||
|
# Miscellaneous
|
||||||
|
*.tgz
|
||||||
|
*.tar.gz
|
||||||
|
*.egg-info/
|
||||||
|
*.egg
|
||||||
|
|
||||||
|
# Poetry build artifacts
|
||||||
|
*.whl
|
||||||
|
*.tar.gz
|
||||||
|
|
||||||
|
# pyenv
|
||||||
|
.python-version
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
.docker/
|
||||||
|
|
||||||
|
# Temporary files
|
||||||
|
*.log
|
||||||
23
pyproject.toml
Normal file
23
pyproject.toml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
[tool.poetry]
|
||||||
|
name = "install-chromedriver"
|
||||||
|
version = "0.1.0"
|
||||||
|
description = "Simple CLI utility to install the matching chromedriver to your currently installed chrome in either your PATH, or your virtualenv, if one is enabled"
|
||||||
|
authors = ["Kenny's Mom <wouldntyouliketoknow@nachoemail.com>"]
|
||||||
|
license = "MIT"
|
||||||
|
|
||||||
|
[tool.poetry.dependencies]
|
||||||
|
python = ">=3.8,<3.14"
|
||||||
|
typer = "0.9.0"
|
||||||
|
webdriver-manager = "^4.0.2"
|
||||||
|
|
||||||
|
[tool.poetry.dev-dependencies]
|
||||||
|
pyinstaller ="^6.11.1"
|
||||||
|
|
||||||
|
[tool.poetry.scripts]
|
||||||
|
install-chromedriver = "cli:app"
|
||||||
|
build-executable = "scripts:install"
|
||||||
|
build-all = "scripts:build_all"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["poetry-core>=1.0.0"]
|
||||||
|
build-backend = "poetry.core.masonry.api"
|
||||||
27
scripts.py
Normal file
27
scripts.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
def install():
|
||||||
|
HERE = Path(__file__).parent.absolute()
|
||||||
|
path_to_main = str(HERE / "src" / "cli.py")
|
||||||
|
try:
|
||||||
|
subprocess.check_call([
|
||||||
|
"pyinstaller",
|
||||||
|
"--onefile",
|
||||||
|
"--name=install-chromedriver",
|
||||||
|
path_to_main
|
||||||
|
])
|
||||||
|
print("Executable built successfully.")
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
print("PyInstaller failed.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def build_all():
|
||||||
|
# Run poetry build
|
||||||
|
subprocess.run(["poetry", "build"], check=True)
|
||||||
|
|
||||||
|
# Run the build-executable script
|
||||||
|
subprocess.run(["poetry", "run", "build-executable"], check=True)
|
||||||
0
src/__init__.py
Normal file
0
src/__init__.py
Normal file
8
src/cli.py
Normal file
8
src/cli.py
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import typer
|
||||||
|
from install_chromedriver.install_chromedriver import install_chrome
|
||||||
|
|
||||||
|
app = typer.Typer()
|
||||||
|
app.command()(install_chrome)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app()
|
||||||
3
src/install_chromedriver/__init__.py
Normal file
3
src/install_chromedriver/__init__.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
if __name__ == "__main__":
|
||||||
|
from cli import app
|
||||||
|
app()
|
||||||
30
src/install_chromedriver/install_chromedriver.py
Normal file
30
src/install_chromedriver/install_chromedriver.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import os
|
||||||
|
import pathlib
|
||||||
|
import shutil
|
||||||
|
import typer
|
||||||
|
from typing_extensions import Annotated
|
||||||
|
|
||||||
|
from webdriver_manager.chrome import ChromeDriverManager
|
||||||
|
|
||||||
|
|
||||||
|
def get_first_writable_directory(path):
|
||||||
|
|
||||||
|
path_parts = pathlib.Path(path).parts
|
||||||
|
|
||||||
|
for i in range(len(path_parts), 0, -1):
|
||||||
|
test_path = os.path.join(*path_parts[:i])
|
||||||
|
if os.access(test_path, os.W_OK):
|
||||||
|
return test_path
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def install_chrome(
|
||||||
|
path: Annotated[str, typer.Option(
|
||||||
|
help="Directory in which to install chromedriver. Defaults to current virtualenv, if in a venv, else it defaults to placing the bin in the first writable directory on your PATH.")] =
|
||||||
|
os.path.join(os.environ.get("VIRTUAL_ENV") or get_first_writable_directory(os.environ.get("PATH")),'bin')):
|
||||||
|
chromedriver_bin = os.path.join(path, 'chromedriver')
|
||||||
|
if os.path.exists(chromedriver_bin):
|
||||||
|
os.remove(chromedriver_bin)
|
||||||
|
new_bin = ChromeDriverManager().install().replace('THIRD_PARTY_NOTICES.','')
|
||||||
|
shutil.copy(new_bin, chromedriver_bin)
|
||||||
|
os.chmod(chromedriver_bin, 0o755)
|
||||||
19
src/install_chromedriver/pyinstaller.py
Normal file
19
src/install_chromedriver/pyinstaller.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import PyInstaller.__main__
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
HERE = Path(__file__).parent.absolute()
|
||||||
|
path_to_main = str(HERE / "cli.py")
|
||||||
|
|
||||||
|
|
||||||
|
def install():
|
||||||
|
PyInstaller.__main__.run([
|
||||||
|
path_to_main,
|
||||||
|
'--onefile',
|
||||||
|
'--windowed',
|
||||||
|
'--debug=all'
|
||||||
|
# other pyinstaller options...
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
install()
|
||||||
Loading…
Reference in New Issue
Block a user