Skip to content

Commit

Permalink
Feature/python3.6 (#26)
Browse files Browse the repository at this point in the history
* add python 3.6 to github action

* lessen requirements threshold to support python3.6

* add utility module & implement `has_named_parameter` function

* handle `text` param not existance in python3.6 `subprocess.check_output`

* refactor e.output to e.__str__

* add retry mechanism in requesting pypi

* add python 3.6 support

* fixing the critical requirements to trigger dependant bot
  • Loading branch information
AHReccese authored May 2, 2024
1 parent 0ddc437 commit 68d08ab
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ body:
- Python 3.9
- Python 3.8
- Python 3.7
- Python 3.6
default: 1
validations:
required: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-2022, macOS-13]
python-version: [3.7, 3.8, 3.9, 3.10.0, 3.11.0, 3.12.0]
python-version: [3.6, 3.7, 3.8, 3.9, 3.10.0, 3.11.0, 3.12.0]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
6 changes: 3 additions & 3 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
requests==2.31.0
setuptools==69.5.1
wheel==0.43.0
twine==5.0.0
setuptools==40.8.0
wheel==0.35.0
twine==3.5.0
vulture>=1.0
bandit>=1.5.1
pydocstyle>=3.0.0
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
requests>=1.0.0
setuptools>=40.8.0
wheel>=0.40.0
twine>=4.0.0
wheel>=0.35.0
twine>=3.5.0
16 changes: 14 additions & 2 deletions reserver/reserver_func.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""Reserver functions."""
from requests import get
import requests
import requests.adapters
from .reserver_param import PYPI_TEST_URL, PYPI_MAIN_URL
from hashlib import sha256
from time import time
Expand Down Expand Up @@ -32,7 +33,18 @@ def does_package_exist(suggested_name, test_pypi):
url = PYPI_TEST_URL + "/" + suggested_name + "/"
else:
url = PYPI_MAIN_URL + "/" + suggested_name + "/"
response = get(url, timeout=5)

s = requests.Session()
retries = requests.adapters.Retry(
total=5,
backoff_factor=0.1,
status_forcelist=[ 500, 502, 503, 504 ]
)

s.mount('http://', requests.adapters.HTTPAdapter(max_retries=retries))
s.mount('https://', requests.adapters.HTTPAdapter(max_retries=retries))

response = s.get(url, timeout=5)
return not response.status_code == 404


Expand Down
8 changes: 6 additions & 2 deletions reserver/reserver_obj.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""Reserver modules."""
from .reserver_func import does_package_exist, generate_template_setup_py
from .util import has_named_parameter
from os import environ, path, getcwd, remove
from shutil import rmtree
from sys import executable
Expand Down Expand Up @@ -93,10 +94,13 @@ def upload(self, package_name):
error = None
for command in commands:
try:
check_output(command, shell=True, text=True)
if has_named_parameter(check_output, "text"):
check_output(command, shell=True, text=True)
else:
check_output(command, shell=True)
except CalledProcessError as e:
publish_failed = True
error = e.output
error = e.__str__()
if command == commands[-2]:
if "403" in error and "Invalid or non-existent authentication information" in error:
error = "Invalid or non-existent authentication information(PyPI API Key)."
Expand Down
19 changes: 19 additions & 0 deletions reserver/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
"""utility module."""
from inspect import signature


def has_named_parameter(func, param_name):
"""
Check whether the given function has a parameter named param_name or not.
:param func: function to check it's params
:type func: function
:param param_name: parameter's name
:type param_name: str
:return: boolean
"""
_signature = signature(func)
parameter_names = [p.name for p in _signature.parameters.values()]
return param_name in parameter_names
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def read_description():
'Natural Language :: English',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
Expand Down

0 comments on commit 68d08ab

Please sign in to comment.