Skip to content

Commit

Permalink
First part of pkg_resources library deprecation. (PR #7990)
Browse files Browse the repository at this point in the history
# Description

First part that migrates the use of the deprecated library: pkg_resources. This part preserves the venv caching mechanism that allows us to speed up the test suite. The second part should migrate this mechanism

Related to #6668

# Self Check:

Strike through any lines that are not applicable (`~~line~~`) then check the box

- [ ] Attached issue to pull request
- [ ] Changelog entry
- [ ] Type annotations are present
- [ ] Code is clear and sufficiently documented
- [ ] No (preventable) type errors (check using make mypy or make mypy-diff)
- [ ] Sufficient test cases (reproduces the bug/tests the requested feature)
- [ ] Correct, in line with design
- [ ] End user documentation is included or an issue is created for end-user documentation (add ref to issue here: )
- [ ] If this PR fixes a race condition in the test suite, also push the fix to the relevant stable branche(s) (see [test-fixes](https://internal.inmanta.com/development/core/tasks/build-master.html#test-fixes) for more info)
  • Loading branch information
hlloreda authored and inmantaci committed Oct 3, 2024
1 parent ced309b commit d048e72
Show file tree
Hide file tree
Showing 26 changed files with 672 additions and 405 deletions.
3 changes: 0 additions & 3 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ updates:
# Allow both direct and indirect updates for all packages
- dependency-type: "all"
ignore:
# #6668
- dependency-name: "setuptools"
update-types: ["version-update:semver-major"]
- dependency-name: "pytest-inmanta-extensions"
versions: [">=0.0.1"]
- dependency-name: "pydantic"
Expand Down
4 changes: 4 additions & 0 deletions changelogs/unreleased/drop-pkg-resources-first-part.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
description: First part of `pkg_resources` library deprecation.
change-type: patch
destination-branches: [master, iso7]
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# serve to show the default.
import importlib.metadata
import shutil
import sys, os, pkg_resources, datetime
import sys, os, datetime
from importlib.metadata import PackageNotFoundError
from sphinx.errors import ConfigError

Expand Down
14 changes: 1 addition & 13 deletions mypy-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -892,13 +892,8 @@ src/inmanta/execute/scheduler.py:0: error: Missing type parameters for generic t
src/inmanta/execute/scheduler.py:0: error: "<subclass of "DelayedResultVariable" and "RelationAttributeVariable">" has no attribute "attribute" [attr-defined]
src/inmanta/execute/scheduler.py:0: error: "<subclass of "DelayedResultVariable" and "RelationAttributeVariable">" has no attribute "attribute" [attr-defined]
src/inmanta/execute/scheduler.py:0: error: "<subclass of "DelayedResultVariable" and "RelationAttributeVariable">" has no attribute "attribute" [attr-defined]
src/inmanta/env.py:0: error: Argument 1 to "parse_requirements" has incompatible type "Sequence[CanonicalRequirement]"; expected "Sequence[str]" [arg-type]
src/inmanta/env.py:0: error: "type[WorkingSet]" has no attribute "_build_master" [attr-defined]
src/inmanta/env.py:0: error: Incompatible types in assignment (expression has type "WorkingSet", variable has type "Iterable[DistInfoDistribution]") [assignment]
src/inmanta/env.py:0: note: Following member(s) of "WorkingSet" have conflicts:
src/inmanta/env.py:0: note: Expected:
src/inmanta/env.py:0: note: def __iter__(self) -> Iterator[DistInfoDistribution]
src/inmanta/env.py:0: note: Got:
src/inmanta/env.py:0: note: def __iter__(self) -> Iterator[Distribution]
src/inmanta/env.py:0: error: Incompatible return value type (got "tuple[str | None, Loader | None] | None", expected "tuple[str | None, Loader] | None") [return-value]
src/inmanta/env.py:0: error: Item "None" of "ModuleSpec | None" has no attribute "submodule_search_locations" [union-attr]
src/inmanta/env.py:0: error: Item "None" of "ModuleSpec | None" has no attribute "submodule_search_locations" [union-attr]
Expand All @@ -909,7 +904,6 @@ src/inmanta/compiler/__init__.py:0: error: Incompatible types in assignment (exp
src/inmanta/compiler/__init__.py:0: error: Incompatible types in assignment (expression has type "Namespace | None", variable has type "Namespace") [assignment]
src/inmanta/compiler/__init__.py:0: error: Missing type parameters for generic type "ResultVariable" [type-arg]
src/inmanta/module.py:0: error: Missing type parameters for generic type Module [type-arg]
src/inmanta/module.py:0: error: Incompatible return value type (got "SpecifierSet", expected "str") [return-value]
src/inmanta/module.py:0: error: Returning Any from function declared to return "Mapping[str, object]" [no-any-return]
src/inmanta/module.py:0: error: Argument 1 to "Metadata" has incompatible type "**Mapping[str, object]"; expected "str" [arg-type]
src/inmanta/module.py:0: error: Argument 1 to "Metadata" has incompatible type "**Mapping[str, object]"; expected "str | None" [arg-type]
Expand All @@ -926,18 +920,12 @@ src/inmanta/module.py:0: error: Missing type parameters for generic type Module
src/inmanta/module.py:0: error: Missing type parameters for generic type Module [type-arg]
src/inmanta/module.py:0: error: Missing type parameters for generic type Module [type-arg]
src/inmanta/module.py:0: error: Missing type parameters for generic type Module [type-arg]
src/inmanta/module.py:0: error: Unsupported operand types for in ("Version" and "InmantaModuleRequirement") [operator]
src/inmanta/module.py:0: error: Missing type parameters for generic type Module [type-arg]
src/inmanta/module.py:0: error: Missing type parameters for generic type Module [type-arg]
src/inmanta/module.py:0: error: Missing type parameters for generic type Module [type-arg]
src/inmanta/module.py:0: error: Missing type parameters for generic type Module [type-arg]
src/inmanta/module.py:0: error: Missing type parameters for generic type Module [type-arg]
src/inmanta/module.py:0: error: Missing type parameters for generic type Module [type-arg]
src/inmanta/module.py:0: error: Incompatible return value type (got "pkg_resources._vendored_packaging.version.Version", expected "packaging.version.Version | None") [return-value]
src/inmanta/module.py:0: error: "str" has no attribute "filter" [attr-defined]
src/inmanta/module.py:0: error: Argument 4 to "__best_for_compiler_version" of "ModuleV1" has incompatible type "pkg_resources._vendored_packaging.version.Version"; expected "packaging.version.Version" [arg-type]
src/inmanta/module.py:0: error: Incompatible return value type (got "pkg_resources._vendored_packaging.version.Version", expected "packaging.version.Version | None") [return-value]
src/inmanta/module.py:0: error: Incompatible return value type (got "pkg_resources._vendored_packaging.version.Version", expected "packaging.version.Version | None") [return-value]
src/inmanta/moduletool.py:0: error: Skipping analyzing "cookiecutter.main": module is installed, but missing library stubs or py.typed marker [import-untyped]
src/inmanta/moduletool.py:0: error: Missing type parameters for generic type "ModuleLike" [type-arg]
src/inmanta/moduletool.py:0: error: Missing type parameters for generic type Module [type-arg]
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"logfire>=0.46,<2.0",
"more-itertools>=8,<11",
"opentelemetry-instrumentation-asyncpg~=0.46b0",
# leave upper bound floating for fast-moving and extremely stable packaging
"packaging>=21.3",
# upper bound on packaging because we use a non-public API that might change in any (non-SemVer) version
"packaging>=21.3,<24.2",
# pip>=21.3 required for editable pyproject.toml + setup.cfg based install support
"pip>=21.3",
"ply~=3.0",
Expand All @@ -29,7 +29,7 @@
"pynacl~=1.5",
"python-dateutil~=2.0",
"pyyaml~=6.0",
"setuptools<71",
"setuptools",
"texttable~=1.0",
"tornado~=6.0",
# lower bound because of ilevkivskyi/typing_inspect#100
Expand Down
5 changes: 2 additions & 3 deletions src/inmanta/agent/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@
from dataclasses import dataclass
from typing import Any, Dict, Optional, Sequence, cast

import pkg_resources

import inmanta.types
import inmanta.util
import packaging.requirements
from inmanta import const
from inmanta.agent import config as cfg
from inmanta.agent import resourcepool
Expand Down Expand Up @@ -300,7 +299,7 @@ async def create_and_install_environment(self, blueprint: EnvBlueprint) -> None:
await asyncio.get_running_loop().run_in_executor(self.io_threadpool, self.init_env)
if len(req): # install_for_config expects at least 1 requirement or a path to install
await self.async_install_for_config(
requirements=list(pkg_resources.parse_requirements(req)),
requirements=[packaging.requirements.Requirement(requirement_string=e) for e in req],
config=blueprint.pip_config,
)

Expand Down
4 changes: 1 addition & 3 deletions src/inmanta/agent/in_process_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from concurrent.futures.thread import ThreadPoolExecutor
from typing import Any, Optional

import pkg_resources

import inmanta.agent.cache
import inmanta.protocol
import inmanta.util
Expand Down Expand Up @@ -603,7 +601,7 @@ async def _install(self, blueprint: executor.ExecutorBlueprint) -> None:
await loop.run_in_executor(
self.thread_pool,
self._env.install_for_config,
list(pkg_resources.parse_requirements(blueprint.requirements)),
inmanta.util.parse_requirements(blueprint.requirements),
blueprint.pip_config,
)
await loop.run_in_executor(self.thread_pool, self._loader.deploy_version, blueprint.sources)
Loading

0 comments on commit d048e72

Please sign in to comment.