Skip to content

Add py.typed marker to pylsp imports to be analysed with mypy #641

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

Merged
merged 1 commit into from
May 12, 2025

Conversation

krassowski
Copy link
Member

Closes #640

Copy link
Member

@ccordoba12 ccordoba12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @krassowski!

@ccordoba12 ccordoba12 merged commit 70d9f12 into python-lsp:develop May 12, 2025
10 checks passed
@dalthviz
Copy link
Contributor

Quick note/question here, doesn't the new py.typed file needs to be included over MANIFEST.in? I think something like include pylsp/py.typed should be added there?

@ccordoba12
Copy link
Member

I think you're right @dalthviz, good catch!

@krassowski, could you take care of that in another PR?

@krassowski
Copy link
Member Author

Hmm. I ran python -m build and checked that py.typed gets included when opening this PR, I double checked now:

$ tar -tzf dist/python_lsp_server-1.12.3.dev2+g70d9f12.tar.gz | grep py.typed
python_lsp_server-1.12.3.dev2+g70d9f12/pylsp/py.typed

$ unzip -l dist/python_lsp_server-1.12.3.dev2+g70d9f12-py3-none-any.whl | grep py.typed
        0  2025-05-13 12:18   pylsp/py.typed

I think this is happening because setuptools 69+ includes py.typed by default; this was implemented in:

I think I will still open another PR to add it to MANIFEST.in just to avoid ambiguity and in case someone builds it with an older setuptools version.

For reference the RELEASE.md mentions build:

7. python -bb -X dev -W error -m build

and we use setuptools backend but allow versions older than 69:

[build-system]
requires = ["setuptools>=61.2.0", "setuptools_scm[toml]>=3.4.3"]

@krassowski krassowski deleted the add-py.typed branch May 13, 2025 12:35
@krassowski
Copy link
Member Author

Just confirming that downgrading setuptools by changing:

diff --git a/pyproject.toml b/pyproject.toml
index f9c6a52..b718e42 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -2,7 +2,7 @@
 # Copyright 2021- Python Language Server Contributors.
 
 [build-system]
-requires = ["setuptools>=61.2.0", "setuptools_scm[toml]>=3.4.3"]
+requires = ["setuptools<=68.0.0", "setuptools_scm[toml]>=3.4.3"]
 build-backend = "setuptools.build_meta"
 
 [project]

Leads to py.typed not being included in the wheel anymore.

However, adding include pylsp/py.typed does not add it back; neither are other non-Python files listed in the MANIFEST.in (README.md, versioneer.py, ruff.toml, .pylintrc`) included in the wheel:

$ unzip -l dist/python_lsp_server-1.12.3.*.whl
Archive:  dist/python_lsp_server-1.12.3.dev2+g70d9f12.d20250513-py3-none-any.whl
  Length      Date    Time    Name
---------  ---------- -----   ----
      762  2025-03-31 12:45   pylsp/__init__.py
     3831  2025-03-31 12:45   pylsp/__main__.py
     9866  2025-05-10 07:34   pylsp/_utils.py
       47  2025-05-13 12:44   pylsp/_version.py
     2551  2025-05-10 07:34   pylsp/hookspecs.py
     2050  2023-09-09 10:48   pylsp/lsp.py
    35469  2025-05-12 14:55   pylsp/python_lsp.py
     2768  2023-09-09 10:48   pylsp/text_edit.py
     3834  2025-03-31 12:45   pylsp/uris.py
    22672  2025-05-13 12:18   pylsp/workspace.py
      105  2021-07-09 14:35   pylsp/config/__init__.py
     6956  2025-05-09 19:37   pylsp/config/config.py
     2370  2025-03-31 12:45   pylsp/config/flake8_conf.py
     1268  2025-03-31 12:45   pylsp/config/pycodestyle_conf.py
     2753  2025-03-31 12:45   pylsp/config/source.py
      105  2021-07-09 14:35   pylsp/plugins/__init__.py
     4390  2025-03-31 12:45   pylsp/plugins/_resolvers.py
     2887  2025-03-31 12:45   pylsp/plugins/_rope_task_handle.py
     3185  2025-03-31 12:45   pylsp/plugins/autopep8_format.py
     2670  2025-03-31 12:45   pylsp/plugins/definition.py
     8335  2025-03-31 12:45   pylsp/plugins/flake8_lint.py
     7035  2023-09-09 10:48   pylsp/plugins/folding.py
     1100  2025-03-31 12:45   pylsp/plugins/highlight.py
     1657  2025-05-10 07:34   pylsp/plugins/hover.py
    10502  2025-05-10 07:34   pylsp/plugins/jedi_completion.py
     1908  2025-03-31 12:45   pylsp/plugins/jedi_rename.py
     1826  2025-03-31 12:45   pylsp/plugins/mccabe_lint.py
     1530  2025-03-31 12:45   pylsp/plugins/preload_imports.py
     4011  2025-03-31 12:45   pylsp/plugins/pycodestyle_lint.py
     4172  2025-03-31 12:45   pylsp/plugins/pydocstyle_lint.py
     3137  2025-03-31 12:45   pylsp/plugins/pyflakes_lint.py
    12372  2025-03-31 12:45   pylsp/plugins/pylint_lint.py
     1036  2025-03-31 12:45   pylsp/plugins/references.py
    13357  2025-03-31 12:45   pylsp/plugins/rope_autoimport.py
     5913  2025-03-31 12:45   pylsp/plugins/rope_completion.py
     2574  2025-03-31 12:45   pylsp/plugins/signature.py
     7944  2025-03-31 12:45   pylsp/plugins/symbols.py
     6785  2025-03-31 12:45   pylsp/plugins/yapf_format.py
     1147  2025-05-13 12:44   python_lsp_server-1.12.3.dev2+g70d9f12.d20250513.dist-info/LICENSE
    10943  2025-05-13 12:44   python_lsp_server-1.12.3.dev2+g70d9f12.d20250513.dist-info/METADATA
       92  2025-05-13 12:44   python_lsp_server-1.12.3.dev2+g70d9f12.d20250513.dist-info/WHEEL
      860  2025-05-13 12:44   python_lsp_server-1.12.3.dev2+g70d9f12.d20250513.dist-info/entry_points.txt
        6  2025-05-13 12:44   python_lsp_server-1.12.3.dev2+g70d9f12.d20250513.dist-info/top_level.txt
     3806  2025-05-13 12:44   python_lsp_server-1.12.3.dev2+g70d9f12.d20250513.dist-info/RECORD
---------                     -------
   222587                     44 files

I think this might be an interaction with setuptools-scm? I am not sure. It seems like pinning setuptools>=69.0.0 is a safer bet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should we add py.typed marker?
3 participants