mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
remove unneeded namespace code from install_pyqt5/6.py
This commit is contained in:
parent
44d3584071
commit
424bb5bc68
2 changed files with 6 additions and 79 deletions
|
@ -2,9 +2,7 @@
|
||||||
# MIT
|
# MIT
|
||||||
|
|
||||||
"""downloads and parses info of a pkg and generates a BUILD file for it"""
|
"""downloads and parses info of a pkg and generates a BUILD file for it"""
|
||||||
import argparse
|
|
||||||
import glob
|
import glob
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -12,17 +10,6 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pip._internal.commands import create_command
|
from pip._internal.commands import create_command
|
||||||
from pip._vendor import pkg_resources
|
|
||||||
|
|
||||||
|
|
||||||
def _create_nspkg_init(dirpath):
|
|
||||||
"""Creates an init file to enable namespacing"""
|
|
||||||
if not os.path.exists(dirpath):
|
|
||||||
# Handle missing namespace packages by ignoring them
|
|
||||||
return
|
|
||||||
nspkg_init = os.path.join(dirpath, "__init__.py")
|
|
||||||
with open(nspkg_init, "w") as nspkg:
|
|
||||||
nspkg.write("__path__ = __import__('pkgutil').extend_path(__path__, __name__)")
|
|
||||||
|
|
||||||
|
|
||||||
def install_package(pkg, directory, pip_args):
|
def install_package(pkg, directory, pip_args):
|
||||||
|
@ -49,30 +36,6 @@ def install_package(pkg, directory, pip_args):
|
||||||
cmd = create_command("install")
|
cmd = create_command("install")
|
||||||
cmd.main(pip_args)
|
cmd.main(pip_args)
|
||||||
|
|
||||||
# need dist-info directory for pkg_resources to be able to find the packages
|
|
||||||
dist_info = glob.glob(os.path.join(directory, "*.dist-info"))[0]
|
|
||||||
# fix namespace packages by adding proper __init__.py files
|
|
||||||
namespace_packages = os.path.join(dist_info, "namespace_packages.txt")
|
|
||||||
if os.path.exists(namespace_packages):
|
|
||||||
with open(namespace_packages) as nspkg:
|
|
||||||
for line in nspkg.readlines():
|
|
||||||
namespace = line.strip().replace(".", os.sep)
|
|
||||||
if namespace:
|
|
||||||
_create_nspkg_init(os.path.join(directory, namespace))
|
|
||||||
|
|
||||||
# PEP 420 -- Implicit Namespace Packages
|
|
||||||
if (sys.version_info[0], sys.version_info[1]) >= (3, 3):
|
|
||||||
for dirpath, dirnames, filenames in os.walk(directory):
|
|
||||||
# we are only interested in dirs with no init file
|
|
||||||
if "__init__.py" in filenames:
|
|
||||||
dirnames[:] = []
|
|
||||||
continue
|
|
||||||
# remove bin and dist-info dirs
|
|
||||||
for ignored in ("bin", os.path.basename(dist_info)):
|
|
||||||
if ignored in dirnames:
|
|
||||||
dirnames.remove(ignored)
|
|
||||||
_create_nspkg_init(dirpath)
|
|
||||||
|
|
||||||
def _cleanup(directory, pattern):
|
def _cleanup(directory, pattern):
|
||||||
for p in glob.glob(os.path.join(directory, pattern)):
|
for p in glob.glob(os.path.join(directory, pattern)):
|
||||||
shutil.rmtree(p)
|
shutil.rmtree(p)
|
||||||
|
@ -149,6 +112,9 @@ def main():
|
||||||
merge_files(base, folder)
|
merge_files(base, folder)
|
||||||
shutil.rmtree(folder)
|
shutil.rmtree(folder)
|
||||||
|
|
||||||
|
with open(os.path.join(base, "__init__.py"), "w") as file:
|
||||||
|
file.write("__path__ = __import__('pkgutil').extend_path(__path__, __name__)")
|
||||||
|
|
||||||
# add missing py.typed file
|
# add missing py.typed file
|
||||||
with open(os.path.join(base, "py.typed"), "w") as file:
|
with open(os.path.join(base, "py.typed"), "w") as file:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -2,9 +2,7 @@
|
||||||
# MIT
|
# MIT
|
||||||
|
|
||||||
"""downloads and parses info of a pkg and generates a BUILD file for it"""
|
"""downloads and parses info of a pkg and generates a BUILD file for it"""
|
||||||
import argparse
|
|
||||||
import glob
|
import glob
|
||||||
import logging
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -12,18 +10,6 @@ import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pip._internal.commands import create_command
|
from pip._internal.commands import create_command
|
||||||
from pip._vendor import pkg_resources
|
|
||||||
|
|
||||||
|
|
||||||
def _create_nspkg_init(dirpath):
|
|
||||||
"""Creates an init file to enable namespacing"""
|
|
||||||
if not os.path.exists(dirpath):
|
|
||||||
# Handle missing namespace packages by ignoring them
|
|
||||||
return
|
|
||||||
nspkg_init = os.path.join(dirpath, "__init__.py")
|
|
||||||
with open(nspkg_init, "w") as nspkg:
|
|
||||||
nspkg.write("__path__ = __import__('pkgutil').extend_path(__path__, __name__)")
|
|
||||||
|
|
||||||
|
|
||||||
def install_package(pkg, directory, pip_args):
|
def install_package(pkg, directory, pip_args):
|
||||||
"""Downloads wheel for a package. Assumes python binary provided has
|
"""Downloads wheel for a package. Assumes python binary provided has
|
||||||
|
@ -49,39 +35,11 @@ def install_package(pkg, directory, pip_args):
|
||||||
cmd = create_command("install")
|
cmd = create_command("install")
|
||||||
cmd.main(pip_args)
|
cmd.main(pip_args)
|
||||||
|
|
||||||
# need dist-info directory for pkg_resources to be able to find the packages
|
|
||||||
dist_info = glob.glob(os.path.join(directory, "*.dist-info"))[0]
|
|
||||||
# fix namespace packages by adding proper __init__.py files
|
|
||||||
namespace_packages = os.path.join(dist_info, "namespace_packages.txt")
|
|
||||||
if os.path.exists(namespace_packages):
|
|
||||||
with open(namespace_packages) as nspkg:
|
|
||||||
for line in nspkg.readlines():
|
|
||||||
namespace = line.strip().replace(".", os.sep)
|
|
||||||
if namespace:
|
|
||||||
_create_nspkg_init(os.path.join(directory, namespace))
|
|
||||||
|
|
||||||
# PEP 420 -- Implicit Namespace Packages
|
|
||||||
if (sys.version_info[0], sys.version_info[1]) >= (3, 3):
|
|
||||||
for dirpath, dirnames, filenames in os.walk(directory):
|
|
||||||
# we are only interested in dirs with no init file
|
|
||||||
if "__init__.py" in filenames:
|
|
||||||
dirnames[:] = []
|
|
||||||
continue
|
|
||||||
# remove bin and dist-info dirs
|
|
||||||
for ignored in ("bin", os.path.basename(dist_info)):
|
|
||||||
if ignored in dirnames:
|
|
||||||
dirnames.remove(ignored)
|
|
||||||
_create_nspkg_init(dirpath)
|
|
||||||
|
|
||||||
|
|
||||||
def _cleanup(directory, pattern):
|
def _cleanup(directory, pattern):
|
||||||
for p in glob.glob(os.path.join(directory, pattern)):
|
for p in glob.glob(os.path.join(directory, pattern)):
|
||||||
shutil.rmtree(p)
|
shutil.rmtree(p)
|
||||||
|
|
||||||
|
|
||||||
fix_none = re.compile(r"(\s*None) =")
|
|
||||||
|
|
||||||
|
|
||||||
def copy_and_fix_pyi(source, dest):
|
def copy_and_fix_pyi(source, dest):
|
||||||
"Fix broken PyQt types."
|
"Fix broken PyQt types."
|
||||||
with open(source) as input_file:
|
with open(source) as input_file:
|
||||||
|
@ -151,6 +109,9 @@ def main():
|
||||||
merge_files(base, folder)
|
merge_files(base, folder)
|
||||||
shutil.rmtree(folder)
|
shutil.rmtree(folder)
|
||||||
|
|
||||||
|
with open(os.path.join(base, "__init__.py"), "w") as file:
|
||||||
|
file.write("__path__ = __import__('pkgutil').extend_path(__path__, __name__)")
|
||||||
|
|
||||||
# add missing py.typed file
|
# add missing py.typed file
|
||||||
with open(os.path.join(base, "py.typed"), "w") as file:
|
with open(os.path.join(base, "py.typed"), "w") as file:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue