mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-08 16:39:55 +00:00
linting everything in black
This commit is contained in:
@@ -8,10 +8,10 @@ import requests
|
||||
|
||||
|
||||
class Requirements:
|
||||
""" handle requirements.txt """
|
||||
"""handle requirements.txt"""
|
||||
|
||||
FILE_PATH = 'tubearchivist/requirements.txt'
|
||||
LOCK = '/tmp/tubearchivist-requirements.lock'
|
||||
FILE_PATH = "tubearchivist/requirements.txt"
|
||||
LOCK = "/tmp/tubearchivist-requirements.lock"
|
||||
|
||||
def __init__(self):
|
||||
self.exists = self.checked_today()
|
||||
@@ -19,24 +19,24 @@ class Requirements:
|
||||
self.all_updates = False
|
||||
|
||||
def checked_today(self):
|
||||
""" skip requirements check when lock file exists """
|
||||
"""skip requirements check when lock file exists"""
|
||||
exists = pathlib.Path(self.LOCK).exists()
|
||||
return exists
|
||||
|
||||
def look_for_updates(self):
|
||||
""" look through requirements and check for updates """
|
||||
"""look through requirements and check for updates"""
|
||||
self.all_requirements = self.get_dependencies()
|
||||
self.all_updates = self.check_packages()
|
||||
|
||||
def get_dependencies(self):
|
||||
""" read out requirements.txt """
|
||||
"""read out requirements.txt"""
|
||||
|
||||
all_requirements = []
|
||||
with open(self.FILE_PATH, 'r', encoding='utf-8') as f:
|
||||
with open(self.FILE_PATH, "r", encoding="utf-8") as f:
|
||||
dependencies = f.readlines()
|
||||
|
||||
for dependency in dependencies:
|
||||
package, version = dependency.split('==')
|
||||
package, version = dependency.split("==")
|
||||
all_requirements.append((package, version.strip()))
|
||||
|
||||
all_requirements.sort(key=lambda x: x[0].lower())
|
||||
@@ -44,33 +44,32 @@ class Requirements:
|
||||
return all_requirements
|
||||
|
||||
def check_packages(self):
|
||||
""" compare installed with remote version """
|
||||
"""compare installed with remote version"""
|
||||
|
||||
total = len(self.all_requirements)
|
||||
print(f'checking versions for {total} packages...')
|
||||
print(f"checking versions for {total} packages...")
|
||||
|
||||
all_updates = {}
|
||||
|
||||
for dependency in self.all_requirements:
|
||||
package, version_installed = dependency
|
||||
url = f'https://pypi.org/pypi/{package}/json'
|
||||
url = f"https://pypi.org/pypi/{package}/json"
|
||||
response = requests.get(url).json()
|
||||
version_remote = response['info']['version']
|
||||
homepage = response['info']['home_page']
|
||||
version_remote = response["info"]["version"]
|
||||
homepage = response["info"]["home_page"]
|
||||
if version_remote != version_installed:
|
||||
to_update = {
|
||||
package: {
|
||||
"from": version_installed,
|
||||
"to": version_remote
|
||||
}
|
||||
package: {"from": version_installed, "to": version_remote}
|
||||
}
|
||||
all_updates.update(to_update)
|
||||
message = (f'update {package} {version_installed}' +
|
||||
f'==> {version_remote}\n {homepage}')
|
||||
message = (
|
||||
f"update {package} {version_installed}"
|
||||
+ f"==> {version_remote}\n {homepage}"
|
||||
)
|
||||
print(message)
|
||||
|
||||
if not all_updates:
|
||||
print('no updates found')
|
||||
print("no updates found")
|
||||
|
||||
# remember that
|
||||
pathlib.Path(self.LOCK).touch()
|
||||
@@ -78,7 +77,7 @@ class Requirements:
|
||||
return all_updates
|
||||
|
||||
def apply_updates(self):
|
||||
""" update requirements.txt file with new versions """
|
||||
"""update requirements.txt file with new versions"""
|
||||
|
||||
to_write = []
|
||||
|
||||
@@ -86,31 +85,31 @@ class Requirements:
|
||||
package, old_version = requirement
|
||||
|
||||
if package in self.all_updates.keys():
|
||||
package_version = self.all_updates[package]['to']
|
||||
package_version = self.all_updates[package]["to"]
|
||||
else:
|
||||
package_version = old_version
|
||||
|
||||
to_write.append(f'{package}=={package_version}\n')
|
||||
to_write.append(f"{package}=={package_version}\n")
|
||||
|
||||
with open(self.FILE_PATH, 'w', encoding='utf-8') as f:
|
||||
with open(self.FILE_PATH, "w", encoding="utf-8") as f:
|
||||
f.writelines(to_write)
|
||||
|
||||
print('requirements.txt updates')
|
||||
print("requirements.txt updates")
|
||||
|
||||
|
||||
def main():
|
||||
""" main to check for updates """
|
||||
"""main to check for updates"""
|
||||
handler = Requirements()
|
||||
if handler.exists:
|
||||
return
|
||||
|
||||
handler.look_for_updates()
|
||||
if handler.all_updates:
|
||||
input_response = input('\nupdate requirements.txt? [y/n] ')
|
||||
if input_response == 'y':
|
||||
input_response = input("\nupdate requirements.txt? [y/n] ")
|
||||
if input_response == "y":
|
||||
handler.apply_updates()
|
||||
else:
|
||||
print('cancle update...')
|
||||
print("cancel update...")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user