Newest version of Ruud's upgrade from GitHub

This commit is contained in:
PySimpleGUI 2020-04-06 16:30:03 -04:00
parent f7f3fc915a
commit 08aa764b9b
1 changed files with 91 additions and 86 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3
version = __version__ = "4.18.0.16 Unreleased - Print and MLine.Print fixed sep char handling, popup_get_date, icon parm popup_animated, popup button size (6,1), NEW CALENDAR chooser integrated, Graph.draw_lines, color chooser set parent window, scrollable column scrollwheel fixed, autoscroll parm for Multiline.print, fixed TabGroup border width, EXPERIMENTAL Scrollable Columns"
version = __version__ = "4.18.0.17 Unreleased - Print and MLine.Print fixed sep char handling, popup_get_date, icon parm popup_animated, popup button size (6,1), NEW CALENDAR chooser integrated, Graph.draw_lines, color chooser set parent window, scrollable column scrollwheel fixed, autoscroll parm for Multiline.print, fixed TabGroup border width, EXPERIMENTAL Scrollable Columns, fix for install from GitHub"
port = 'PySimpleGUI'
@ -15314,7 +15314,6 @@ def _refresh_debugger():
# 888 888 888 .d888888 888 888 888
# 888 888 888 888 888 888 888 888
# 888 888 888 "Y888888 888 888 888
import sys
import site
import shutil
@ -15328,24 +15327,24 @@ import urllib.error
def _install(files, url=None):
"""
install one file package from GitHub
install one file package from GitHub or current directory
Parameters
----------
files : list
files to be installed
the first item (files[0]) will be used as the name of the package
optional files should be preceded wit an exclamation mark (!)
the first item (files[0]) will be used as the name of the package''
optional files should be preceded with an exclamation mark (!)
url : str
url of the location of the GitHub repository
this will start usually with https://raw.githubusercontent.com/ and end with /master/
if omitted, the files will be copied from the current directory (no GitHub)
if omitted, the files will be copied from the current directory (not GitHub)
Returns
-------
info : Info instance
with structure contains
info.package : name of the package installed
info.path : name where the package is installed in the site-packages
info.version : version of the package (obtained from <package>.py)
@ -15357,13 +15356,22 @@ def _install(files, url=None):
<package><version>.dist-info folder with the usual files METADATA, INSTALLER and RECORDS.
As the setup.py is not run, the METADATA is very limited, i.e. is contains just name and version.
If an __init__.py is in files that file will be used.
If a __init__.py is in files that file will be used.
Otherwise, an __init__/py file will be generated. In thet case, if a __version__ = statement
is found in the source file, the __version__ will be included in that __init__.py file.
Version history
---------------
version 1.0.1 2020-03-04
version 1.0.4 2020-03-29
Linux and ios versions now search in sys.path for site-packages,
wheras other platforms now use site.getsitepackages().
This is to aavoid installation in a roaming directory on Windows.
version 1.0.2 2020-03-07
modified several open calls to be compatible with Python < 3.6
multipe installation for Pythonista removed. Now installs only in site-packages
version 1.0.1 2020-03-06
now uses urllib instead of requests to avoid non standard libraries
installation for Pythonista improved
@ -15382,9 +15390,9 @@ def _install(files, url=None):
info = Info()
Pythonista = sys.platform == "ios"
if not files:
raise ValueError('no files specified')
if files[0][0] == '!':
raise ValueError('first item in files (sourcefile) may not be optional')
raise ValueError("no files specified")
if files[0][0] == "!":
raise ValueError("first item in files (sourcefile) may not be optional")
package = Path(files[0]).stem
sourcefile = files[0]
@ -15398,7 +15406,7 @@ def _install(files, url=None):
try:
with urllib.request.urlopen(url + file) as response:
page = response.read()
# page = requests.get(url + file)
file_contents[file] = page
exists = True
except urllib.error.URLError:
@ -15429,96 +15437,93 @@ def _install(files, url=None):
info.files_copied = list(file_contents.keys())
info.package = package
info.version = version
paths = []
file = '__init__.py'
file = "__init__.py"
if file not in file_contents:
file_contents[file] = ("from ." + package + " import *\n").encode()
if version != 'unknown':
if version != "unknown":
file_contents[file] += ("from ." + package + " import __version__\n").encode()
if sys.platform.startswith('linux') or (sys.platform == 'ios'):
search_in = sys.path
else:
search_in = site.getsitepackages()
for f in search_in:
sitepackages_path = Path(f)
if sitepackages_path.name == "site-packages" and sitepackages_path.is_dir():
break
else:
raise ModuleNotFoundError("can't find the site-packages folder")
path = sitepackages_path / package
info.path = str(path)
if path.is_file():
path.unlink()
if not path.is_dir():
path.mkdir()
for file, contents in file_contents.items():
with (path / file).open("wb") as f:
f.write(contents)
if Pythonista:
cwd = Path.cwd()
parts1 = []
for part in cwd.parts:
parts1.append(part)
if part == "Documents":
break
else:
raise EnvironmentError("unable to install")
sitepackages_paths = [Path(*parts1) / ("site-packages" + ver) for ver in ("", "-2", "-3")]
pypi_packages = sitepackages_path / ".pypi_packages"
config = configparser.ConfigParser()
config.read(pypi_packages)
config[package] = {}
config[package]["url"] = "github"
config[package]["version"] = version
config[package]["summary"] = ""
config[package]["files"] = path.as_posix()
config[package]["dependency"] = ""
with pypi_packages.open("w") as f:
config.write(f)
else:
sitepackages_paths = [Path(site.getsitepackages()[-1])]
for entry in sitepackages_path.glob("*"):
if entry.is_dir():
if entry.stem.startswith(package) and entry.suffix == ".dist-info":
shutil.rmtree(entry)
path_distinfo = Path(str(path) + "-" + version + ".dist-info")
if not path_distinfo.is_dir():
path_distinfo.mkdir()
with (path_distinfo / "METADATA").open("w") as f: # make a dummy METADATA file
f.write("Name: " + package + "\n")
f.write("Version: " + version + "\n")
for sitepackages_path in sitepackages_paths:
with (path_distinfo / "INSTALLER").open("w") as f: # make a dummy METADATA file
f.write("github\n")
with (path_distinfo / "RECORD").open("w") as f:
pass # just to create the file to be recorded
path = sitepackages_path / package
paths.append(str(path))
with (path_distinfo / "RECORD").open("w") as record_file:
if not path.is_dir():
path.mkdir()
for p in (path, path_distinfo):
for file in p.glob("**/*"):
for file, contents in file_contents.items():
with open(path / file, "wb") as f:
f.write(contents)
if file.is_file():
name = file.relative_to(sitepackages_path).as_posix() # make sure we have slashes
record_file.write(name + ",")
if Pythonista:
pypi_packages = sitepackages_path / '.pypi_packages'
config = configparser.ConfigParser()
config.read(pypi_packages)
config[package] = {}
config[package]['url'] = 'github'
config[package]['version'] = version
config[package]['summary'] = ''
config[package]['files'] = path.as_posix()
config[package]['dependency'] = ''
with pypi_packages.open('w') as f:
config.write(f)
else:
for entry in sitepackages_path.glob("*"):
if entry.is_dir():
if entry.stem.startswith(package) and entry.suffix == ".dist-info":
shutil.rmtree(entry)
path_distinfo = Path(str(path) + "-" + version + ".dist-info")
if not path_distinfo.is_dir():
path_distinfo.mkdir()
with open(path_distinfo / "METADATA", "w") as f: # make a dummy METADATA file
f.write("Name: " + package + "\n")
f.write("Version: " + version + "\n")
if (file.stem == "RECORD" and p == path_distinfo) or ("__pycache__" in name.lower()):
record_file.write(",")
else:
with file.open("rb") as f:
file_contents = f.read()
hash = "sha256=" + base64.urlsafe_b64encode(
hashlib.sha256(file_contents).digest()
).decode("latin1").rstrip("=")
# hash calculation derived from wheel.py in pip
with open(path_distinfo / "INSTALLER", "w") as f: # make a dummy METADATA file
f.write("github\n")
with open(path_distinfo / "RECORD", "w") as f:
pass # just to create the file to be recorded
length = str(len(file_contents))
record_file.write(hash + "," + length)
with open(path_distinfo / "RECORD", "w") as record_file:
record_file.write("\n")
for p in (path, path_distinfo):
for file in p.glob("**/*"):
if file.is_file():
name = file.relative_to(sitepackages_path).as_posix() # make sure we have slashes
record_file.write(name + ",")
if (file.stem == "RECORD" and p == path_distinfo) or ("__pycache__" in name.lower()):
record_file.write(",")
else:
with open(file, "rb") as f:
file_contents = f.read()
hash = "sha256=" + base64.urlsafe_b64encode(
hashlib.sha256(file_contents).digest()
).decode("latin1").rstrip("=")
# hash calculation derived from wheel.py in pip
length = str(len(file_contents))
record_file.write(hash + "," + length)
record_file.write("\n")
info.path = ','.join(paths)
return info
def _upgrade_from_github():
info = _install(
files="PySimpleGUI.py !init.py".split(), url="https://raw.githubusercontent.com/PySimpleGUI/PySimpleGUI/master/"