Closed jaraco closed 5 months ago
Might be worth enabling encoding warnings
Here's where I do that for my projects:
https://github.com/jaraco/skeleton/blob/68ac292eb37ce92e992e6fab05a44ad86f32e8f1/tox.ini#L4-L5
I scanned through the equivalent config for towncrier (the noxfile), but I don't immediately see how a environment variable could be set. It's also not obvious to me if it should be set for tests only or for all sessions. Reading through the docs, the env
parameter exists for run()
and as a property on the session, but it's unclear what it's role is. Reading between the lines, it sounds like env
is similar to the env
parameter to subprocess.Popen(env=)
- that is, if supplied, it replaces the default environment rather than supplementing it, which is very different to tox's setenv (which supplements the environment variables).
Interestingly, running tox-to-nox
on that config creates a noxfile that uses session.env.__setitem__
in each session to set the value:
import nox
@nox.session(python='/Users/jaraco/Library/Application Support/pipx/venvs/nox/bin/python')
def diffcov(session):
"""run tests and check that diff from main is covered"""
session.env['PYTHONWARNDEFAULTENCODING'] = '1'
session.install('diff-cover')
session.install('-e', '.')
session.run('pytest', '--cov-report', 'xml')
session.run('diff-cover', 'coverage.xml', '--compare-branch=origin/main', '--html-report', 'diffcov.html')
session.run('diff-cover', 'coverage.xml', '--compare-branch=origin/main', '--fail-under=100')
@nox.session(python='/Users/jaraco/Library/Application Support/pipx/venvs/nox/bin/python')
def docs(session):
"""build the documentation"""
session.env['PYTHONWARNDEFAULTENCODING'] = '1'
session.install('-e', '.')
session.chdir('docs')
session.run('python', '-m', 'sphinx', '-W', '--keep-going', '.', '/Users/jaraco/code/jaraco/skeleton/build/html')
session.run('python', '-m', 'sphinxlint', '--jobs', '1')
@nox.session(python='/Users/jaraco/Library/Application Support/pipx/venvs/nox/bin/python')
def finalize(session):
"""assemble changelog and tag a release"""
session.env['PYTHONWARNDEFAULTENCODING'] = '1'
session.install('towncrier', 'jaraco.develop >= 7.23')
session.run('python', '-m', 'jaraco.develop.finalize')
@nox.session(python='/Users/jaraco/Library/Application Support/pipx/venvs/nox/bin/python')
def py(session):
"""perform primary checks (tests, style, types, coverage)"""
session.env['PYTHONWARNDEFAULTENCODING'] = '1'
session.install('-e', '.')
session.run('pytest')
@nox.session(python='/Users/jaraco/Library/Application Support/pipx/venvs/nox/bin/python')
def release(session):
"""publish the package to PyPI and GitHub"""
session.env['TWINE_USERNAME'] = '__token__'
session.install('build', 'twine>=3', 'jaraco.develop>=7.1')
session.run('python', '-c', 'import shutil; shutil.rmtree('dist', ignore_errors=True)')
session.run('python', '-m', 'build')
session.run('python', '-m', 'twine', 'upload', 'dist/*')
session.run('python', '-m', 'jaraco.develop.create-github-release')
Adding the environment variable to the tests does reveal that there are many more locations in the code where the warning is triggered:
Here's a distilled list of the violations:
towncrier tests/encoding-warnings @ nox -e tests-3.12 | grep EncodingWarning | sort -V | uniq | sed -e 's|.*/site-packages/||g'
nox > Running session tests-3.12
nox > Re-using existing virtual environment at .nox/tests-3-12.
nox > python -m pip install Twisted 'coverage[toml]'
nox > python -m pip install .
nox > coverage run --module twisted.trial towncrier
nox > Session tests-3.12 was successful.
nox > Running session coverage_report
nox > Re-using existing virtual environment at .nox/coverage_report.
nox > python -m pip install 'coverage[toml]'
nox > coverage combine
nox > coverage report
nox > Session coverage_report was successful.
nox > Ran multiple sessions:
nox > * tests-3.12: success
nox > * coverage_report: success
towncrier/build.py:169: EncodingWarning: 'encoding' argument not specified
towncrier/create.py:141: EncodingWarning: 'encoding' argument not specified
towncrier/test/helpers.py:21: EncodingWarning: 'encoding' argument not specified
towncrier/test/helpers.py:32: EncodingWarning: 'encoding' argument not specified
towncrier/test/helpers.py:68: EncodingWarning: 'encoding' argument not specified
towncrier/test/helpers.py:70: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:26: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:29: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:32: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:36: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:39: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:41: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:43: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:45: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:47: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:49: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:52: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:55: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:108: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:133: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:171: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:173: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:222: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:224: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:243: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:283: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:290: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:394: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:396: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:411: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:413: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:435: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:437: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:463: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:465: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:484: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:486: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:534: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:537: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:592: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:635: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:678: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:725: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:822: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:844: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:911: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:913: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:915: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:917: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:987: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:990: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:1044: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:1108: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:1110: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:1268: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_build.py:1270: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_check.py:29: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_check.py:156: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_check.py:179: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_check.py:308: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_check.py:316: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_check.py:318: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_create.py:38: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_create.py:262: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_create.py:269: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_project.py:34: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_project.py:47: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_project.py:116: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_project.py:139: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_project.py:145: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_project.py:165: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_project.py:188: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_write.py:79: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_write.py:103: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_write.py:210: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_write.py:247: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_write.py:268: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_write.py:287: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_write.py:297: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_write.py:319: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_write.py:338: EncodingWarning: 'encoding' argument not specified
towncrier/test/test_write.py:361: EncodingWarning: 'encoding' argument not specified
82 checks is a little steep to fix by hand. I looked and ruff doesn't (yet) support fixing the warnings. How do you feel about enabling the warnings but not fixing all of them yet?
@jaraco with this PR, I can see that the import warning are gone.
Please consider update the documentation to mention that UTF-8 is mandatory and I think that after that we can merge this.
Thanks again and sorry for the delay
Thanks for the changes. I have merged this. For now, we should go with UTF-8 as we don't have the "energy" to consider other encoding types.
If someone wants other encoding type, they can send a report and a PR.
Closes #561
Description
Checklist
src/towncrier/newsfragments/
. Describe your change and include important information. Your change will be included in the public release notes.docs/tutorial.rst
is still up-to-date.docs/cli.rst
reflects those changes.docs/configuration.rst
reflects those changes.