Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
168 lines (139 sloc) 5.25 KB
import glob
import subprocess
from pathlib import Path
from doit.action import CmdAction
PACKAGE = "efb_fb_messenger_slave"
# major, minor, patch, alpha, beta, dev, post
"default_tasks": ["msgfmt"]
def task_gettext():
pot = f"./{PACKAGE}/locale/{PACKAGE}.pot"
sources = glob.glob("./**/*.py", recursive=True)
sources = [i for i in sources if "" not in i]
command = "xgettext --add-comments=TRANSLATORS --from-code=UTF-8 -o " + pot + " " + " ".join(sources)
return {
"actions": [
['cp', README_BASE, './.cache/README.rst'],
['sphinx-build', '-b', 'gettext', '-C', '-D', 'master_doc=README',
'-D', 'gettext_additional_targets=literal-block,image',
'./.cache', './readme_translations/locale/', './.cache/README.rst'],
['rm', './.cache/README.rst'],
"targets": [
"file_dep": sources
def task_msgfmt():
languages = [i[i.rfind('/')+1:] for i in glob.glob("./readme_translations/locale/*_*")]
sources = glob.glob("./**/*.po", recursive=True)
dests = [i[:-3] + ".mo" for i in sources]
actions = [["msgfmt", sources[i], "-o", dests[i]] for i in range(len(sources))]
actions.append(["mkdir", "./.cache/source"])
actions.append(["cp", README_BASE, "./.cache/source/README.rst"])
locale_dirs = (Path('.') / "readme_translations" / "locale").absolute()
for i in languages:
actions.append(["sphinx-build", "-E", "-b", "rst", "-C",
"-D", f"language={i}", "-D", f"locale_dirs={locale_dirs}",
"-D", "extensions=sphinxcontrib.restbuilder",
"-D", "master_doc=README", "./.cache/source", f"./.cache/{i}"])
actions.append(["mv", f"./.cache/{i}/README.rst", f"./readme_translations/{i}.rst"])
actions.append(["rm", "-rf", f"./.cache/{i}"])
actions.append(["rm", "-rf", "./.cache/source"])
return {
"actions": actions,
"targets": dests,
"file_dep": sources,
"task_dep": ['crowdin', 'crowdin_pull']
def task_crowdin():
sources = glob.glob(f"./{PACKAGE}/**/*.po", recursive=True)
return {
"actions": ["crowdin upload sources"],
"file_dep": sources,
"task_dep": ["gettext"]
def task_crowdin_pull():
return {
"actions": ["crowdin download"]
def task_commit_lang_file():
def git_actions():
if['git', 'diff-index', '--quiet', 'HEAD']).returncode != 0:
return ["git commit -S -m \"loc: sync localization files from crowdin\""]
return ["echo"]
return {
"actions": [
["git", "add", "*.po", "readme_translations/*.rst"],
"task_dep": ["crowdin", "crowdin_pull"]
def task_bump_version():
def gen_bump_version(mode=DEFAULT_BUMP_MODE):
return './ --tag ' + mode
return {
"actions": [CmdAction(gen_bump_version)],
"params": [
"name": "mode",
"short": "b",
"long": "bump",
"help": "{major}.{minor}.{patch}{(a|b)}{.post}{.dev}",
"choices": [
("major", "Bump a major version"),
("minor", "Bump a minor version"),
("patch", "Bump a patch version"),
("alpha", "Bump to the next alpha version"),
("alpha", "Bump to the next beta version"),
("post", "Bump to the next post version"),
("dev", "Bump a dev version (for commit only)")
"task_dep": ["test", "mypy", "commit_lang_file"]
def task_mypy():
# sources = glob.glob("./{package}/**/*.py".format(package=PACKAGE), recursive=True)
actions = [f"mypy -p {PACKAGE} --ignore-missing-imports"]
return {
"actions": actions
def task_test():
sources = glob.glob(f"./{PACKAGE}/**/*.py", recursive=True)
sources = [i for i in sources if "" not in i]
return {
"actions": [
f"coverage run --source ./{PACKAGE} -m pytest",
"coverage report"
"file_dep": sources
def task_build():
return {
"actions": [
f"mv {PACKAGE}.egg-info {PACKAGE}.egg-info.bak",
"python sdist bdist_wheel",
f"rm -rf build {PACKAGE}.egg-info",
f"mv {PACKAGE}.egg-info.bak {PACKAGE}.egg-info",
"task_dep": ["mypy", "test", "msgfmt", "bump_version"]
def task_publish():
def get_twine_command():
__version__ = __import__(PACKAGE).__version__
if 'dev' in __version__:
raise ValueError(f"Cannot publish dev version ({__version__}).")
binarys = glob.glob(f"./dist/*{__version__}*", recursive=True)
return " ".join(["twine", "upload"] + binarys)
return {
"actions": [CmdAction(get_twine_command)],
"task_dep": ["build"]
You can’t perform that action at this time.