Skip to content

Commit ee751d3

Browse files
[ENH] Speed up first completion (#399)
* Remove python 2 compat junk * WIP * Cut as many corners as possible while still remaining with python * Fix type annotation * cpp extension boilerplate * meson build is now working * WIP * wip * Implement a compiled extension which finds modules * Compiled extension tested, working * Don't use `python setup.py <whatever>` * Don't use editable installs for testing * Don't build/test with build isolation * Switch order of args * Correct a bad docstring * Add pybind11 dep to CI... * Enforce c++17 standard * Fix the doc build configuration * Use dependency groups for docs and lint; don't build docs in test * Add 'build' as test dependency * Make tests run in editable mode * Add hypothesis; follow meson-python docs around editable mode * Make epydoc and wheel direct dependencies of pyflyby * Add setuptools and wheel, required by epydoc * Make the install `pure: false`; prevent site-packages pollution * Set lower bound on meson-python to 0.18.0 to enforce PEP639 * Add caching; progress bars aren't quite right yet * Don't bother with progress bars * Add a function to force the cache to be rebuilt * Export rebuild_import_cache at top level * Cleanup * Expand import caching test * Check that updating the mtime of an importer path regenerates the cache * Add `appdirs` to autodoc_mock_imports; remove unused import * Add `prompt-toolkit` as dependency * Fix tests broken by new log messages * Disable test broken due to log messages * Remove patch_stdout calls; that's a problem for another time * Try using two scenarios * Try stripping out log lines; can't do anything else since subprocess... * Add env variable for suppressing pyflyby cache rebuild log messages
1 parent c209f4b commit ee751d3

16 files changed

Lines changed: 579 additions & 318 deletions

File tree

.github/workflows/docs.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ jobs:
1212
- uses: actions/setup-python@v5
1313
- name: Install dependencies
1414
run: |
15-
pip install sphinx sphinx_rtd_theme sphinx-autodoc-typehints
16-
python -m pip install --upgrade pip setuptools wheel
17-
python -m pip install --upgrade rlipython ipykernel==5.4.3 requests jupyter flaky 'notebook<6.1' 'prompt_toolkit<3.0.15' wheel 'jupyter_console>=6.2' 'pytest-cov<3' ipython 'coverage<6.3' pytest-json-report
18-
pip install -e .
15+
pip install -U pip
16+
pip install -v --group docs
1917
- name: Build docs
2018
run: |
2119
make html

.github/workflows/lint.yml

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,22 @@ name: Lint
33
on: [push, pull_request]
44

55
jobs:
6-
test:
6+
lint:
77
runs-on: "ubuntu-latest"
8-
strategy:
9-
fail-fast: false
10-
matrix:
11-
python-version: ["3.13"]
12-
138
steps:
149
- uses: actions/checkout@v5
15-
- name: Set up Python ${{ matrix.python-version }}
10+
- name: Set up Python
1611
uses: actions/setup-python@v5
1712
with:
18-
python-version: ${{ matrix.python-version }}
19-
- name: Install and update Python dependencies on Python 3
13+
python-version: 3.13
14+
- name: Install pyflyby
2015
run: |
21-
python -m pip install --upgrade pip setuptools wheel
22-
python -m pip install --upgrade pyflakes flake8 mypy
23-
python -m pip install types-six
24-
pip install -e .
16+
# Include build dependencies for run time; see
17+
# https://mesonbuild.com/meson-python/how-to-guides/editable-installs.html#build-dependencies
18+
# for details.
19+
pip install meson-python meson ninja pybind11>=2.10.4
20+
pip install setuptools wheel # needed for epydoc
21+
pip install --no-build-isolation -ve . --group lint
2522
- name: Mypy
2623
run: |
2724
mypy lib/python --ignore-missing-imports
@@ -32,4 +29,3 @@ jobs:
3229
- name: Self-tidy-import
3330
run: |
3431
./bin/tidy-imports -d lib/python/ tests/
35-

.github/workflows/test.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ jobs:
3030
uses: actions/setup-python@v5
3131
with:
3232
python-version: ${{ matrix.python-version }}
33-
- name: Install and update Python dependencies on Python 3
33+
- name: Install pyflyby
3434
run: |
35-
python -m pip install --upgrade pip setuptools wheel
36-
python -m pip install --upgrade "pexpect>=3.3" 'pytest<=8' rlipython 'ipykernel>=5.4.3' requests jupyter flaky 'notebook<6.1' wheel 'jupyter_console>=6.2' pytest-cov ipython coverage pytest-json-report hypothesis
37-
pip install -e .
35+
# Include build dependencies for run time; see
36+
# https://mesonbuild.com/meson-python/how-to-guides/editable-installs.html#build-dependencies
37+
# for details.
38+
pip install meson-python meson ninja pybind11>=2.10.4
39+
pip install setuptools wheel # needed for epydoc
40+
pip install --no-build-isolation -ve .[test]
3841
- name: test release build
3942
run: |
40-
python setup.py sdist bdist_wheel
43+
python -m build
4144
- name: compileall
4245
run: |
4346
python -We:invalid -m compileall -f -q lib/ etc/;
@@ -62,10 +65,3 @@ jobs:
6265
name: pytest-timing-${{ matrix.os }}-${{ matrix.python-version }}
6366
path: ./report-*.json
6467
- uses: codecov/codecov-action@v5
65-
- name: Build docs
66-
if: ${{ matrix.python-version == '3.11'}}
67-
run: |
68-
pip install sphinx sphinx_rtd_theme sphinx-autodoc-typehints
69-
cd doc
70-
make html
71-
cd ..

README.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ Emacs support
459459

460460
* To get a ``M-x tidy-imports`` command in GNU Emacs, add to your ``~/.emacs``::
461461

462-
(load "/path/to/pyflyby/lib/emacs/pyflyby.el")
462+
(load "/<site-packages>/pyflyby/share/emacs/site-lisp/pyflyby.el")
463463

464464

465465
- Pyflyby.el doesn't yet work with XEmacs; patches welcome.
@@ -546,5 +546,3 @@ Release
546546

547547
8. Check/update https://github.com/conda-forge/pyflyby-feedstock for new pyflyby
548548
release on conda-forge
549-
550-

doc/api/idents.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ _idents module
22
==============
33
.. automodule:: pyflyby._idents
44
:members:
5-
:exclude-members: _my_iskeyword

doc/conf.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# -- Path setup --------------------------------------------------------------
44
import os
5+
import pathlib
6+
import re
57
import sys
68
sys.path.insert(0, os.path.abspath('../lib/python'))
79
sys.path.insert(0, os.path.abspath('..'))
@@ -11,9 +13,21 @@
1113
copyright = '2019, Karl Chen'
1214
author = 'Karl Chen'
1315
# The full version, including alpha/beta/rc tags
14-
import pyflyby
1516

16-
release = pyflyby.__version__
17+
def find_version():
18+
# Extract version information via regex to avoid importing
19+
project_root = pathlib.Path(__file__).parent.parent
20+
with open(project_root / "lib" / "python" / "pyflyby" / "_version.py") as f:
21+
version_match = re.search(
22+
r"^__version__ = ['\"](?P<version>.*)['\"]$",
23+
f.read(),
24+
re.M,
25+
)
26+
if version_match:
27+
return version_match.group("version")
28+
raise RuntimeError("Unable to find version string.")
29+
30+
release = find_version()
1731

1832

1933
# -- General configuration ---------------------------------------------------
@@ -29,6 +43,12 @@
2943
'private-members': True
3044
}
3145

46+
autodoc_mock_imports = [
47+
"pyflyby._fast_iter_modules",
48+
"appdirs",
49+
"prompt_toolkit",
50+
]
51+
3252
html_theme_options = {
3353
'collapse_navigation': False,
3454
'navigation_depth': -1,

lib/python/pyflyby/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
unload_ipython_extension)
3232
from pyflyby._livepatch import livepatch, xreload
3333
from pyflyby._log import logger
34+
from pyflyby._modules import rebuild_import_cache
3435
from pyflyby._parse import PythonBlock, PythonStatement
3536
from pyflyby._saveframe import saveframe
3637
from pyflyby._saveframe_reader \

lib/python/pyflyby/_idents.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,14 @@
55

66

77
from functools import total_ordering
8-
from keyword import kwlist
8+
from keyword import iskeyword
99
import re
1010

1111
from pyflyby._util import cached_attribute, cmp
1212

1313
from typing import Optional, Tuple, Dict
1414

1515

16-
# Don't consider "print" a keyword, in order to be compatible with user code
17-
# that uses "from __future__ import print_function".
18-
_my_kwlist = list(kwlist)
19-
_my_iskeyword = frozenset(_my_kwlist).__contains__
20-
21-
2216
# TODO: use DottedIdentifier.prefixes
2317
def dotted_prefixes(dotted_name, reverse=False):
2418
"""
@@ -114,7 +108,7 @@ def is_identifier(s: str, dotted: bool = False, prefix: bool = False):
114108
return is_identifier(s + '_', dotted=dotted, prefix=False)
115109
if dotted:
116110
return all(is_identifier(w, dotted=False) for w in s.split('.'))
117-
return s.isidentifier() and not _my_iskeyword(s)
111+
return s.isidentifier() and not iskeyword(s)
118112

119113

120114
def brace_identifiers(text):

0 commit comments

Comments
 (0)