Skip to content

Commit

Permalink
Clean up after the 2.4.0 release. (pex-tool#2430)
Browse files Browse the repository at this point in the history
+ Fix a missed item in the changelog.
+ Clean up the `--exclude` Pip patch and improve its logging.

---------

Co-authored-by: Huon Wilson <[email protected]>
  • Loading branch information
jsirois and huonw authored Jun 12, 2024
1 parent 2f35cec commit 1817514
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
20 changes: 15 additions & 5 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,24 @@ arguments appear first on the synthesized command line and the
explicitly passed arguments appear last so that the explicit arguments
can trump (which is how Python handles this).

Finally, several bugs existing in the `--exclude` implementation since
its introduction are now fixed and the feature is greatly improved to
act on excludes eagerly, never traversing them in the resolve process;
thus avoiding downloads associated with them as well as potentially
failing metadata extraction & wheel builds for ill-behaved sdists.
Several bugs existing in the `--exclude` implementation since its
introduction are now fixed and the feature is greatly improved to act on
excludes eagerly, never traversing them in the resolve process; thus
avoiding downloads associated with them as well as potentially failing
metadata extraction & wheel builds for ill-behaved sdists.

Finally, a bug was fixed in `pex3 lock export` for lock files containing
either locked VCS requirements or locked local project directories.
Previously, these were exported with a `<project name>==<version>`
requirement, which lost fidelity with the input requirement. Now they
are exported with their original requirement form. Further, since the
`--hash` of these styles of locked requirement are unuseable outside
Pex, a new `--format` option of `pip-no-hashes` is introduced for the
adventurous.

* Implement support for preserving and injecting Python args. (#2427)
* Fix `--exclude`. (#2409)
* Fix `pex3 lock export` handling of exotic reqs. (#2423)

## 2.3.3

Expand Down
33 changes: 27 additions & 6 deletions pex/pip/excludes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,28 @@
from pex.typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Optional
from typing import Mapping, Optional


class PatchContext(object):
_PEX_EXCLUDES_FILE_ENV_VAR_NAME = "_PEX_EXCLUDES_FILE"

@classmethod
def load_exclude_configuration(cls):
# type: () -> ExcludeConfiguration

excludes_file = os.environ.pop(cls._PEX_EXCLUDES_FILE_ENV_VAR_NAME)
with open(excludes_file) as fp:
return ExcludeConfiguration.create(json.load(fp))

@classmethod
def dump_exclude_configuration(cls, exclude_configuration):
# type: (ExcludeConfiguration) -> Mapping[str, str]

patches_file = os.path.join(safe_mkdtemp(), "excludes.json")
with open(patches_file, "w") as excludes_fp:
json.dump([str(req) for req in exclude_configuration], excludes_fp)
return {cls._PEX_EXCLUDES_FILE_ENV_VAR_NAME: patches_file}


def patch(exclude_configuration):
Expand All @@ -21,13 +42,13 @@ def patch(exclude_configuration):
if not exclude_configuration:
return None

patches_dir = safe_mkdtemp()
with open(os.path.join(patches_dir, "excludes.json"), "w") as excludes_fp:
json.dump([str(req) for req in exclude_configuration], excludes_fp)

return DownloadObserver(
analyzer=None,
patch_set=PatchSet.create(
Patch.from_code_resource(__name__, "requires.py", _PEX_EXCLUDES_FILE=excludes_fp.name)
Patch.from_code_resource(
__name__,
"requires.py",
**PatchContext.dump_exclude_configuration(exclude_configuration)
)
),
)
12 changes: 3 additions & 9 deletions pex/pip/excludes/requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@

from __future__ import absolute_import, print_function

import json
import logging
import os

logger = logging.getLogger(__name__)


def patch():
from pex.dist_metadata import Requirement
from pex.exclude_configuration import ExcludeConfiguration
from pex.pip.excludes import PatchContext

# N.B.: The following environment variable is used by the Pex runtime to control Pip and must
# be kept in-sync with `__init__.py`.
excludes_file = os.environ.pop("_PEX_EXCLUDES_FILE")
with open(excludes_file) as fp:
exclude_configuration = ExcludeConfiguration.create(json.load(fp))
exclude_configuration = PatchContext.load_exclude_configuration()

def create_requires(orig_requires):
def requires(self, *args, **kwargs):
Expand All @@ -28,7 +22,7 @@ def requires(self, *args, **kwargs):
if excluded_by:
logger.debug(
"[{type}: patched {orig_requires}] Excluded {dep} from {dist} due to "
"configured excludes: {excludes}".format(
"Pex-configured excludes: {excludes}".format(
orig_requires=orig_requires,
type=type(self),
dep=repr(str(req)),
Expand Down

0 comments on commit 1817514

Please sign in to comment.