Update build process.
This commit is contained in:
parent
43057351b9
commit
9ecea804c9
92
Makefile
92
Makefile
|
@ -1,40 +1,16 @@
|
||||||
.PHONY: clean clean-test clean-pyc clean-build docs help
|
.PHONY: clean clean-test clean-pyc clean-build
|
||||||
.DEFAULT_GOAL := help
|
|
||||||
define BROWSER_PYSCRIPT
|
|
||||||
import os, webbrowser, sys
|
|
||||||
try:
|
|
||||||
from urllib import pathname2url
|
|
||||||
except:
|
|
||||||
from urllib.request import pathname2url
|
|
||||||
|
|
||||||
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1])))
|
VERSION = $(shell grep VERSION setup.py|cut -d\" -f2)
|
||||||
endef
|
|
||||||
export BROWSER_PYSCRIPT
|
|
||||||
|
|
||||||
define PRINT_HELP_PYSCRIPT
|
|
||||||
import re, sys
|
|
||||||
|
|
||||||
for line in sys.stdin:
|
|
||||||
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line)
|
|
||||||
if match:
|
|
||||||
target, help = match.groups()
|
|
||||||
print("%-20s %s" % (target, help))
|
|
||||||
endef
|
|
||||||
export PRINT_HELP_PYSCRIPT
|
|
||||||
BROWSER := python -c "$$BROWSER_PYSCRIPT"
|
|
||||||
|
|
||||||
help:
|
|
||||||
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST)
|
|
||||||
|
|
||||||
clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
|
clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts
|
||||||
|
|
||||||
|
|
||||||
clean-build: ## remove build artifacts
|
clean-build: ## remove build artifacts
|
||||||
rm -fr build/
|
rm -fr build/
|
||||||
rm -fr dist/
|
rm -fr dist/
|
||||||
rm -fr .eggs/
|
rm -fr .eggs/
|
||||||
find . -name '*.egg-info' -exec rm -fr {} +
|
find . -name '*.egg-info' -exec rm -fr {} +
|
||||||
find . -name '*.egg' -exec rm -f {} +
|
find . -name '*.egg' -exec rm -f {} +
|
||||||
|
rm -fr bot_z.web/build/
|
||||||
|
|
||||||
clean-pyc: ## remove Python file artifacts
|
clean-pyc: ## remove Python file artifacts
|
||||||
find . -name '*.pyc' -exec rm -f {} +
|
find . -name '*.pyc' -exec rm -f {} +
|
||||||
|
@ -47,41 +23,37 @@ clean-test: ## remove test and coverage artifacts
|
||||||
rm -f .coverage
|
rm -f .coverage
|
||||||
rm -fr htmlcov/
|
rm -fr htmlcov/
|
||||||
|
|
||||||
lint: ## check style with flake8
|
release: clean build
|
||||||
flake8 bot_z tests
|
|
||||||
|
|
||||||
test: ## run tests quickly with the default Python
|
sdist:
|
||||||
|
|
||||||
python setup.py test
|
|
||||||
|
|
||||||
test-all: ## run tests on every Python version with tox
|
|
||||||
tox
|
|
||||||
|
|
||||||
coverage: ## check code coverage quickly with the default Python
|
|
||||||
coverage run --source bot_z setup.py test
|
|
||||||
coverage report -m
|
|
||||||
coverage html
|
|
||||||
$(BROWSER) htmlcov/index.html
|
|
||||||
|
|
||||||
docs: ## generate Sphinx HTML documentation, including API docs
|
|
||||||
rm -f docs/bot_z.rst
|
|
||||||
rm -f docs/modules.rst
|
|
||||||
sphinx-apidoc -o docs/ bot_z
|
|
||||||
$(MAKE) -C docs clean
|
|
||||||
$(MAKE) -C docs html
|
|
||||||
$(BROWSER) docs/_build/html/index.html
|
|
||||||
|
|
||||||
servedocs: docs ## compile the docs watching for changes
|
|
||||||
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .
|
|
||||||
|
|
||||||
release: clean ## package and upload a release
|
|
||||||
python setup.py sdist upload
|
|
||||||
python setup.py bdist_wheel upload
|
|
||||||
|
|
||||||
dist: clean ## builds source and wheel package
|
|
||||||
python setup.py sdist
|
python setup.py sdist
|
||||||
python setup.py bdist_wheel
|
|
||||||
ls -l dist
|
build: sdist build-linux64 build-linux32 build-win32 build-win64 build-macos
|
||||||
|
|
||||||
|
build-linux64:
|
||||||
|
python setup.py bdist_wheel --plat-name manylinux1-x86_64
|
||||||
|
|
||||||
|
sdist/bot_z-$(VERSION)-py3-none-manylinux1_x86_64.whl: build-linux64
|
||||||
|
|
||||||
|
build-linux32:
|
||||||
|
python setup.py bdist_wheel --plat-name manylinux1-i686
|
||||||
|
|
||||||
|
sdist/bot_z-$(VERSION)-py3-none-manylinux1_i686.whl: build-linux32
|
||||||
|
|
||||||
|
build-win32:
|
||||||
|
python setup.py bdist_wheel --plat-name win32
|
||||||
|
|
||||||
|
sdist/bot_z-$(VERSION)-py3-none-win32.whl: build-win32
|
||||||
|
|
||||||
|
build-win64:
|
||||||
|
python setup.py bdist_wheel --plat-name win-amd64
|
||||||
|
|
||||||
|
sdist/bot_z-$(VERSION)-py3-none-manylinux1_win-amd64.whl: build-win64
|
||||||
|
|
||||||
|
build-macos:
|
||||||
|
python setup.py bdist_wheel --plat-name macosx
|
||||||
|
|
||||||
|
sdist/bot_z-$(VERSION)-py3-none-macosx.whl: build-macos
|
||||||
|
|
||||||
install: clean ## install the package to the active Python's site-packages
|
install: clean ## install the package to the active Python's site-packages
|
||||||
python setup.py install
|
python setup.py install
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 0.1.0
|
current_version = 1.0.0
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
|
|
||||||
|
|
66
setup.py
66
setup.py
|
@ -4,28 +4,40 @@
|
||||||
"""The setup script."""
|
"""The setup script."""
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
from distutils.dir_util import copy_tree, mkpath
|
||||||
|
import glob
|
||||||
from html.parser import HTMLParser
|
from html.parser import HTMLParser
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
from setuptools import setup, find_packages # noqa
|
from pprint import pformat
|
||||||
from setuptools.command.develop import develop # noqa
|
from setuptools import setup, find_packages # type: ignore
|
||||||
from setuptools.command.install import install # noqa
|
from setuptools.command.develop import develop # type: ignore
|
||||||
from setuptools.command.bdist_egg import bdist_egg # noqa
|
from setuptools.command.install import install # type: ignore
|
||||||
|
from setuptools.command.bdist_egg import bdist_egg # type: ignore
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tarfile
|
import tarfile
|
||||||
import typing as T
|
import typing as T
|
||||||
from urllib.error import HTTPError, URLError
|
from urllib.error import HTTPError, URLError
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
from wheel.bdist_wheel import bdist_wheel # noqa
|
from wheel.bdist_wheel import bdist_wheel # type: ignore
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
|
|
||||||
GECKO_RELEASE_PATH = "https://github.com/mozilla/geckodriver"
|
GECKO_RELEASE_PATH = "https://github.com/mozilla/geckodriver"
|
||||||
PKG_NAME = "bot_z"
|
PKG_NAME = "bot_z"
|
||||||
VERSION = "0.2.1"
|
VERSION = "1.0.0"
|
||||||
AUTHOR = "blallo"
|
AUTHOR = "blallo"
|
||||||
AUTHOR_EMAIL = "blallo@autistici.org"
|
AUTHOR_EMAIL = "blallo@autistici.org"
|
||||||
BIN_PATH = "bin/geckodriver"
|
BIN_PATH = "bin/geckodriver"
|
||||||
|
ASSET_FILE_PATHS = [
|
||||||
|
"assets/*",
|
||||||
|
"assets/static/*",
|
||||||
|
"assets/static/css/*",
|
||||||
|
"assets/static/js/*",
|
||||||
|
]
|
||||||
|
|
||||||
with open("README.md") as readme_file:
|
with open("README.md") as readme_file:
|
||||||
readme = readme_file.read()
|
readme = readme_file.read()
|
||||||
|
@ -48,6 +60,42 @@ setup_requirements = [] # type: T.List[str]
|
||||||
test_requirements = [] # type: T.List[str]
|
test_requirements = [] # type: T.List[str]
|
||||||
|
|
||||||
|
|
||||||
|
def _find_javascript_pkgmgr():
|
||||||
|
pkgmgr_list = ("yarn", "npm")
|
||||||
|
for _pkgmgr in pkgmgr_list:
|
||||||
|
if shutil.which(_pkgmgr):
|
||||||
|
pkgmgr = _pkgmgr
|
||||||
|
break
|
||||||
|
|
||||||
|
if not pkgmgr:
|
||||||
|
raise RuntimeError(
|
||||||
|
"Missing javascript package manager. Allowed are: {}".format(pkgmgr_list)
|
||||||
|
)
|
||||||
|
|
||||||
|
return pkgmgr
|
||||||
|
|
||||||
|
|
||||||
|
def _find_built_assets(base_path: str):
|
||||||
|
asset_manifest = os.path.join(base_path, "build", "asset-manifest.json")
|
||||||
|
with open(asset_manifest) as f:
|
||||||
|
manifest = json.load(f)
|
||||||
|
return manifest.get("files")
|
||||||
|
|
||||||
|
|
||||||
|
def build_web():
|
||||||
|
pkgmgr = _find_javascript_pkgmgr()
|
||||||
|
webpath = "./bot.z_web" # TODO: find base path
|
||||||
|
script = f"cd {webpath} && {pkgmgr} build"
|
||||||
|
print("[BUILD_WEB] running script:\n\t{}".format(script))
|
||||||
|
subprocess.check_call(["bash", "-c", script])
|
||||||
|
assets = _find_built_assets(webpath)
|
||||||
|
print("[BUILD_WEB] built assets: {}".format(pformat(assets)))
|
||||||
|
assets_path = pkg_resources.resource_filename("api", "assets")
|
||||||
|
if not os.path.exists(assets_path):
|
||||||
|
mkpath(assets_path)
|
||||||
|
copy_tree(os.path.join(webpath, "build"), assets_path)
|
||||||
|
|
||||||
|
|
||||||
class GitTags(HTMLParser):
|
class GitTags(HTMLParser):
|
||||||
tags: T.List[str] = list()
|
tags: T.List[str] = list()
|
||||||
take_next = 0
|
take_next = 0
|
||||||
|
@ -185,6 +233,7 @@ def preinstall(platform: T.Optional[str] = None) -> None:
|
||||||
gecko_uri = assemble_driver_uri(version, platform)
|
gecko_uri = assemble_driver_uri(version, platform)
|
||||||
print("[POSTINSTALL] gecko_uri: {}".format(gecko_uri))
|
print("[POSTINSTALL] gecko_uri: {}".format(gecko_uri))
|
||||||
download_driver_bin(gecko_uri, target_path)
|
download_driver_bin(gecko_uri, target_path)
|
||||||
|
build_web()
|
||||||
|
|
||||||
|
|
||||||
def translate_platform_to_gecko_vers(plat: str) -> str:
|
def translate_platform_to_gecko_vers(plat: str) -> str:
|
||||||
|
@ -258,15 +307,14 @@ setup(
|
||||||
author=AUTHOR,
|
author=AUTHOR,
|
||||||
author_email=AUTHOR_EMAIL,
|
author_email=AUTHOR_EMAIL,
|
||||||
url="https://git.abbiamoundominio.org/blallo/BotZ",
|
url="https://git.abbiamoundominio.org/blallo/BotZ",
|
||||||
packages=find_packages(include=["bot_z"]),
|
packages=find_packages(include=["bot_z", "api"]),
|
||||||
cmdclass={
|
cmdclass={
|
||||||
"develop": CustomDevelopCommand,
|
"develop": CustomDevelopCommand,
|
||||||
"install": CustomInstallCommand,
|
"install": CustomInstallCommand,
|
||||||
"bdist_wheel": CustomBDistWheel,
|
"bdist_wheel": CustomBDistWheel,
|
||||||
},
|
},
|
||||||
entry_points={"console_scripts": ["bot_z=bot_z.cli:cli", "z_app=api.app:cli"]},
|
entry_points={"console_scripts": ["bot_z=bot_z.cli:cli", "z_app=api.app:cli"]},
|
||||||
package_data={"bot_z": ["bin/geckodriver"]},
|
package_data={"bot_z": ["bin/geckodriver"], "api": ASSET_FILE_PATHS},
|
||||||
include_package_data=True,
|
|
||||||
install_requires=requirements,
|
install_requires=requirements,
|
||||||
license="GLWTS Public Licence",
|
license="GLWTS Public Licence",
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user