def create_package_file(self): if os.path.exists(self.pkg): log.warning("package.py already exist and may be used for other functionality") else: key, token = encrypt( url=self.git.url, email=self.git.email, username=self.git.username, password=self.git.password, pypi_user=self.pypi_user, pypi_pass=self.pypi_pass, ) upload = "\n lambda: manager.upload()," if self.pypi_user and self.pypi_pass else "" with open(self.pkg, 'w') as f: f.write(f'''from qaviton_package_manager import Manager, decypt manager = Manager(**decypt( key={key}, token={token}, )) if __name__ == "__main__": manager.run( lambda: manager.update(), lambda: manager.update_test(), lambda: manager.test(), lambda: manager.build(),{upload} ) ''' ) log.info('created package.py file')
def select_license(): log.info('fetching licenses') http = HTTP.get() r = http.get('https://api.github.com/licenses') r.raise_for_status() licenses: list = r.json() licenses.append({'key': 'private'}) while True: print("\nSelect a License:") default_no = None for i, l in enumerate(licenses): print(f" ({i + 1}) {l['key']}") if l['key'] == SETTINGS.LICENSE_TYPE: default_no = i + 1 if default_no is None: SETTINGS.LICENSE_TYPE = licenses[-1]['key'] default_no = len(licenses) + 1 print(f"default: ({default_no}) {SETTINGS.LICENSE_TYPE}") try: license_no = prompt("") if not license_no: return SETTINGS.LICENSE_TYPE return licenses[int(license_no) - 1]['key'] except KeyboardInterrupt as e: raise e except: print('invalid input, please select a valid number')
def set_version(self): self.versions = [] bad_version_tags = [] for v in sorted( self.repo('tag --merged').decode('utf-8').splitlines()): try: self.versions.append(Version(v)) except: bad_version_tags.append(v) if bad_version_tags: log.warning(f"package {self.link} has invalid version tags:") for v in bad_version_tags: print(' ', v) log.info('you can fix this issue using: \n' ' git push --delete origin tagName\n' ' git tag -d tagName') # get version versions = sorted(self.specifier.filter(self.versions)) if not versions: raise VersionFilterError( f"pkg {self.link} with specifiers {self.specifier} " f"has no valid version from its versions list: {self.versions}" ) self.version = versions[-1] self.repo(f'checkout tags/{self.version.__str__()}')
def handle_git_ignore(self): if not os.path.exists(self.git_ignore): log.warning("missing .gitignore file") print('creating .gitignore file') with open(self.git_ignore, 'w') as f: f.write('\n'.join(ignore_list)) self.git.add('"'+self.git_ignore+'"') else: with open(self.git_ignore) as f: lines = f.read().splitlines() with open(self.git_ignore, 'a') as f: f.write('\n'+'\n'.join([line for line in ignore_list if line not in lines])) log.info('added content to .gitignore file')
def __init__(self, git: Git, pypi_user, pypi_pass, package_name=None): log.info("creating git packaging system") log.info("press q to quit") if package_name is None: self.package_name = git.root.rsplit(os.sep, 1)[1] log.warning('package name not specified, selecting dir name:', self.package_name) else: self.package_name = package_name Prep.__init__(self, git, self.package_name) self.pypi_user = pypi_user self.pypi_pass = pypi_pass self.git_ignore = self.root + os.sep + SETTINGS.GIT_IGNORE self.pkg = self.root + os.sep + SETTINGS.PACKAGE self.run()
def main(): from os.path import exists from os import getcwd, sep root = getcwd() pkg = root + sep + 'package.py' if exists(pkg): from qaviton_helpers import import_path try: manager = import_path(pkg).manager except Exception as e: from qaviton_package_manager.utils.logger import log log.warning(e) log.info(f"could not retrieve 'manager' parameter from {pkg}") log.info("creating a new manager") else: return manager.run() from qaviton_package_manager.manager import Manager return Manager().run()
def run(self): log.info("asserting package __init__.py file") init_content = self.get_pkg_init() log.info("asserting package LICENSE") license = self.get_license() log.info("asserting package README") readme = self.get_readme() log.info("asserting package requirements") requirements = self.set_requirements() log.info("asserting package testing requirements") self.set_test_requirements() if os.path.exists(self.setup_path): log.warning("setup.py already exist") else: package_params = self.handle_package_init(init_content, license) self.create_setup_file(readme, requirements, package_params) self.create_package_file() self.handle_git_ignore() self.handle_venv()
def handle_venv(self): venv_path = self.git.root+os.sep+'venv' if not os.path.exists(venv_path): log.info('Creating virtual environment.') try: import venv venv.create(venv_path) except Exception as e: log.exception(e) log.error('Could not create virtual environment. Please make sure python -m venv venv works on your environment') if os.sep == '\\': log.info('to activate your virtual environment: C:\> venv\\Scripts\\activate.bat') else: log.info('to activate your virtual environment: $ . venv/bin/activate')