Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of pkg_resources due to deprecation #257

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

strategy:
matrix:
python-version: [ "3.8" ]
python-version: [ "3.9", "3.10", "3.11", "3.12" ]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:

strategy:
matrix:
python-version: [ "3.8" ]
python-version: [ "3.9", "3.10", "3.11", "3.12" ]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unittests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
Expand Down
7 changes: 6 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ disable=I,
useless-import-alias, # nice to have
useless-super-delegation, # nice to have
wrong-import-order,
wrong-import-position
wrong-import-position,
use-implicit-booleaness-not-comparison-to-zero,
use-implicit-booleaness-not-comparison-to-string,
unspecified-encoding,
broad-exception-raised,
consider-using-f-string

[REPORTS]

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ future. And Ronda service will be hosted in AWS S3.

## Prerequisites

* python 3.5+
* python 3.9+
* git

### [Optional] Install AWS CLI tool
Expand Down
4 changes: 3 additions & 1 deletion charon/pkgs/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ def __init__(self, title: str, header: str, items: Set[str]):
self.items = items

def generate_index_file_content(self, package_type: str) -> str:
template = None
if package_type == PACKAGE_TYPE_MAVEN:
template = Template(MAVEN_INDEX_TEMPLATE)
elif package_type == PACKAGE_TYPE_NPM:
template = Template(NPM_INDEX_TEMPLATE)
return template.render(index=self)
if template:
return template.render(index=self)


def generate_indexes(
Expand Down
1 change: 1 addition & 0 deletions charon/pkgs/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ def _scan_metadata_paths_from_archive(
path=path, target_dir=tmp_root, is_for_upload=True,
pkg_root=pkg_root, registry=registry
)
package = None
if len(valid_paths) > 1:
version = _scan_for_version(valid_paths[1])
package = NPMPackageMetadata(version, True)
Expand Down
5 changes: 3 additions & 2 deletions charon/utils/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import jsonschema
import yaml
from pkg_resources import resource_stream
import importlib

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -55,7 +55,8 @@ def load_schema(package, schema):
"""
# Read schema from file
try:
resource = resource_stream(package, schema)
resource = importlib.resources.files(package).joinpath(schema).open("rb")
# resource = resource_stream(package, schema)
schema = codecs.getreader('utf-8')(resource)
except ImportError:
logger.error('Unable to find package %s', package)
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ subresource-integrity>=0.2
jsonschema>=4.19.0
urllib3>=1.26.18
semantic-version>=2.10.0
setuptools>=70.0.0
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"subresource-integrity>=0.2",
"jsonschema>=4.19.0",
"urllib3>=1.26.18",
"semantic-version>=2.10.0",
"setuptools>=70.0.0",
"semantic-version>=2.10.0"
],
)
8 changes: 4 additions & 4 deletions tests/utils/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import os

import jsonschema
import pkg_resources
import pytest
import yaml
from flexmock import flexmock
Expand Down Expand Up @@ -65,16 +64,17 @@ def test_read_yaml_bad_package(caplog):
assert 'Unable to find package bad_package' in caplog.text


@pytest.mark.skip(reason="removed pkg_resources, use importlib instead")
def test_read_yaml_file_bad_extract(tmpdir, caplog):
class FakeProvider(object):
def get_resource_stream(self, pkg, rsc):
raise IOError

# pkg_resources.resource_stream() cannot be mocked directly
# Instead mock the module-level function it calls.
(flexmock(pkg_resources)
.should_receive('get_provider')
.and_return(FakeProvider()))
# (flexmock(pkg_resources)
# .should_receive('get_provider')
# .and_return(FakeProvider()))

config_path = os.path.join(str(tmpdir), 'config.yaml')
with open(config_path, 'w'):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ deps = -r requirements-dev.txt
commands = python3 -m pytest --cov=charon {posargs:"tests"}

[testenv:pylint]
deps = pylint==2.9.6
deps = pylint>=2.9.6
commands = python3 -m pylint charon tests

[testenv:flake8]
Expand Down
Loading