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 #!/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' port = 'PySimpleGUI'
@ -15314,7 +15314,6 @@ def _refresh_debugger():
# 888 888 888 .d888888 888 888 888 # 888 888 888 .d888888 888 888 888
# 888 888 888 888 888 888 888 888 # 888 888 888 888 888 888 888 888
# 888 888 888 "Y888888 888 888 888 # 888 888 888 "Y888888 888 888 888
import sys import sys
import site import site
import shutil import shutil
@ -15328,24 +15327,24 @@ import urllib.error
def _install(files, url=None): def _install(files, url=None):
""" """
install one file package from GitHub install one file package from GitHub or current directory
Parameters Parameters
---------- ----------
files : list files : list
files to be installed files to be installed
the first item (files[0]) will be used as the name of the package the first item (files[0]) will be used as the name of the package''
optional files should be preceded wit an exclamation mark (!) optional files should be preceded with an exclamation mark (!)
url : str url : str
url of the location of the GitHub repository url of the location of the GitHub repository
this will start usually with https://raw.githubusercontent.com/ and end with /master/ 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 Returns
------- -------
info : Info instance info : Info instance
with structure contains
info.package : name of the package installed info.package : name of the package installed
info.path : name where the package is installed in the site-packages info.path : name where the package is installed in the site-packages
info.version : version of the package (obtained from <package>.py) 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. <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. 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 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. is found in the source file, the __version__ will be included in that __init__.py file.
Version history 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 now uses urllib instead of requests to avoid non standard libraries
installation for Pythonista improved installation for Pythonista improved
@ -15382,9 +15390,9 @@ def _install(files, url=None):
info = Info() info = Info()
Pythonista = sys.platform == "ios" Pythonista = sys.platform == "ios"
if not files: if not files:
raise ValueError('no files specified') raise ValueError("no files specified")
if files[0][0] == '!': if files[0][0] == "!":
raise ValueError('first item in files (sourcefile) may not be optional') raise ValueError("first item in files (sourcefile) may not be optional")
package = Path(files[0]).stem package = Path(files[0]).stem
sourcefile = files[0] sourcefile = files[0]
@ -15398,7 +15406,7 @@ def _install(files, url=None):
try: try:
with urllib.request.urlopen(url + file) as response: with urllib.request.urlopen(url + file) as response:
page = response.read() page = response.read()
# page = requests.get(url + file)
file_contents[file] = page file_contents[file] = page
exists = True exists = True
except urllib.error.URLError: except urllib.error.URLError:
@ -15429,51 +15437,48 @@ def _install(files, url=None):
info.files_copied = list(file_contents.keys()) info.files_copied = list(file_contents.keys())
info.package = package info.package = package
info.version = version info.version = version
paths = []
file = '__init__.py' file = "__init__.py"
if file not in file_contents: if file not in file_contents:
file_contents[file] = ("from ." + package + " import *\n").encode() file_contents[file] = ("from ." + package + " import *\n").encode()
if version != 'unknown': if version != "unknown":
file_contents[file] += ("from ." + package + " import __version__\n").encode() 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()
if Pythonista: for f in search_in:
cwd = Path.cwd() sitepackages_path = Path(f)
parts1 = [] if sitepackages_path.name == "site-packages" and sitepackages_path.is_dir():
for part in cwd.parts:
parts1.append(part)
if part == "Documents":
break break
else: else:
raise EnvironmentError("unable to install") raise ModuleNotFoundError("can't find the site-packages folder")
sitepackages_paths = [Path(*parts1) / ("site-packages" + ver) for ver in ("", "-2", "-3")]
else:
sitepackages_paths = [Path(site.getsitepackages()[-1])]
for sitepackages_path in sitepackages_paths:
path = sitepackages_path / package path = sitepackages_path / package
paths.append(str(path)) info.path = str(path)
if path.is_file():
path.unlink()
if not path.is_dir(): if not path.is_dir():
path.mkdir() path.mkdir()
for file, contents in file_contents.items(): for file, contents in file_contents.items():
with open(path / file, "wb") as f: with (path / file).open("wb") as f:
f.write(contents) f.write(contents)
if Pythonista: if Pythonista:
pypi_packages = sitepackages_path / '.pypi_packages' pypi_packages = sitepackages_path / ".pypi_packages"
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(pypi_packages) config.read(pypi_packages)
config[package] = {} config[package] = {}
config[package]['url'] = 'github' config[package]["url"] = "github"
config[package]['version'] = version config[package]["version"] = version
config[package]['summary'] = '' config[package]["summary"] = ""
config[package]['files'] = path.as_posix() config[package]["files"] = path.as_posix()
config[package]['dependency'] = '' config[package]["dependency"] = ""
with pypi_packages.open('w') as f: with pypi_packages.open("w") as f:
config.write(f) config.write(f)
else: else:
for entry in sitepackages_path.glob("*"): for entry in sitepackages_path.glob("*"):
@ -15483,16 +15488,16 @@ def _install(files, url=None):
path_distinfo = Path(str(path) + "-" + version + ".dist-info") path_distinfo = Path(str(path) + "-" + version + ".dist-info")
if not path_distinfo.is_dir(): if not path_distinfo.is_dir():
path_distinfo.mkdir() path_distinfo.mkdir()
with open(path_distinfo / "METADATA", "w") as f: # make a dummy METADATA file with (path_distinfo / "METADATA").open("w") as f: # make a dummy METADATA file
f.write("Name: " + package + "\n") f.write("Name: " + package + "\n")
f.write("Version: " + version + "\n") f.write("Version: " + version + "\n")
with open(path_distinfo / "INSTALLER", "w") as f: # make a dummy METADATA file with (path_distinfo / "INSTALLER").open("w") as f: # make a dummy METADATA file
f.write("github\n") f.write("github\n")
with open(path_distinfo / "RECORD", "w") as f: with (path_distinfo / "RECORD").open("w") as f:
pass # just to create the file to be recorded pass # just to create the file to be recorded
with open(path_distinfo / "RECORD", "w") as record_file: with (path_distinfo / "RECORD").open("w") as record_file:
for p in (path, path_distinfo): for p in (path, path_distinfo):
for file in p.glob("**/*"): for file in p.glob("**/*"):
@ -15504,7 +15509,7 @@ def _install(files, url=None):
if (file.stem == "RECORD" and p == path_distinfo) or ("__pycache__" in name.lower()): if (file.stem == "RECORD" and p == path_distinfo) or ("__pycache__" in name.lower()):
record_file.write(",") record_file.write(",")
else: else:
with open(file, "rb") as f: with file.open("rb") as f:
file_contents = f.read() file_contents = f.read()
hash = "sha256=" + base64.urlsafe_b64encode( hash = "sha256=" + base64.urlsafe_b64encode(
hashlib.sha256(file_contents).digest() hashlib.sha256(file_contents).digest()
@ -15516,9 +15521,9 @@ def _install(files, url=None):
record_file.write("\n") record_file.write("\n")
info.path = ','.join(paths)
return info return info
def _upgrade_from_github(): def _upgrade_from_github():
info = _install( info = _install(
files="PySimpleGUI.py !init.py".split(), url="https://raw.githubusercontent.com/PySimpleGUI/PySimpleGUI/master/" files="PySimpleGUI.py !init.py".split(), url="https://raw.githubusercontent.com/PySimpleGUI/PySimpleGUI/master/"