mirror of
https://github.com/onionshare/onionshare.git
synced 2025-07-31 18:38:57 -04:00
Merge pull request #1981 from onionshare/mig/replace-pkg_resources-with-importlib
Replace use of pkg_resources.resource_filename with importlib.resources
This commit is contained in:
commit
0197ebaf5b
5 changed files with 15 additions and 55 deletions
4
.github/workflows/tests.yml
vendored
4
.github/workflows/tests.yml
vendored
|
@ -15,7 +15,7 @@ jobs:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v4
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: "3.9"
|
python-version: "3.10"
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
|
@ -41,7 +41,7 @@ jobs:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-python@v4
|
- uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: "3.9"
|
python-version: "3.10"
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
|
|
|
@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
import base64
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import importlib.resources as importlib_resources
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import random
|
import random
|
||||||
|
@ -29,7 +30,6 @@ import threading
|
||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
import re
|
import re
|
||||||
from pkg_resources import resource_filename
|
|
||||||
|
|
||||||
import colorama
|
import colorama
|
||||||
from colorama import Fore, Back, Style
|
from colorama import Fore, Back, Style
|
||||||
|
@ -313,9 +313,10 @@ class Common:
|
||||||
"""
|
"""
|
||||||
Returns the absolute path of a resource
|
Returns the absolute path of a resource
|
||||||
"""
|
"""
|
||||||
path = resource_filename("onionshare_cli", os.path.join("resources", filename))
|
ref = importlib_resources.files("onionshare_cli.resources") / filename
|
||||||
self.log("Common", "get_resource_path", f"filename={filename}, path={path}")
|
with importlib_resources.as_file(ref) as path:
|
||||||
return path
|
self.log("Common", "get_resource_path", f"filename={filename}, path={str(path)}")
|
||||||
|
return str(path)
|
||||||
|
|
||||||
def get_tor_paths(self):
|
def get_tor_paths(self):
|
||||||
if self.platform == "Linux":
|
if self.platform == "Linux":
|
||||||
|
|
47
cli/poetry.lock
generated
47
cli/poetry.lock
generated
|
@ -507,7 +507,6 @@ files = [
|
||||||
[package.dependencies]
|
[package.dependencies]
|
||||||
blinker = ">=1.6.2"
|
blinker = ">=1.6.2"
|
||||||
click = ">=8.1.3"
|
click = ">=8.1.3"
|
||||||
importlib-metadata = {version = ">=3.6.0", markers = "python_version < \"3.10\""}
|
|
||||||
itsdangerous = ">=2.1.2"
|
itsdangerous = ">=2.1.2"
|
||||||
Jinja2 = ">=3.1.2"
|
Jinja2 = ">=3.1.2"
|
||||||
Werkzeug = ">=2.3.3"
|
Werkzeug = ">=2.3.3"
|
||||||
|
@ -729,27 +728,6 @@ files = [
|
||||||
[package.extras]
|
[package.extras]
|
||||||
all = ["flake8 (>=7.1.1)", "mypy (>=1.11.2)", "pytest (>=8.3.2)", "ruff (>=0.6.2)"]
|
all = ["flake8 (>=7.1.1)", "mypy (>=1.11.2)", "pytest (>=8.3.2)", "ruff (>=0.6.2)"]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "importlib-metadata"
|
|
||||||
version = "7.0.1"
|
|
||||||
description = "Read metadata from Python packages"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.8"
|
|
||||||
groups = ["main"]
|
|
||||||
markers = "python_version < \"3.10\""
|
|
||||||
files = [
|
|
||||||
{file = "importlib_metadata-7.0.1-py3-none-any.whl", hash = "sha256:4805911c3a4ec7c3966410053e9ec6a1fecd629117df5adee56dfc9432a1081e"},
|
|
||||||
{file = "importlib_metadata-7.0.1.tar.gz", hash = "sha256:f238736bb06590ae52ac1fab06a3a9ef1d8dce2b7a35b5ab329371d6c8f5d2cc"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.dependencies]
|
|
||||||
zipp = ">=0.5"
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-lint"]
|
|
||||||
perf = ["ipython"]
|
|
||||||
testing = ["flufl.flake8", "importlib-resources (>=1.3)", "packaging", "pyfakefs", "pytest (>=6)", "pytest-black (>=0.3.7)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy (>=0.9.1)", "pytest-perf (>=0.9.2)", "pytest-ruff"]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "iniconfig"
|
name = "iniconfig"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
|
@ -1263,27 +1241,6 @@ files = [
|
||||||
[package.dependencies]
|
[package.dependencies]
|
||||||
h11 = ">=0.9.0,<1"
|
h11 = ">=0.9.0,<1"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "zipp"
|
|
||||||
version = "3.21.0"
|
|
||||||
description = "Backport of pathlib-compatible object wrapper for zip files"
|
|
||||||
optional = false
|
|
||||||
python-versions = ">=3.9"
|
|
||||||
groups = ["main"]
|
|
||||||
markers = "python_version < \"3.10\""
|
|
||||||
files = [
|
|
||||||
{file = "zipp-3.21.0-py3-none-any.whl", hash = "sha256:ac1bbe05fd2991f160ebce24ffbac5f6d11d83dc90891255885223d42b3cd931"},
|
|
||||||
{file = "zipp-3.21.0.tar.gz", hash = "sha256:2c9958f6430a2040341a52eb608ed6dd93ef4392e02ffe219417c1b28b5dd1f4"},
|
|
||||||
]
|
|
||||||
|
|
||||||
[package.extras]
|
|
||||||
check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1)"]
|
|
||||||
cover = ["pytest-cov"]
|
|
||||||
doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"]
|
|
||||||
enabler = ["pytest-enabler (>=2.2)"]
|
|
||||||
test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more-itertools", "pytest (>=6,!=8.1.*)", "pytest-ignore-flaky"]
|
|
||||||
type = ["pytest-mypy"]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zope-event"
|
name = "zope-event"
|
||||||
version = "5.0"
|
version = "5.0"
|
||||||
|
@ -1359,5 +1316,5 @@ testing = ["coverage (>=5.0.3)", "zope.event", "zope.testing"]
|
||||||
|
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.1"
|
lock-version = "2.1"
|
||||||
python-versions = ">=3.9,<3.13"
|
python-versions = ">=3.10,<3.13"
|
||||||
content-hash = "010d6517823f846fe752d72d6e90a7c6f6a056a8be7c473bfb2f466543f41276"
|
content-hash = "92dac9c4dbbdf94b9dc1f9bf5149be1e87be7d0c6b5a2773c6f10f54cb93e76d"
|
||||||
|
|
|
@ -16,7 +16,7 @@ classifiers = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = ">=3.9,<3.13"
|
python = ">=3.10,<3.13"
|
||||||
click = "*"
|
click = "*"
|
||||||
flask = "2.3.2"
|
flask = "2.3.2"
|
||||||
flask-compress = "^1.13"
|
flask-compress = "^1.13"
|
||||||
|
|
|
@ -18,9 +18,9 @@ You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import importlib.resources as importlib_resources
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
from pkg_resources import resource_filename
|
|
||||||
from PySide6 import QtCore, QtWidgets, QtGui
|
from PySide6 import QtCore, QtWidgets, QtGui
|
||||||
|
|
||||||
from . import strings
|
from . import strings
|
||||||
|
@ -548,8 +548,10 @@ class GuiCommon:
|
||||||
Returns the absolute path of a resource
|
Returns the absolute path of a resource
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return resource_filename("onionshare", os.path.join("resources", filename))
|
ref = importlib_resources.files("onionshare.resources") / filename
|
||||||
except KeyError:
|
with importlib_resources.as_file(ref) as path:
|
||||||
|
return str(path)
|
||||||
|
except FileNotFoundError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue