Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Oct 14, 2022
7 parents 3d7dd47 + 5434cb0 + 063aecd + 3c3b444 + d2e277d + 7aa3e4c + ac7a0dd commit a55b024
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 33 deletions.
4 changes: 2 additions & 2 deletions CHANGES.rst
Expand Up @@ -27,7 +27,7 @@ Changes

Documentation changes
^^^^^^^^^^^^^^^^^^^^^
* #3554: Changed requires to requests in the pyproject.toml example in the :ref:`Dependency management section of the Quickstart guide <userguide/quickstart:dependency-management>` -- by :user:`mfbutner`
* #3554: Changed requires to requests in the pyproject.toml example in the :doc:`Dependency management section of the Quickstart guide <userguide/quickstart>` -- by :user:`mfbutner`

Misc
^^^^
Expand Down Expand Up @@ -63,7 +63,7 @@ Changes

Documentation changes
^^^^^^^^^^^^^^^^^^^^^
* #3538: Corrected documentation on how to use the `legacy-editable` mode.
* #3538: Corrected documentation on how to use the ``legacy-editable`` mode.


v65.0.2
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/3569.misc.rst
@@ -0,0 +1,2 @@
Improved information about conflicting entries in the current working directory
and editable install (in documentation and as an informational warning).
1 change: 1 addition & 0 deletions changelog.d/3576.misc.rst
@@ -0,0 +1 @@
Updated version of ``validate_pyproject``.
1 change: 1 addition & 0 deletions changelog.d/3624.change.rst
@@ -0,0 +1 @@
Fixed editable install for multi-module/no-package ``src``-layout projects.
11 changes: 11 additions & 0 deletions docs/userguide/development_mode.rst
Expand Up @@ -155,6 +155,10 @@ Limitations
projects structured using :ref:`flat-layout` is still **experimental**.
If you experience problems, you can try converting your package structure
to the :ref:`src-layout`.
- File system entries in the current working directory
whose names coincidentally match installed packages
may take precedence in :doc:`Python's import system <python:reference/import>`.
Users are encouraged to avoid such scenarios [#cwd]_.

.. attention::
Editable installs are **not a perfect replacement for regular installs**
Expand Down Expand Up @@ -240,6 +244,13 @@ More information is available on the text of :pep:`PEP 660 <660#what-to-put-in-t
packages created with ``pkgutil`` or ``pkg_namespaces``, however this is not
officially supported.
.. [#cwd]
Techniques like the :ref:`src-layout` or tooling-specific options like
`tox's changedir <https://tox.wiki/en/stable/config.html#conf-changedir>`_
can be used to prevent such kinds of situations (chekout `this blog post
<https://blog.ganssle.io/articles/2019/08/test-as-installed.html>`_ for more
insights).
.. [#installer]
For this workaround to work, the installer tool needs to support legacy
editable installations. (Future versions of ``pip``, for example, may drop
Expand Down
7 changes: 4 additions & 3 deletions setuptools/build_meta.py
Expand Up @@ -437,9 +437,10 @@ def build_editable(
info_dir = self._get_dist_info_dir(metadata_directory)
opts = ["--dist-info-dir", info_dir] if info_dir else []
cmd = ["editable_wheel", *opts, *self._editable_args(config_settings)]
return self._build_with_temp_dir(
cmd, ".whl", wheel_directory, config_settings
)
with suppress_known_deprecation():
return self._build_with_temp_dir(
cmd, ".whl", wheel_directory, config_settings
)

def get_requires_for_build_editable(self, config_settings=None):
return self.get_requires_for_build_wheel(config_settings)
Expand Down
17 changes: 13 additions & 4 deletions setuptools/command/editable_wheel.py
Expand Up @@ -294,7 +294,7 @@ def _safely_run(self, cmd_name: str):
msg = f"""{traceback.format_exc()}\n
If you are seeing this warning it is very likely that a setuptools
plugin or customization overrides the `{cmd_name}` command, without
tacking into consideration how editable installs run build steps
taking into consideration how editable installs run build steps
starting from v64.0.0.
Plugin authors and developers relying on custom build steps are encouraged
Expand Down Expand Up @@ -393,7 +393,7 @@ def __call__(self, wheel: "WheelFile", files: List[str], mapping: Dict[str, str]
def __enter__(self):
msg = f"""
Editable install will be performed using .pth file to extend `sys.path` with:
{self.path_entries!r}
{list(map(os.fspath, self.path_entries))!r}
"""
_logger.warning(msg + _LENIENT_WARNING)
return self
Expand Down Expand Up @@ -503,7 +503,11 @@ def __enter__(self):
return self

def __exit__(self, _exc_type, _exc_value, _traceback):
...
msg = """\n
Please be careful with folders in your working directory with the same
name as your package as they may take precedence during imports.
"""
warnings.warn(msg, InformationOnly)


def _can_symlink_files(base_dir: Path) -> bool:
Expand Down Expand Up @@ -551,13 +555,18 @@ def _simple_layout(
False
>>> _simple_layout(['a', 'a.b'], {"": "src", "a.b": "_ab"}, "/tmp/myproj")
False
>>> # Special cases, no packages yet:
>>> _simple_layout([], {"": "src"}, "/tmp/myproj")
True
>>> _simple_layout([], {"a": "_a", "": "src"}, "/tmp/myproj")
False
"""
layout = {
pkg: find_package_path(pkg, package_dir, project_dir)
for pkg in packages
}
if not layout:
return False
return set(package_dir) in ({}, {""})
parent = os.path.commonpath([_parent_path(k, v) for k, v in layout.items()])
return all(
_normalize_path(Path(parent, *key.split('.'))) == _normalize_path(value)
Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/test.py
Expand Up @@ -118,7 +118,7 @@ def test_args(self):
return list(self._test_args())

def _test_args(self):
if not self.test_suite and sys.version_info >= (2, 7):
if not self.test_suite:
yield 'discover'
if self.verbose:
yield '--verbose'
Expand Down
4 changes: 2 additions & 2 deletions setuptools/config/_validate_pyproject/extra_validations.py
Expand Up @@ -5,12 +5,12 @@

from typing import Mapping, TypeVar

from .fastjsonschema_exceptions import JsonSchemaValueException
from .error_reporting import ValidationError

T = TypeVar("T", bound=Mapping)


class RedefiningStaticFieldAsDynamic(JsonSchemaValueException):
class RedefiningStaticFieldAsDynamic(ValidationError):
"""According to PEP 621:
Build back-ends MUST raise an error if the metadata specifies a field
Expand Down
24 changes: 12 additions & 12 deletions setuptools/config/_validate_pyproject/fastjsonschema_validations.py

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions setuptools/config/_validate_pyproject/formats.py
Expand Up @@ -111,14 +111,16 @@ def pep517_backend_reference(value: str) -> bool:


def _download_classifiers() -> str:
import cgi
import ssl
from email.message import Message
from urllib.request import urlopen

url = "https://pypi.org/pypi?:action=list_classifiers"
with urlopen(url) as response:
content_type = response.getheader("content-type", "text/plain")
encoding = cgi.parse_header(content_type)[1].get("charset", "utf-8")
return response.read().decode(encoding)
context = ssl.create_default_context()
with urlopen(url, context=context) as response:
headers = Message()
headers["content_type"] = response.getheader("content-type", "text/plain")
return response.read().decode(headers.get_param("charset", "utf-8"))


class _TroveClassifier:
Expand Down
3 changes: 2 additions & 1 deletion setuptools/config/expand.py
Expand Up @@ -42,6 +42,7 @@
Union,
cast
)
from pathlib import Path
from types import ModuleType

from distutils.errors import DistutilsOptionError
Expand Down Expand Up @@ -149,7 +150,7 @@ def _read_file(filepath: Union[bytes, _Path]) -> str:


def _assert_local(filepath: _Path, root_dir: str):
if not os.path.abspath(filepath).startswith(root_dir):
if Path(os.path.abspath(root_dir)) not in Path(os.path.abspath(filepath)).parents:
msg = f"Cannot access {filepath!r} (or anything outside {root_dir!r})"
raise DistutilsOptionError(msg)

Expand Down
2 changes: 0 additions & 2 deletions setuptools/monkey.py
Expand Up @@ -71,8 +71,6 @@ def patch_all():
distutils.filelist.findall = setuptools.findall

needs_warehouse = (
sys.version_info < (2, 7, 13)
or
(3, 4) < sys.version_info < (3, 4, 6)
or
(3, 5) < sys.version_info <= (3, 5, 3)
Expand Down
9 changes: 9 additions & 0 deletions setuptools/tests/config/test_expand.py
@@ -1,4 +1,5 @@
import os
from pathlib import Path

import pytest

Expand Down Expand Up @@ -45,6 +46,10 @@ def test_read_files(tmp_path, monkeypatch):
}
write_files(files, dir_)

secrets = Path(str(dir_) + "secrets")
secrets.mkdir(exist_ok=True)
write_files({"secrets.txt": "secret keys"}, secrets)

with monkeypatch.context() as m:
m.chdir(dir_)
assert expand.read_files(list(files)) == "a\nb\nc"
Expand All @@ -53,6 +58,10 @@ def test_read_files(tmp_path, monkeypatch):
with pytest.raises(DistutilsOptionError, match=cannot_access_msg):
expand.read_files(["../a.txt"])

cannot_access_secrets_msg = r"Cannot access '.*secrets\.txt'"
with pytest.raises(DistutilsOptionError, match=cannot_access_secrets_msg):
expand.read_files(["../dir_secrets/secrets.txt"])

# Make sure the same APIs work outside cwd
assert expand.read_files(list(files), dir_) == "a\nb\nc"
with pytest.raises(DistutilsOptionError, match=cannot_access_msg):
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Expand Up @@ -60,7 +60,7 @@ commands =
[testenv:generate-validation-code]
skip_install = True
deps =
validate-pyproject[all]==0.7.1
validate-pyproject[all]==0.10.1
commands =
python -m tools.generate_validation_code

Expand Down

0 comments on commit a55b024

Please sign in to comment.