From bd75a6b1cef33ae8f5f31be94ce80b30a7615330 Mon Sep 17 00:00:00 2001 From: Mohamed El-Zeneiny Date: Mon, 20 Mar 2023 23:37:25 -0400 Subject: [PATCH] Working on pybuilder flow, main build + unittests working --- build.py | 165 +++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 3 + setup.py | 0 3 files changed, 168 insertions(+) create mode 100644 build.py create mode 100644 pyproject.toml mode change 100644 => 100755 setup.py diff --git a/build.py b/build.py new file mode 100644 index 000000000..1c22121ad --- /dev/null +++ b/build.py @@ -0,0 +1,165 @@ +# -*- coding: utf-8 -*- +from pybuilder.core import use_plugin, init, task +from enum import Enum +import glob +import shutil +import warnings +import sys +import os +import subprocess + +use_plugin("python.core") +#use_plugin("python.unittest") +use_plugin("python.flake8") +use_plugin("python.coverage") +use_plugin("exec") + +name = "youtube-dl" +default_task = ["clean", "analyze","offlinetest","build"] +version = "0.0.0" + +OS = Enum('OS',['Linux','MacOS', 'Windows']) + + +@init +def set_properties(project): + project.set_property("dir_source_main_python", "youtube_dl") + project.set_property("dir_source_unittest_python", "test") + project.set_property("dir_source_main_scripts", "devscripts") + #project.set_property("unittest_module_glob", "test*") + project.set_property('coverage_break_build', False) + sys.path.append("./youtube_dl") + from version import __version__ + project.version = __version__ + type = OS.Linux + if sys.platform == "linux" or sys.platform == "linux2": + type = OS.Linux + elif sys.platform == "darwin": + type = OS.MacOS + elif sys.platform == "win32": + type = OS.Windows + project.os = type + + +def delete(logger, path): + if (os.path.exists(path)): + logger.info("Deleting: " + path) + if (os.path.isfile(path)): + os.remove(path) + elif (os.path.isdir(path)): + shutil.rmtree(path) + +@task +def clean(logger, project): + delete_patterns = [ + "*/__pycache__", + "*/testdata", + "*.pyc", + "*.class", + "*.dump", + "*.part*", + "*.ytdl", + "*.info.json", + "*.mp4", + "*.m4a", + "*.flv", + "*.mp3", + "*.avi", + "*.mkv", + "*.webm", + "*.3gp", + "*.wav", + "*.ape", + "*.swf", + "*.jpg", + "*.png", + ] + + for pat in delete_patterns: + for file in glob.glob(pat): + delete(logger, file) + + delete_files = [ + 'youtube-dl.1.temp.md', + 'youtube-dl.1', + 'youtube-dl.bash-completion', + 'README.txt', + 'MANIFEST', + 'build/', + 'dist/', + '.coverage', + 'cover/', + 'youtube-dl.tar.gz', + 'youtube-dl.zsh', + 'youtube-dl.fish', + 'youtube_dl/extractor/lazy_extractors.py', + 'CONTRIBUTING.md.tmp', + 'youtube-dl', + 'youtube-dl.exe' + ] + + for file in delete_files: + delete(logger, file) + + +@task +## build for the current operating system +def build(logger, project): + if (project.os == OS.Linux or project.os == OS.MacOS): + buildUnix(logger, project) + elif project.os == OS.Windows: + buildWin32(logger, project) + else: + logger.error("Operating system detection failed, please manually select an OS to build for!") + logger.error("$ pyb buildUnix or $ pyb buildWin32") + + +def mkdir_p(path): + try: + return os.mkdir(path) + except FileExistsError: + pass + +@task +def buildUnix(logger, project): + logger.info(project.version) + mkdir_p("zip") + source_dirs = [ + "youtube_dl", "youtube_dl/downloader", "youtube_dl/extractor", "youtube_dl/postprocessor" + ] + for dir in source_dirs: + mkdir_p("zip/"+dir) + subprocess.run("cp -pPr "+dir+"/*.py zip/"+dir+"/", shell=True) + subprocess.run("touch -t 200001010101 zip/youtube_dl/*.py zip/youtube_dl/*/*.py", shell=True) + subprocess.run("mv zip/youtube_dl/__main__.py zip/",shell=True) + subprocess.run("cd zip ; zip -q ../youtube-dl youtube_dl/*.py youtube_dl/*/*.py __main__.py",shell=True) + subprocess.run("rm -rf zip", shell=True) + subprocess.run("echo '#!/usr/bin/env python' > youtube-dl ; cat youtube-dl.zip >> youtube-dl ; rm youtube-dl.zip; chmod a+x youtube-dl", shell=True) + + +@task +def buildWin32(logger, project): + subprocess.run("python -m setup.py py2exe") + +@task +def offlinetest(logger,project): + subprocess.run("python -m nose --verbose test \ + --exclude test_age_restriction.py \ + --exclude test_download.py \ + --exclude test_iqiyi_sdk_interpreter.py \ + --exclude test_socks.py \ + --exclude test_subtitles.py \ + --exclude test_write_annotations.py \ + --exclude test_youtube_lists.py \ + --exclude test_youtube_signature.py", + shell=True) + +@task +def test(logger, project): + subprocess.run("nosetests --with-coverage \ + --cover-package=youtube_dl \ + --cover-html \ + --verbose \ + --processes 4 test", + shell=True) + \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..950f54989 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["pybuilder>=0.12.0"] +build-backend = "pybuilder.pep517" diff --git a/setup.py b/setup.py old mode 100644 new mode 100755