Skip to content

Commit

Permalink
Clarify imports that are dependent on the version of Python
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Nov 28, 2023
1 parent 96ea29e commit c98af7d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ repos:
- id: check-docstring-first
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
additional_dependencies: [toml]
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
hooks:
Expand All @@ -36,4 +35,5 @@ repos:
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies: [tomli]
# remove toml extra once Python 3.10 is no longer supported
additional_dependencies: ['.[toml]']
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ dependencies = [
# Any dependency that is part of the "core python toolchain" (e.g. pip,
# wheel) specify a minimum version, but no maximum, because we always want
# the most recent version.
#
# limited to <=3.9 for the `group` argument for `entry_points()`
"importlib_metadata >= 4.4; python_version <= '3.9'",
"packaging >= 22.0",
"pip >= 23.1.1",
Expand Down
13 changes: 5 additions & 8 deletions src/briefcase/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import argparse
import importlib
import importlib.metadata
import inspect
import os
import platform
import shutil
import subprocess
import sys
import textwrap
from abc import ABC, abstractmethod
from argparse import RawDescriptionHelpFormatter
Expand All @@ -17,14 +19,9 @@
from cookiecutter.repository import is_repo_url
from platformdirs import PlatformDirs

try:
import importlib_metadata
except ImportError: # pragma: no-cover-if-lt-py310
import importlib.metadata as importlib_metadata

try:
if sys.version_info >= (3, 11): # pragma: no-cover-if-lt-py311
import tomllib
except ModuleNotFoundError: # pragma: no-cover-if-gte-py310
else: # pragma: no-cover-if-gte-py311
import tomli as tomllib

from briefcase import __version__
Expand Down Expand Up @@ -520,7 +517,7 @@ def briefcase_required_python_version(self):
# Native format is ">=3.8"
return tuple(
int(v)
for v in importlib_metadata.metadata("briefcase")["Requires-Python"]
for v in importlib.metadata.metadata("briefcase")["Requires-Python"]
.split("=")[1]
.strip()
.split(".")
Expand Down
5 changes: 3 additions & 2 deletions src/briefcase/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import copy
import keyword
import re
import sys
import unicodedata
from types import SimpleNamespace

try:
if sys.version_info >= (3, 11): # pragma: no-cover-if-lt-py311
import tomllib
except ModuleNotFoundError: # pragma: no-cover-if-gte-py310
else: # pragma: no-cover-if-gte-py311
import tomli as tomllib

from briefcase.platforms import get_output_formats, get_platforms
Expand Down
4 changes: 2 additions & 2 deletions src/briefcase/platforms/web/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from briefcase.console import Log

try:
if sys.version_info >= (3, 11): # pragma: no-cover-if-lt-py311
import tomllib
except ModuleNotFoundError: # pragma: no-cover-if-gte-py310
else: # pragma: no-cover-if-gte-py311
import tomli as tomllib

import tomli_w
Expand Down
4 changes: 2 additions & 2 deletions tests/platforms/web/static/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import sys
from unittest import mock

try:
if sys.version_info >= (3, 11): # pragma: no-cover-if-lt-py311
import tomllib
except ModuleNotFoundError:
else: # pragma: no-cover-if-gte-py311
import tomli as tomllib

import pytest
Expand Down

0 comments on commit c98af7d

Please sign in to comment.