Run mypy on all packages' files

Also:
- mypy fixes.
- Use `with` statement to open/close files.
This commit is contained in:
Nicola Soranzo
2022-05-30 22:38:55 +01:00
parent d3719517e7
commit f2a42ba67e
24 changed files with 164 additions and 84 deletions
+14 -10
View File
@@ -6,27 +6,31 @@ import re
import subprocess
import sys
DEV_RELEASE = os.environ.get("DEV_RELEASE", None) == "1"
PROJECT_DIRECTORY = os.getcwd()
PROJECT_DIRECTORY_NAME = os.path.basename(os.path.abspath(PROJECT_DIRECTORY))
PROJECT_MODULE_FILENAME = f"project_galaxy_{PROJECT_DIRECTORY_NAME}.py"
PROJECT_NAME = PROJECT_DIRECTORY_NAME.replace("_", "-")
def main(argv):
DEV_RELEASE = os.environ.get("DEV_RELEASE", None) == "1"
PROJECT_DIRECTORY = os.getcwd()
PROJECT_DIRECTORY_NAME = os.path.basename(os.path.abspath(PROJECT_DIRECTORY))
PROJECT_MODULE_FILENAME = f"project_galaxy_{PROJECT_DIRECTORY_NAME}.py"
PROJECT_NAME = PROJECT_DIRECTORY_NAME.replace("_", "-")
source_dir = argv[1]
version = argv[2]
mod_path = os.path.join(PROJECT_DIRECTORY, source_dir, PROJECT_MODULE_FILENAME)
if not DEV_RELEASE:
history_path = os.path.join(PROJECT_DIRECTORY, "HISTORY.rst")
history = open(history_path).read()
with open(history_path) as f:
history = f.read()
today = datetime.datetime.today()
today_str = today.strftime("%Y-%m-%d")
history = history.replace(".dev0", f" ({today_str})")
open(history_path, "w").write(history)
mod = open(mod_path).read()
with open(history_path, "w") as f:
f.write(history)
with open(mod_path) as f:
mod = f.read()
mod = re.sub(r"__version__ = '[\d\.]*\.dev\d+'", f"__version__ = '{version}'", mod)
mod = open(mod_path, "w").write(mod)
with open(mod_path, "w") as f:
f.write(mod)
tag = f"galaxy-{PROJECT_NAME}-{version}"
shell(["git", "commit", "-m", f"Version {version} of {PROJECT_NAME} (tag {tag}).", "HISTORY.rst", mod_path])
shell(["git", "tag", tag])