Skip to content

Commit

Permalink
Support 313 (#287)
Browse files Browse the repository at this point in the history
* Add 3.13 to supported versions

* Patch download-artifact vulnerability

* Remove assumption test

* Attempt to work around windows issue

* Skip 32bit musllinux on 313

* Use pyproject cibw skip
  • Loading branch information
Erotemic authored Sep 24, 2024
1 parent 70d1540 commit bf39251
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 45 deletions.
51 changes: 32 additions & 19 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
echo "MOD_DPATH = $MOD_DPATH"
python -m pytest --verbose --cov=line_profiler $MOD_DPATH ../tests
cd ..
- uses: actions/upload-artifact@v4.3.1
- uses: actions/upload-artifact@v4.4.0
name: Upload sdist artifact
with:
name: sdist_wheels
Expand All @@ -123,16 +123,17 @@ jobs:
- ubuntu-latest
- macOS-latest
- windows-latest
cibw_skip:
- '*-win32'
#cibw_skip:
#- '*-win32'
arch:
- auto
steps:
- name: Checkout source
uses: actions/[email protected]
- name: Enable MSVC 64bit
uses: ilammy/msvc-dev-cmd@v1
if: matrix.os == 'windows-latest' && ${{ contains(matrix.cibw_skip, '*-win32') }}
#if: matrix.os == 'windows-latest' && ${{ contains(matrix.cibw_skip, '*-win32') }}
if: matrix.os == 'windows-latest'
- name: Set up QEMU
uses: docker/[email protected]
if: runner.os == 'Linux' && matrix.arch != 'auto'
Expand All @@ -144,7 +145,7 @@ jobs:
output-dir: wheelhouse
config-file: pyproject.toml
env:
CIBW_SKIP: ${{ matrix.cibw_skip }}
#CIBW_SKIP: ${{ matrix.cibw_skip }}
CIBW_ARCHS_LINUX: ${{ matrix.arch }}
- name: Show built files
shell: bash
Expand Down Expand Up @@ -182,7 +183,7 @@ jobs:
with:
file: ./coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}
- uses: actions/upload-artifact@v4.3.1
- uses: actions/upload-artifact@v4.4.0
name: Upload wheels artifact
with:
name: wheels-${{ matrix.os }}-${{ matrix.arch }}
Expand Down Expand Up @@ -216,23 +217,23 @@ jobs:
install-extras: tests-strict,runtime-strict
os: windows-latest
arch: auto
- python-version: '3.12'
- python-version: 3.13.0-rc.2
install-extras: tests-strict,runtime-strict,optional-strict
os: ubuntu-latest
arch: auto
- python-version: '3.12'
- python-version: 3.13.0-rc.2
install-extras: tests-strict,runtime-strict,optional-strict
os: macOS-latest
arch: auto
- python-version: '3.12'
- python-version: 3.13.0-rc.2
install-extras: tests-strict,runtime-strict,optional-strict
os: windows-latest
arch: auto
- python-version: '3.12'
- python-version: 3.13.0-rc.2
install-extras: tests
os: macOS-latest
arch: auto
- python-version: '3.12'
- python-version: 3.13.0-rc.2
install-extras: tests
os: windows-latest
arch: auto
Expand All @@ -256,6 +257,10 @@ jobs:
install-extras: tests,optional
os: ubuntu-latest
arch: auto
- python-version: 3.13.0-rc.2
install-extras: tests,optional
os: ubuntu-latest
arch: auto
- python-version: '3.8'
install-extras: tests,optional
os: macOS-latest
Expand All @@ -276,6 +281,10 @@ jobs:
install-extras: tests,optional
os: macOS-latest
arch: auto
- python-version: 3.13.0-rc.2
install-extras: tests,optional
os: macOS-latest
arch: auto
- python-version: '3.8'
install-extras: tests,optional
os: windows-latest
Expand All @@ -296,6 +305,10 @@ jobs:
install-extras: tests,optional
os: windows-latest
arch: auto
- python-version: 3.13.0-rc.2
install-extras: tests,optional
os: windows-latest
arch: auto
steps:
- name: Checkout source
uses: actions/[email protected]
Expand All @@ -311,7 +324,7 @@ jobs:
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- uses: actions/[email protected].2
- uses: actions/[email protected].8
name: Download wheels
with:
pattern: wheels-*
Expand Down Expand Up @@ -407,13 +420,13 @@ jobs:
steps:
- name: Checkout source
uses: actions/[email protected]
- uses: actions/[email protected].2
- uses: actions/[email protected].8
name: Download wheels
with:
pattern: wheels-*
merge-multiple: true
path: wheelhouse
- uses: actions/[email protected].2
- uses: actions/[email protected].8
name: Download sdist
with:
name: sdist_wheels
Expand Down Expand Up @@ -462,7 +475,7 @@ jobs:
ots stamp wheelhouse/*.whl wheelhouse/*.tar.gz wheelhouse/*.asc
ls -la wheelhouse
twine upload --username __token__ --password "$TWINE_PASSWORD" --repository-url "$TWINE_REPOSITORY_URL" wheelhouse/*.whl wheelhouse/*.tar.gz --skip-existing --verbose || { echo "failed to twine upload" ; exit 1; }
- uses: actions/upload-artifact@v4.3.1
- uses: actions/upload-artifact@v4.4.0
name: Upload deploy artifacts
with:
name: deploy_artifacts
Expand All @@ -482,13 +495,13 @@ jobs:
steps:
- name: Checkout source
uses: actions/[email protected]
- uses: actions/[email protected].2
- uses: actions/[email protected].8
name: Download wheels
with:
pattern: wheels-*
merge-multiple: true
path: wheelhouse
- uses: actions/[email protected].2
- uses: actions/[email protected].8
name: Download sdist
with:
name: sdist_wheels
Expand Down Expand Up @@ -537,7 +550,7 @@ jobs:
ots stamp wheelhouse/*.whl wheelhouse/*.tar.gz wheelhouse/*.asc
ls -la wheelhouse
twine upload --username __token__ --password "$TWINE_PASSWORD" --repository-url "$TWINE_REPOSITORY_URL" wheelhouse/*.whl wheelhouse/*.tar.gz --skip-existing --verbose || { echo "failed to twine upload" ; exit 1; }
- uses: actions/upload-artifact@v4.3.1
- uses: actions/upload-artifact@v4.4.0
name: Upload deploy artifacts
with:
name: deploy_artifacts
Expand All @@ -558,7 +571,7 @@ jobs:
steps:
- name: Checkout source
uses: actions/[email protected]
- uses: actions/[email protected].2
- uses: actions/[email protected].8
name: Download artifacts
with:
name: deploy_artifacts
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changes
* FIX: Fix issue with auto-profile of editable installs #279
* FIX: Lookup OP-codes instead of hard coding them #284
* CHANGE: Drop support for Python 3.6 and Python 3.7
* ENH: Add support for Python 3.13

4.1.3
~~~~~
Expand Down
2 changes: 2 additions & 0 deletions line_profiler/_line_profiler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ cdef class LineProfiler:
self.code_hash_map = {}
self.dupes_map = {}
self.timer_unit = hpTimerUnit()
# Create a data store for thread-local objects
# https://docs.python.org/3/library/threading.html#thread-local-data
self.threaddata = threading.local()

for func in functions:
Expand Down
3 changes: 2 additions & 1 deletion line_profiler/autoprofile/autoprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,5 @@ def run(script_file, ns, prof_mod, profile_imports=False):
tree_profiled = AstTreeProfiler(script_file, prof_mod, profile_imports).profile()

_extend_line_profiler_for_profiling_imports(ns[PROFILER_LOCALS_NAME])
exec(compile(tree_profiled, script_file, 'exec'), ns, ns)
code_obj = compile(tree_profiled, script_file, 'exec')
exec(code_obj, ns, ns)
14 changes: 11 additions & 3 deletions line_profiler/line_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,17 @@ def show_func(filename, start_lineno, func_name, timings, unit,
else:
for lineno, line in zip(linenos, sublines):
nhits, time, per_hit, percent = display.get(lineno, empty)
txt = template % (lineno, nhits, time, per_hit, percent,
line.rstrip('\n').rstrip('\r'))
stream.write(txt)
line_ = line.rstrip('\n').rstrip('\r')
txt = template % (lineno, nhits, time, per_hit, percent, line_)
try:
stream.write(txt)
except UnicodeEncodeError:
# todo: better handling of windows encoding issue
# for now just work around it
line_ = 'UnicodeEncodeError - help wanted for a fix'
txt = template % (lineno, nhits, time, per_hit, percent, line_)
stream.write(txt)

stream.write('\n')
stream.write('\n')

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ omit =[
]

[tool.cibuildwheel]
build = "cp38-* cp39-* cp310-* cp311-* cp312-*"
build = "cp38-* cp39-* cp310-* cp311-* cp312-* cp313-*"
skip = ["*-win32", "cp313-musllinux_i686"]
build-frontend = "build"
build-verbosity = 1
#test-requires = [ "-r requirements/tests-strict.txt",]
Expand Down
25 changes: 17 additions & 8 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,26 @@ def main():
else:
print(f'[run_tests] No installed version of {package_name} found')

# disable coverage in cibuildwheel for now
use_coverage = not is_cibuildwheel()

try:
import pytest
pytest_args = [
'--cov-config', os.fspath(pyproject_fpath),
'--cov-report', 'html',
'--cov-report', 'term',
'--cov-report', 'xml',
'--cov=' + package_name,
pytest_args = []

if use_coverage:
pytest_args += [
'--cov-config', os.fspath(pyproject_fpath),
'--cov-report', 'html',
'--cov-report', 'term',
'--cov-report', 'xml',
'--cov=' + package_name,
]

pytest_args += [
os.fspath(modpath), os.fspath(test_dir)
]
if is_cibuildwheel():
if is_cibuildwheel() and use_coverage:
pytest_args.append('--cov-append')

pytest_args = pytest_args + sys.argv[1:]
Expand All @@ -163,7 +172,7 @@ def main():
retcode = 1
finally:
os.chdir(orig_cwd)
if is_cibuildwheel():
if is_cibuildwheel() and use_coverage:
# for CIBW under linux
copy_coverage_cibuildwheel_docker(f'/home/runner/work/{package_name}/{package_name}')
print('[run_tests] Restoring cwd = {!r}'.format(orig_cwd))
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def run_cythonize(force=False):
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Software Development',
]
Expand Down
9 changes: 0 additions & 9 deletions tests/test_assumptions.py

This file was deleted.

11 changes: 9 additions & 2 deletions tests/test_autoprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,22 @@ def test_autoprofile_script_with_prof_imports():
# pytest.skip('Failing due to the noop bug')

args = [sys.executable, '-m', 'kernprof', '--prof-imports', '-p', 'script.py', '-l', os.fspath(script_fpath)]
proc = ub.cmd(args, cwd=temp_dpath, verbose=2)
proc = ub.cmd(args, cwd=temp_dpath, verbose=0)
print('Kernprof Stdout:')
print(proc.stdout)
print('Kernprof Stderr:')
print(proc.stderr)
print('About to check kernprof return code')
proc.check_returncode()

args = [sys.executable, '-m', 'line_profiler', os.fspath(script_fpath) + '.lprof']
proc = ub.cmd(args, cwd=temp_dpath)
proc = ub.cmd(args, cwd=temp_dpath, verbose=0)
raw_output = proc.stdout
print('Line_profile Stdout:')
print(raw_output)
print('Line_profile Stderr:')
print(proc.stderr)
print('About to check line_profiler return code')
proc.check_returncode()

assert 'Function: add_one' in raw_output
Expand Down
4 changes: 2 additions & 2 deletions tests/test_explicit_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def _demo_explicit_profile_script():
@profile
def fib(n):
a, b = 0, 1
while a < n:
for _ in range(n):
a, b = b, a + b
return a
fib(10)
''')

Expand Down

0 comments on commit bf39251

Please sign in to comment.