From 88421bed556aecc010e3d6e241a704b2b4dba6a5 Mon Sep 17 00:00:00 2001 From: Peter Fison Date: Thu, 10 Dec 2020 12:57:32 +0000 Subject: [PATCH] Bug fixes and tweaks --- easypypi/easypypi.py | 59 +++++++++++++++++++----------------- easypypi/shared_functions.py | 2 +- easypypi/utils.py | 25 +++++++++------ setup - old.py | 2 +- setup.py | 2 +- 5 files changed, 49 insertions(+), 41 deletions(-) diff --git a/easypypi/easypypi.py b/easypypi/easypypi.py index 755c1c8..2a53e42 100644 --- a/easypypi/easypypi.py +++ b/easypypi/easypypi.py @@ -37,7 +37,7 @@ class Package(CleverDict): Makes use of CleverDict's auto-save feature to store values in a config file, and .get_aliases() to keep a track of newly created attributes. - Exits early if review == False + Exits early if prompts == False redirect : Send stdout and stderr to PySimpleGUI Debug Window @@ -48,13 +48,18 @@ class Package(CleverDict): setup_fields = SETUP_FIELDS def __init__(self, name=None, **kwargs): + if "prompts" in kwargs: + prompts = kwargs['prompts'] + del kwargs["prompts"] + else: + prompts = True super().__init__(**kwargs) + # Caution! If kwargs are supplied, autosave will overwrite JSON confi self.start_gui(redirect=kwargs.get("redirect")) - self.load_defaults(name) - # Must load before setting any other values - # Otherwise JSON config will be overwritten with null values + self.load_defaults(name, prompts) + # As above... must Load before Setting any other values with autosave on if self.name and self.get("setup_filepath_str"): - if self.get("prompts") is not False: + if prompts is not False: self.review() self.generate() self.upload() @@ -93,12 +98,12 @@ def start_gui(self, **kwargs): ) print(f"\nⓘ Your easyPyPI config file is:\n {self.__class__.config_filepath}") - def load_defaults(self, name=None): + def load_defaults(self, name=None, prompts = True): """ Entry point for loading default Package values as attributes. Choose between last updated JSON config file, and setup.py if it exists. - Exits early if review == False + Exits early if prompts == False """ self.create_skeleton_config_file() # Important! Defaults must be loaded from file (if possible) first: @@ -111,7 +116,7 @@ def load_defaults(self, name=None): default_text="as_easy_as_pie", **sg_kwargs, ) - if self.get("prompts") and self.name: + if prompts and self.name: self.create_folder_structure() if self.setup_filepath.is_file() and self.setup_filepath.stat().st_size: # setup.py exists & isn't empty, overwrite default values @@ -194,10 +199,10 @@ def review(self): Entry point for creating a package for the first time, or reviewing basic metadata for a previously created package. """ - self.register_on_pypi_and_github() # First for self.github_username + self.check_account_credentials("github_") # sets self.github_username self.get_metadata() - self.get_classifiers() self.get_license() + self.get_classifiers() self.upversioned_already = True def generate(self): @@ -444,7 +449,7 @@ def get_password(self, account): ), ) - def register_on_pypi_and_github(self): + def check_account_credentials(self, filter=None): """ Prompts for TestPyPI/PyPI account names for twine to use. @@ -460,13 +465,18 @@ def register_on_pypi_and_github(self): .pypi_test_password .github_password + filter : restricts the function to the account specified + """ url = r"https://pypi.org/account/register/" - for account, (repo, url) in { + accounts = { "github_": ["Github", "https://github.com/join"], "pypi_": ["PyPI", url], "pypi_test_": ["Test PyPI", url.replace("pypi", "test.pypi")], - }.items(): + } + if filter: + accounts = {k:v for k,v in accounts.items() if k == filter} + for account, (repo, url) in accounts.items(): if not self.get(account + "username"): response = sg.popup_yes_no( f"Do you need to register for an account on {repo}?", **sg_kwargs) @@ -478,8 +488,8 @@ def register_on_pypi_and_github(self): f'then return to easyPyPI to continue the process...') webbrowser.open(url) self.get_username(account) - # if not self.get(account + "password"): - # self.get_password(account) + if not self.get(account + "password"): + self.get_password(account) self.url = self.get_default_url() # Uses self.github_username def copy_other_files(self): @@ -512,7 +522,7 @@ def update_script_lines(self): for keyword in self.__class__.setup_fields: old_line_starts = keyword.upper() + " = " if keyword == "license": - new_value = self.license_dict.name + new_value = self.license else: new_value = getattr(self, keyword) self.script_lines = update_line( @@ -583,8 +593,7 @@ def upload_with_twine(self): params = "testpypi" account = "pypi_test_" params += f" dist/*-{self.version}.tar.gz " - if not (self.get("github_password") and self.get("github_username")): - self.register_on_pypi_and_github() + self.check_account_credentials(account) os.chdir(self.setup_filepath.parent) if os.system( f'cmd /c "python -m twine upload ' @@ -625,7 +634,7 @@ def create_github_repository(self): if choice != "Yes": return if not (self.get("github_password") and self.get("github_username")): - self.register_on_pypi_and_github() + self.check_account_credentials() browser = mechanicalsoup.StatefulBrowser( soup_config={'features': 'lxml'}, raise_on_404=True, @@ -647,7 +656,8 @@ def create_github_repository(self): def upload_to_github(self): """ Uploads package to Github using Git""" - commands = f"""git init + commands = f""" + git init git add *.* git commit -m "Committing version {self.version}" git branch -M main @@ -661,9 +671,8 @@ def upload_to_github(self): **sg_kwargs, ) if choice != "Yes": return - os.chdir(self.setup_filepath.parent) - for command in commands.splitlines(): + for command in commands.splitlines()[1:]: # Ignore first blank line if not os.system(f"cmd /c {command}"): # A return value of 1 indicates an error, 0 indicates success print(f"\nⓘ Your package is now online at:\n {self.url}':\n") @@ -720,9 +729,3 @@ def prompt_with_checkboxes(group, choices): return [choices[k] for k, v in checked.items() if v] if event is None: return - -# TODO: Avoid prompting for ALL passwords if one is missing -# TODO: Better exits from cancel or close window -# TODO: Better handling of attribute errors/missing values check before function -# e.g. decorator to check required values and call .summary() -# TODO: .pypi_username and .pypi_test_username not saving between sessions diff --git a/easypypi/shared_functions.py b/easypypi/shared_functions.py index 4137a02..9fd491a 100644 --- a/easypypi/shared_functions.py +++ b/easypypi/shared_functions.py @@ -36,7 +36,7 @@ def update_line(script_lines, old_line_starts, new_value): try: if isinstance(new_value, list): # Add quotation marks unless list - new_value = str(new_value) + new_value = ", ".join(new_value) else: new_value = f'"{new_value}"' script_lines[index] = old_line_starts + new_value.rstrip() + "\n" diff --git a/easypypi/utils.py b/easypypi/utils.py index 9aeb2ac..6c9e687 100644 --- a/easypypi/utils.py +++ b/easypypi/utils.py @@ -6,22 +6,27 @@ """ SETUP_FIELDS = [ - 'name', - 'version', - 'github_username', - 'url', - 'description', 'author', + 'classifiers', + 'description', 'email', + 'github_username', 'keywords', - 'requirements', 'license', - 'classifiers', + 'name', + 'requirements', + 'url', + 'version', ] EASYPYPI_FIELDS = [ - 'pypi_username', + 'github_password', + 'license_text', + 'pypi_password', + 'pypi_test_password', 'pypi_test_username', + 'pypi_username', + 'script_lines', 'setup_filepath_str', ] @@ -34,9 +39,9 @@ ] REPLACEMENTS = [ - '{self.name}', - '{self.description}', '{self.author}', + '{self.description}', '{self.email}', + '{self.name}', '{datetime.datetime.now()}', ] diff --git a/setup - old.py b/setup - old.py index 1294505..b13e5a6 100644 --- a/setup - old.py +++ b/setup - old.py @@ -11,7 +11,7 @@ EMAIL = "peter@southwestlondon.tv" URL = "https://github.com/Pfython/easypypi" KEYWORDS = "easypypi, Peter Fison, Pfython, pip, package, publish, share, build, deploy, Python" -CLASSIFIERS = ['Development Status :: 4 - Beta, Intended Audience :: Developers, Operating System :: OS Independent, Programming Language :: Python :: 3.6, Programming Language :: Python :: 3.7, Programming Language :: Python :: 3.8, Programming Language :: Python :: 3.9, Topic :: Software Development :: Build Tools, Topic :: Software Development :: Version Control :: Git, Topic :: System :: Archiving :: Packaging, Topic :: System :: Installation/Setup, Topic :: System :: Software Distribution, Topic :: Utilities'] +CLASSIFIERS = "Development Status :: 4 - Beta, Intended Audience :: Developers, Operating System :: OS Independent, Programming Language :: Python :: 3.6, Programming Language :: Python :: 3.7, Programming Language :: Python :: 3.8, Programming Language :: Python :: 3.9, Topic :: Software Development :: Build Tools, Topic :: Software Development :: Version Control :: Git, Topic :: System :: Archiving :: Packaging, Topic :: System :: Installation/Setup, Topic :: System :: Software Distribution, Topic :: Utilities" REQUIREMENTS = "cleverdict, pysimplegui, click, requests, twine, mechanicalsoup" diff --git a/setup.py b/setup.py index 1294505..b13e5a6 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ EMAIL = "peter@southwestlondon.tv" URL = "https://github.com/Pfython/easypypi" KEYWORDS = "easypypi, Peter Fison, Pfython, pip, package, publish, share, build, deploy, Python" -CLASSIFIERS = ['Development Status :: 4 - Beta, Intended Audience :: Developers, Operating System :: OS Independent, Programming Language :: Python :: 3.6, Programming Language :: Python :: 3.7, Programming Language :: Python :: 3.8, Programming Language :: Python :: 3.9, Topic :: Software Development :: Build Tools, Topic :: Software Development :: Version Control :: Git, Topic :: System :: Archiving :: Packaging, Topic :: System :: Installation/Setup, Topic :: System :: Software Distribution, Topic :: Utilities'] +CLASSIFIERS = "Development Status :: 4 - Beta, Intended Audience :: Developers, Operating System :: OS Independent, Programming Language :: Python :: 3.6, Programming Language :: Python :: 3.7, Programming Language :: Python :: 3.8, Programming Language :: Python :: 3.9, Topic :: Software Development :: Build Tools, Topic :: Software Development :: Version Control :: Git, Topic :: System :: Archiving :: Packaging, Topic :: System :: Installation/Setup, Topic :: System :: Software Distribution, Topic :: Utilities" REQUIREMENTS = "cleverdict, pysimplegui, click, requests, twine, mechanicalsoup"