PK!F##poetry_data_manager/__init__.pyfrom .core import PoetryDataManagerPK!opoetry_data_manager/core.py#!/bin/env python3.7 """ This module is the final authority on information about this software. Whenever there is doubt about information regarding this app, use the information in this file. """ import os import appdirs # pip3 instal appdirs import tomlkit # pip3 install tomlkit import arrow # import argparse class PoetryDataManager: def __init__(self, pyproject_toml_file_path): self.name = '' self.version = '' self.description = '' self.readme_file_path = '' self.website = '' self.repository = '' self.authors = [] self.license = '' self.license_file_path = '' self.keywords = [] self.classifiers = [] self.package_data = {} self.includes = [] self.excludes = [] self.entry_points = {} self.dependencies = [] self.application_folders = appdirs.AppDirs() self.__toml_file_contents = None self._pyproject_toml_file_path = pyproject_toml_file_path @property def author_name(self): """Returns the name of the first author""" return self.authors[0].split()[0] @property def author_email(self): """Returns the email of the first author""" return self.authors[0].split()[1].rstrip(">").lstrip("<") @property def readme(self): """This loads and returns the contents of the readme file. The readme file path is determined by the readme variable in the pyproject.toml file which should be set relative to that file""" file_path = os.path.join( os.path.dirname(os.path.realpath(self._pyproject_toml_file_path)), self.readme_file_path ) if os.path.exists(file_path): with open(file_path) as file: return file.read() @property def copyright_string(self): current_year = arrow.now().date().year five_years_ago = arrow.now().shift(years=-5).date().year return f'Copyright © {five_years_ago}-{current_year} {self.author_name}' @property def full_license(self): file_path = os.path.join( os.path.dirname(os.path.realpath(self._pyproject_toml_file_path)), self.license_file_path ) if os.path.exists(file_path): with open(file_path) as file: return file.read() @property def dev_version(self): return self.version + '-dev' @property def alpha_version(self): return self.version + '-alpha' def bump_version_number(self, version_type): version_components = [int(segment) for segment in self.version.split('.')] if version_type == 'major': version_components[0] += 1 version_components[1] = 0 version_components[2] = 0 elif version_type == 'minor': version_components[1] += 1 version_components[2] = 0 elif version_type == 'patch': version_components[2] += 1 self.version = '.'.join([str(segment) for segment in version_components]) self.save_app_data() # Saving and Loading ----------------------------------------------------------------------------------------------- def load_app_data(self): with open(self._pyproject_toml_file_path, 'r') as app_data_file: self.__toml_file_contents = tomlkit.loads(app_data_file.read()) app_data = self.__toml_file_contents['tool']['poetry'] self.name = app_data['name'] self.version = app_data['version'] self.description = app_data['description'] self.readme_file_path = app_data['readme'] self.website = app_data['website'] self.repository = app_data['repository'] self.authors = app_data['authors'] self.license = app_data['license'] self.license_file_path = app_data['license-file-path'] self.keywords = app_data['keywords'] self.classifiers = app_data['classifiers'] self.package_data = app_data['packages'] self.includes = app_data['include'] self.excludes = app_data['exclude'] self.entry_points = app_data['scripts'] self.dependencies = app_data['dependencies'] self.application_folders = appdirs.AppDirs( appname=self.name, appauthor=self.author_name, version=self.version ) def save_app_data(self): app_data = self.__toml_file_contents['tool']['poetry'] app_data['name'] = self.name app_data['version'] = self.version app_data['description'] = self.description app_data['readme'] = self.readme_file_path app_data['website'] = self.website app_data['repository'] = self.repository app_data['authors'] = self.authors app_data['license'] = self.license app_data['license-file-path'] = self.license_file_path app_data['keywords'] = self.keywords app_data['classifiers'] = self.classifiers app_data['packages'] = self.package_data app_data['include'] = self.includes app_data['exclude'] = self.excludes app_data['scripts'] = self.entry_points app_data['dependencies'] = self.dependencies with open(self._pyproject_toml_file_path, 'w') as app_data_file: app_data_file.write(tomlkit.dumps(self.__toml_file_contents)) def commandline_manager(): pass # todo implement argument parsing for retrieving various variables PK!%poetry_data_manager/tests/__init__.pyPK!P%||&poetry_data_manager/tests/test_LICENSEThis is an example license file. This would normally named 'LICENSE' and be placed in the repository root or a 'docs' folderPK!(U]%poetry_data_manager/tests/test_READMEThis is an example readme file. This would normally be named 'README' or 'README.md' or 'README.rtf' and be placed in the repository root or a 'docs' folderPK!20poetry_data_manager/tests/test_appDataManager.pyfrom unittest import TestCase import arrow import appdirs import tomlkit import shutil import os import filecmp from poetry_data_manager.core import PoetryDataManager class TestAppDataManager(TestCase): def setUp(self): self.pyproject_file_path = os.path.join(os.path.dirname(os.path.relpath(__file__)), "test_pyproject.toml") self.poetry_data_manager = PoetryDataManager(self.pyproject_file_path) self.test_load_app_data() def test_author_name(self): self.assertEqual('Bob', self.poetry_data_manager.author_name) def test_author_email(self): self.assertEqual('bob@example.com', self.poetry_data_manager.author_email) def test_readme(self): self.assertEqual( "This is an example readme file. This would normally be named 'README' or 'README.md' or 'README.rtf' and " "be\nplaced in the repository root or a 'docs' folder", self.poetry_data_manager.readme ) def test_copyright_string(self): current_year = arrow.now().date().year five_years_ago = arrow.now().shift(years=-5).date().year self.assertEqual( f'Copyright © {five_years_ago}-{current_year} {self.poetry_data_manager.author_name}', self.poetry_data_manager.copyright_string, ) def test_full_license(self): self.assertEqual( "This is an example license file. This would normally named 'LICENSE' and be placed in the " "repository root or a 'docs' folder", self.poetry_data_manager.full_license) def test_dev_version(self): self.assertEqual('1.3.5-dev', self.poetry_data_manager.dev_version) def test_alpha_version(self): self.assertEqual('1.3.5-alpha', self.poetry_data_manager.alpha_version) def test_bump_version_number(self): test_version_pyproject_file_path = 'test_version_pyproject.toml' poetry_data_manager = PoetryDataManager(test_version_pyproject_file_path) def generate_temp_version_toml_file(): shutil.copyfile(self.pyproject_file_path, test_version_pyproject_file_path) poetry_data_manager.load_app_data() def get_version(): with open(poetry_data_manager._pyproject_toml_file_path, 'r') as app_data_file: return tomlkit.loads(app_data_file.read())['tool']['poetry']['version'] generate_temp_version_toml_file() poetry_data_manager.bump_version_number('major') self.assertEqual('2.0.0', get_version()) generate_temp_version_toml_file() poetry_data_manager.bump_version_number('minor') self.assertEqual('1.4.0', get_version()) generate_temp_version_toml_file() poetry_data_manager.bump_version_number('patch') self.assertEqual('1.3.6', get_version()) os.remove(test_version_pyproject_file_path) def test_load_app_data(self): self.poetry_data_manager.load_app_data() # check the pyproject toml file path self.assertEqual(self.pyproject_file_path, self.poetry_data_manager._pyproject_toml_file_path) # app metadata self.assertEqual("Hello-World", self.poetry_data_manager.name) self.assertEqual('1.3.5', self.poetry_data_manager.version) self.assertEqual("This is an example app", self.poetry_data_manager.description) self.assertEqual('test_README', self.poetry_data_manager.readme_file_path) self.assertEqual('https://hello-world.example.com', self.poetry_data_manager.website) self.assertEqual("https://hello-world.example.com/repo", self.poetry_data_manager.repository) self.assertEqual(["Bob "], self.poetry_data_manager.authors) self.assertEqual("GPL-3.0+", self.poetry_data_manager.license) # pypi keywords and categories self.assertEqual(["keyword1", "keyword2", "keyword3"], self.poetry_data_manager.keywords) self.assertEqual( [ 'Development Status :: 3 - Alpha', 'Intended Audience :: Developers', 'Topic :: Software Development :: Build Tools', ], self.poetry_data_manager.classifiers ) # package data self.assertEqual([{'include': "package_name1"}], self.poetry_data_manager.package_data) self.assertEqual(['includeme1', 'includeme2'], self.poetry_data_manager.includes) self.assertEqual(['excludeme1', 'excludeme2'], self.poetry_data_manager.excludes) # entry points self.assertEqual( {"hello-world": 'package_name1.package_name2.package_name3.module_name:print_hello_world_function'}, self.poetry_data_manager.entry_points ) # dependencies self.assertEqual( { "python": "^3.6", "external_lib1": "^1.0.0" }, self.poetry_data_manager.dependencies ) # appdirs checking self.assertIsInstance(self.poetry_data_manager.application_folders, appdirs.AppDirs) self.assertEqual(self.poetry_data_manager.name, self.poetry_data_manager.application_folders.appname) self.assertEqual(self.poetry_data_manager.author_name, self.poetry_data_manager.application_folders.appauthor) self.assertEqual(self.poetry_data_manager.version, self.poetry_data_manager.application_folders.version) def test_save_app_data(self): test_save_pyproject_file_path = 'test_save_app_data_pyproject.toml' shutil.copyfile(self.pyproject_file_path, test_save_pyproject_file_path) poetry_data_manager = PoetryDataManager(test_save_pyproject_file_path) poetry_data_manager.load_app_data() poetry_data_manager.save_app_data() self.assertTrue(filecmp.cmp(test_save_pyproject_file_path, self.pyproject_file_path)) os.remove(test_save_pyproject_file_path) PK!LX.-poetry_data_manager/tests/test_pyproject.toml# This file should be the the final authority on information about this software. # Whenever there is doubt about information regarding this software, use the information in this file. # For further information on the formatting of this file, please see https://poetry.eustace.io/docs/pyproject/ [tool.poetry] name = "Hello-World" version = "1.3.5" description = "This is an example app" readme = 'test_README' website = 'https://hello-world.example.com' repository = "https://hello-world.example.com/repo" authors = ["Bob "] license = "GPL-3.0+" license-file-path = 'test_LICENSE' keywords = ["keyword1", "keyword2", "keyword3"] classifiers = [ 'Development Status :: 3 - Alpha', 'Intended Audience :: Developers', 'Topic :: Software Development :: Build Tools', ] packages = [{include = "package_name1"}] include = ['includeme1', 'includeme2'] exclude = ['excludeme1', 'excludeme2'] [tool.poetry.scripts] hello-world = 'package_name1.package_name2.package_name3.module_name:print_hello_world_function' [tool.poetry.dependencies] external_lib1 = "^1.0.0" python = "^3.6" [build-system] requires = ["poetry>=0.12"] build-backend = "poetry.masonry.api" PK!Hu)GTU)poetry_data_manager-0.0.1.dist-info/WHEEL HM K-*ϳR03rOK-J,/R(O-)$qzd&Y)r$UV&UrPK!H-9>_,poetry_data_manager-0.0.1.dist-info/METADATATMS0W 3``2Mi@ﲽIʒ*ﻲM zr[@$B59^֘HM:w-\;$0pԵmSЪփ,K A8A=eXRJ⛭1q%5 xRe$nVGT&0|dH|vk}^1jj449Ŵ %͔39llՒ5+QC2hrҳi:ZrKL{$ ASr{gMLJ)1Bvh6"~.`긾 'E^j7Vɀ%&;:ܣ{fҬlJ,>=tėGv,^vljxˍ tR>qzf{(5Kgtp{齿zOtd@Qt|(1$O٠Ȳbn0^9{MmT% |R!}*2p$RFg Xdnء$^Vp XJc̡԰8c0hha]eG(VtnySmHTPK!H93*poetry_data_manager-0.0.1.dist-info/RECORDMs0{? XB,/ ( & $B4әuֽ!5/EyzTs= rc$Z/S#"PGvk/3+9سEǬNO䎺CCwc4h۝n*{V`+ g/l05i9}ˆќxfyex< ^ut83=/MoΨA]ǐ i|\>U,$DIya8EP?C+:I!f.$]M '>Gɏb{3j+^6 h#]rxizߦ}]ȕ )tBq~UA%i>EQ[S*ʘe=L' /L8)#?'mϾ Gjfû+E B,J䶩5wF͹3raK;+$ ,mf}Ejz؅FDuD>3W$Ehq/PK!F##poetry_data_manager/__init__.pyPK!o`poetry_data_manager/core.pyPK!%poetry_data_manager/tests/__init__.pyPK!P%||&apoetry_data_manager/tests/test_LICENSEPK!(U]%!poetry_data_manager/tests/test_READMEPK!20poetry_data_manager/tests/test_appDataManager.pyPK!LX.-f/poetry_data_manager/tests/test_pyproject.tomlPK!Hu)GTU)O4poetry_data_manager-0.0.1.dist-info/WHEELPK!H-9>_,4poetry_data_manager-0.0.1.dist-info/METADATAPK!H93*7poetry_data_manager-0.0.1.dist-info/RECORDPK R9