Skip to content

Commit

Permalink
Bug 1619855 - Require Python 3.6 r=glob,zeid
Browse files Browse the repository at this point in the history
  • Loading branch information
zalun committed Aug 10, 2020
1 parent c01d4bf commit 1517c27
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
6 changes: 5 additions & 1 deletion .circleci/config.yml
Expand Up @@ -6,10 +6,10 @@ workflows:
jobs:
- test-3.6
- test-3.7
- test-3.8
- test-package

jobs:
# while moz-phab runs under 3.5, black and hg-evolve require 3.6+
test-3.6: &test-template
docker:
- image: circleci/python:3.6
Expand Down Expand Up @@ -49,6 +49,10 @@ jobs:
<<: *test-template
docker:
- image: circleci/python:3.7
test-3.8:
<<: *test-template
docker:
- image: circleci/python:3.8

test-package:
docker:
Expand Down
45 changes: 30 additions & 15 deletions mozphab/updater.py
Expand Up @@ -18,6 +18,7 @@

from .arcanist import update_arc
from .config import config
from .exceptions import Error
from .logger import logger
from .subprocess_wrapper import check_call

Expand All @@ -34,11 +35,11 @@ def get_name_and_version():
return "{} ({})".format(dist.project_name, dist.version)


def get_pypi_version():
def get_pypi_info():
url = "https://pypi.org/pypi/MozPhab/json"
output = urllib.request.urlopen(urllib.request.Request(url), timeout=30).read()
response = json.loads(output.decode("utf-8"))
return response["info"]["version"]
return response["info"]


def check_for_updates(with_arc=True):
Expand All @@ -52,39 +53,53 @@ def check_for_updates(with_arc=True):
update_arc()

# Update self.
if sys.version_info < (3, 6):
logger.warning(
"WARNING:\nPython {}.{} will no longer be supported in the next release "
"of MozPhab.".format(sys.version_info.major, sys.version_info.minor)
)

if (
config.self_last_check >= 0
and time.time() - config.self_last_check > SELF_UPDATE_FREQUENCY * 60 * 60
):
config.self_last_check = int(time.time())
config.write()

current_version = get_installed_distribution().version
pypi_version = get_pypi_version()
pypi_info = get_pypi_info()
logger.debug(
"Versions - local: {}, PyPI: {}".format(current_version, pypi_version)
"Versions - local: {}, PyPI: {}".format(
current_version, pypi_info["version"]
)
)

if parse_version(current_version) >= parse_version(pypi_version):
# convert ">=3.6" to (3, 6)
try:
required_python_version = tuple(
[int(i) for i in pypi_info["requires_python"][2:].split(".")]
)
except ValueError:
required_python_version = ()

if sys.version_info < required_python_version:
raise Error(
"Unable to upgrade to version {}.\n"
"MozPhab requires Python in version >= {}".format(
pypi_info["version"], ".".join(required_python_version)
)
)

config.write()

if parse_version(current_version) >= parse_version(pypi_info["version"]):
logger.debug("update check not required")
return

if config.self_auto_update:
logger.info("Upgrading to version %s", pypi_version)
logger.info("Upgrading to version %s", pypi_info["version"])
self_upgrade()
logger.info("Restarting...")
# It's best to ignore errors here as they will be reported by the
# new moz-phab process.
subprocess.run(sys.argv)
sys.exit()

logger.warning("Version %s of `moz-phab` is now available", pypi_version)
logger.warning(
"Version %s of `moz-phab` is now available", pypi_info["version"]
)


def self_upgrade():
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Expand Up @@ -18,7 +18,9 @@
description="Phabricator review submission/management tool.",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
python_requires=">=3.5",
# Note: Please change the `updater.py::check_for_updates` method if the format
# would be different than >=X.Y
python_requires=">=3.6",
include_package_data=True,
package_data={"mozphab": ["metrics.yaml", "pings.yaml"]},
install_requires=[
Expand Down

0 comments on commit 1517c27

Please sign in to comment.