fix flake8 issues

This commit is contained in:
Mohamed El-Zeneiny 2023-03-27 18:06:28 -04:00
commit bc512fcc1d

120
build.py
View file

@ -1,24 +1,23 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from pybuilder.core import * from pybuilder.core import task, dependents, depends, use_plugin, init
from enum import Enum from enum import Enum
import glob import glob
import shutil import shutil
import warnings
import sys import sys
import os import os
import subprocess import subprocess
use_plugin("python.core") use_plugin("python.core")
#use_plugin("python.unittest") # use_plugin("python.unittest")
use_plugin("python.flake8") use_plugin("python.flake8")
use_plugin("python.coverage") use_plugin("python.coverage")
use_plugin("exec") use_plugin("exec")
name = "youtube-dl" name = "youtube-dl"
default_task = ["clean","build"] default_task = ["clean", "build"]
version = "0.0.0" version = "0.0.0"
OS = Enum('OS',['Linux','MacOS', 'Windows']) OS = Enum('OS', ['Linux', 'MacOS', 'Windows'])
@init @init
@ -26,7 +25,7 @@ def set_properties(project):
project.set_property("dir_source_main_python", "youtube_dl") project.set_property("dir_source_main_python", "youtube_dl")
project.set_property("dir_source_unittest_python", "test") project.set_property("dir_source_unittest_python", "test")
project.set_property("dir_source_main_scripts", "devscripts") project.set_property("dir_source_main_scripts", "devscripts")
#project.set_property("unittest_module_glob", "test*") # project.set_property("unittest_module_glob", "test*")
project.set_property('coverage_break_build', False) project.set_property('coverage_break_build', False)
sys.path.append("./youtube_dl") sys.path.append("./youtube_dl")
from version import __version__ from version import __version__
@ -39,26 +38,27 @@ def set_properties(project):
elif sys.platform == "win32": elif sys.platform == "win32":
type = OS.Windows type = OS.Windows
project.os = type project.os = type
def delete(logger, path): def delete(logger, path):
if (os.path.exists(path)): if (os.path.exists(path)):
logger.info("Deleting: " + path) logger.info("Deleting: " + path)
if (os.path.isfile(path)): if (os.path.isfile(path)):
os.remove(path) os.remove(path)
elif (os.path.isdir(path)): elif (os.path.isdir(path)):
shutil.rmtree(path) shutil.rmtree(path)
@task
@task
def clean(logger, project): def clean(logger, project):
delete_patterns = [ delete_patterns = [
"*/__pycache__", "*/__pycache__",
"*/testdata", "*/testdata",
"*.pyc", "*.pyc",
"*.class", "*.class",
"*.dump", "*.dump",
"*.part*", "*.part*",
"*.ytdl", "*.ytdl",
"*.info.json", "*.info.json",
"*.mp4", "*.mp4",
"*.m4a", "*.m4a",
@ -73,37 +73,37 @@ def clean(logger, project):
"*.swf", "*.swf",
"*.jpg", "*.jpg",
"*.png", "*.png",
] ]
for pat in delete_patterns: for pat in delete_patterns:
for file in glob.glob(pat): for file in glob.glob(pat):
delete(logger, file) delete(logger, file)
delete_files = [ delete_files = [
'youtube-dl.1.temp.md', 'youtube-dl.1.temp.md',
'youtube-dl.1', 'youtube-dl.1',
'youtube-dl.bash-completion', 'youtube-dl.bash-completion',
'README.txt', 'README.txt',
'MANIFEST', 'MANIFEST',
'build/', 'build/',
'dist/', 'dist/',
'.coverage', '.coverage',
'cover/', 'cover/',
'youtube-dl.tar.gz', 'youtube-dl.tar.gz',
'youtube-dl.zsh', 'youtube-dl.zsh',
'youtube-dl.fish', 'youtube-dl.fish',
'youtube_dl/extractor/lazy_extractors.py', 'youtube_dl/extractor/lazy_extractors.py',
'CONTRIBUTING.md.tmp', 'CONTRIBUTING.md.tmp',
'youtube-dl', 'youtube-dl',
'youtube-dl.exe' 'youtube-dl.exe'
] ]
for file in delete_files: for file in delete_files:
delete(logger, file) delete(logger, file)
@task @task
## build for the current operating system # build for the current operating system
def build(logger, project): def build(logger, project):
if (project.os == OS.Linux or project.os == OS.MacOS): if (project.os == OS.Linux or project.os == OS.MacOS):
buildUnix(logger, project) buildUnix(logger, project)
@ -120,23 +120,25 @@ def mkdir_p(path):
except FileExistsError: except FileExistsError:
pass pass
@task @task
@dependents("installUnix") @dependents("installUnix")
def buildUnix(logger, project): def buildUnix(logger, project):
logger.info(project.version) logger.info(project.version)
mkdir_p("zip") mkdir_p("zip")
source_dirs = [ source_dirs = [
"youtube_dl", "youtube_dl/downloader", "youtube_dl/extractor", "youtube_dl/postprocessor" "youtube_dl", "youtube_dl/downloader", "youtube_dl/extractor", "youtube_dl/postprocessor"
] ]
for dir in source_dirs: for dir in source_dirs:
mkdir_p("zip/"+dir) mkdir_p("zip/" + dir)
subprocess.run("cp -pPr "+dir+"/*.py zip/"+dir+"/", shell=True) 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("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("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("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("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) 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 @task
@depends("buildUnix") @depends("buildUnix")
def installUnix(logger, project): def installUnix(logger, project):
@ -144,7 +146,7 @@ def installUnix(logger, project):
BINDIR = f"{PREFIX}/bin" BINDIR = f"{PREFIX}/bin"
MANDIR = f"{PREFIX}/man" MANDIR = f"{PREFIX}/man"
SHAREDIR = f"{PREFIX}/share" SHAREDIR = f"{PREFIX}/share"
#SYSCONFDIR = f"$(shell if [ $(PREFIX) = /usr -o $(PREFIX) = /usr/local ]; then echo /etc; else echo $(PREFIX)/etc; fi) # SYSCONFDIR = f"$(shell if [ $(PREFIX) = /usr -o $(PREFIX) = /usr/local ]; then echo /etc; else echo $(PREFIX)/etc; fi)
SYSCONFDIR = "" SYSCONFDIR = ""
DESTDIR = "" DESTDIR = ""
@ -158,36 +160,38 @@ def installUnix(logger, project):
install -d {DESTDIR}{SHAREDIR}/zsh/site-functions\ install -d {DESTDIR}{SHAREDIR}/zsh/site-functions\
install -m 644 youtube-dl.zsh {DESTDIR}{SHAREDIR}/zsh/site-functions/_youtube-dl\ install -m 644 youtube-dl.zsh {DESTDIR}{SHAREDIR}/zsh/site-functions/_youtube-dl\
install -d {DESTDIR}{SYSCONFDIR}/fish/completions\ install -d {DESTDIR}{SYSCONFDIR}/fish/completions\
install -m 644 youtube-dl.fish {DESTDIR}{SYSCONFDIR}/fish/completions/youtube-dl.fish", install -m 644 youtube-dl.fish {DESTDIR}{SYSCONFDIR}/fish/completions/youtube-dl.fish",
shell=True) shell=True)
@task @task
def buildWin32(logger, project): def buildWin32(logger, project):
subprocess.run("python -m setup.py py2exe") subprocess.run("python -m setup.py py2exe")
@task
def offlinetest(logger,project): @task
def offlinetest(logger, project):
res = subprocess.run("python -m nose --verbose test \ res = subprocess.run("python -m nose --verbose test \
--exclude test_age_restriction.py \ --exclude test_age_restriction.py \
--exclude test_download.py \ --exclude test_download.py \
--exclude test_iqiyi_sdk_interpreter.py \ --exclude test_iqiyi_sdk_interpreter.py \
--exclude test_socks.py \ --exclude test_socks.py \
--exclude test_subtitles.py \ --exclude test_subtitles.py \
--exclude test_write_annotations.py \ --exclude test_write_annotations.py \
--exclude test_youtube_lists.py \ --exclude test_youtube_lists.py \
--exclude test_youtube_signature.py", --exclude test_youtube_signature.py",
shell=True) shell=True)
if (res.returncode != 0): if (res.returncode != 0):
sys.exit(res.returncode) sys.exit(res.returncode)
@task
@task
def test(logger, project): def test(logger, project):
res = subprocess.run("nosetests --with-coverage \ res = subprocess.run("nosetests --with-coverage \
--cover-package=youtube_dl \ --cover-package=youtube_dl \
--cover-html \ --cover-html \
--verbose \ --verbose \
--processes 4 test", --processes 4 test",
shell=True) shell=True)
if (res.returncode != 0): if (res.returncode != 0):
sys.exit(res.returncode) sys.exit(res.returncode)