Skip to content
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

fix: Specify encoding as utf-8 to enforce PEP 597 #2007

Merged
merged 37 commits into from
Sep 15, 2022

Conversation

matthewfeickert
Copy link
Member

@matthewfeickert matthewfeickert commented Sep 14, 2022

Description

Resolves #2006

Explicitly specify the encoding as utf-8 while opening a file to enforce PEP 597. This is future-proofing work to some degree as Python 3.15+ will make utf-8 the default. Also enable the PYTHONWARNDEFAULTENCODING environment variable of PEP 597 in CI to ensure that the default encoding is not used (it must be specified).

Add the flake8-encodings pre-commit hook to enforce PEP 597 (thanks @henryiii for the tip!).

Checklist Before Requesting Reviewer

  • Tests are passing
  • "WIP" removed from the title of the pull request
  • Selected an Assignee for the PR to be responsible for the log summary

Before Merging

For the PR Assignees:

  • Summarize commit messages into a comprehensive review of the PR
* Explicitly specify the encoding as utf-8 while opening a file to enforce PEP 597.
  This is future-proofing work to some degree as Python 3.15+ will make utf-8 the
  default.
   - c.f. https://peps.python.org/pep-0597/
* Add the flake8-encodings pre-commit hook to enforce PEP 597.

@matthewfeickert matthewfeickert added tests pytest CI CI systems, GitHub Actions fix A bug fix labels Sep 14, 2022
@matthewfeickert matthewfeickert self-assigned this Sep 14, 2022
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@matthewfeickert
Copy link
Member Author

I think I need to remove the

# https://peps.python.org/pep-0597/
env:
  PYTHONWARNDEFAULTENCODING: 1

addition in the CI as it is applied to all files, and so pytest itself can cause this to fail

...
  File "/opt/hostedtoolcache/Python/3.10.6/x64/lib/python3.10/site-packages/_pytest/capture.py", line 357, in __init__
    self.tmpfile = open(os.devnull)
EncodingWarning: 'encoding' argument not specified

@codecov
Copy link

codecov bot commented Sep 14, 2022

Codecov Report

Base: 98.28% // Head: 98.28% // No change to project coverage 👍

Coverage data is based on head (dc9f9c7) compared to base (511d8a9).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2007   +/-   ##
=======================================
  Coverage   98.28%   98.28%           
=======================================
  Files          68       68           
  Lines        4479     4479           
  Branches      730      730           
=======================================
  Hits         4402     4402           
  Misses         45       45           
  Partials       32       32           
Flag Coverage Δ
contrib 27.61% <3.22%> (ø)
doctest 61.30% <3.22%> (ø)
unittests-3.10 96.22% <100.00%> (ø)
unittests-3.7 96.20% <100.00%> (ø)
unittests-3.8 96.24% <100.00%> (ø)
unittests-3.9 96.27% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/pyhf/cli/infer.py 97.61% <100.00%> (ø)
src/pyhf/cli/patchset.py 100.00% <100.00%> (ø)
src/pyhf/cli/rootio.py 92.59% <100.00%> (ø)
src/pyhf/cli/spec.py 100.00% <100.00%> (ø)
src/pyhf/schema/loader.py 100.00% <100.00%> (ø)
src/pyhf/writexml.py 95.83% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@matthewfeickert matthewfeickert marked this pull request as ready for review September 14, 2022 21:11
@henryiii
Copy link
Member

Maybe https://pypi.org/project/flake8-encodings/ would be useful? Just checking around.

@matthewfeickert
Copy link
Member Author

Given that this PR only does one thing (add encoding) and running

$ pre-commit run flake8 --all-files
flake8...................................................................Passed

with the flake8-encodings pre-commit hook passes, while it fails on master, I'm going to approve and merge this myself. As always, PRs approved by a single core dev can be reverted as needed by the rest of the dev team.

@matthewfeickert matthewfeickert merged commit 8c5d930 into master Sep 15, 2022
@matthewfeickert matthewfeickert deleted the feat/specify-encoding-for-future-proof branch September 15, 2022 03:35
matthewfeickert added a commit that referenced this pull request Sep 20, 2022
Use fstrings for rtol warning

Use level arg over hardcoded 0.05

add in lru_cache import

fix: Pin codemetapy to v0.3.5 for `--no-extras` functionality (#1995)

* Pin codemetapy to v0.3.5 in the 'current release' test workflow to keep the
  `--no-extras` CLI API option.
   - c.f. proycon/codemetapy#24
* Update lower bounds for scipy and click in codemeta.json and add lower bounds
  for importlib-resources and typing-extensions.

Rename and add to public API

Add in hypotest_kwargs

Add FIXME notice for later. FIX BEFORE MERGE

Update public API repr

ci: Install release candidates for 'current release' test workflow (#1996)

* Use release candidates that are on PyPI for verifiying that the public API
  passes tests. This verifies that the release candidates that users are being
  asked to test reflect the release API.
* Use the latest version of pytest.

refactor: Use urllib.parse.urlsplit over urlparse (#1997)

* Use urllib.parse.urlsplit over urllib.parse.urlparse to avoid having to deal with
  urlparse's 'params' argument which incurs a performance cost.
   - c.f. https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlsplit
   - c.f. https://youtu.be/ABJvdsIANds

Indent docstrings correctly

Use uncorrelated_background API for docstring example

Use rtol in docstring example to avoid warning

drop lru_cache

fix kwargs for autoscan

Bump version: 0.7.0rc3 → 0.7.0rc4

docs: Add Binder Python runtime environment specification (#1998)

* Add binder/runtime.txt to specify the version of Python that is used for the Binder
  environment. Use Python 3.10 as this is the latest version that all pyhf backends will
  work with.
   - c.f. https://mybinder.readthedocs.io/en/latest/howto/languages.html#python

fix: Update codemeta lower bounds for jsonschema, importlib-resources (#2000)

* Update jsonschema lower bound to v4.15.0 and importlib-resources lower bound to v1.4.0
  to match their versions in setup.cfg.
   - Amends PR #1979

docs: Add milestone for 2000 project GitHub items (#2001)

* Add milestone to README for 2000 project GitHub issues and pull requests.

fix: Use codemetapy v2.2.2+ API (#2002)

* Update codemetapy to v2.2.2+ in 'current release' workflow to have access to
  the `--no-extras` CLI API in v2.0+ and reproducible runs.
   - c.f. proycon/codemetapy#24
   - c.f. proycon/codemetapy#26
   - Amends PR #1995
* Use the codemetapy v2.0 API which requires `--inputtype python` to be added.
* Update codemeta.json to follow codemetapy v2.0+ general spec.

fix: Add filterwarnings ignore for protobuf DeprecationWarning (#2005)

* Add a ignore to filterwarnings to avoid a protobuf DeprecationWarning

> DeprecationWarning: Call to deprecated create function FileDescriptor().
> Note: Create unlinked descriptors is going to go away. Please use get/find
> descriptors from generated code or query the descriptor_pool.

from TensorFlow's use of protobuf.

fix: Specify encoding as utf-8 to enforce PEP 597 (#2007)

* Explicitly specify the encoding as utf-8 while opening a file to enforce PEP 597.
  This is future-proofing work to some degree as Python 3.15+ will make utf-8 the
  default.
   - c.f. https://peps.python.org/pep-0597/
* Add the flake8-encodings pre-commit hook to enforce PEP 597.

docs: Add FAQ on reasons for need to downgrade dependencies (#1529)

* Add FAQ explaining how reasons why users might have to manually downgrade dependencies.
   - c.f. PR #1979 for context

docs: Seperate docstrings semantically

Apply sourcery suggestion for simplification

Rename to cached for clarity

Add test for auto through upperlimit API

Use None instead of auto to simplify API

Avoid function level globals

Use np.asarray to avoid copy

Use lower and upper to match scipy terms

Split warning for readability

Add test for rtol warning

Remove tmpdir fixture as not needed for these tests given no writing of output

Add check for return_results

More verbose

fix: Correct concatenate lists instead of adding float to all list elements

Test bounds expansion

test: Update test_plot_results_no_axis baseline image (#2009)

* matplotlib v3.6.0 results in a slightly different baseline image than
  matplotlib v3.5.x, so regenerate the baseline image using matplotlib v3.6.0
  with `pytest --mpl-generate-path=tests/contrib/baseline tests/contrib/test_viz.py`.
* Mark the test_plot_results_no_axis test as xfail for Python 3.7 as matplotlib v3.6.0
  is Python 3.8+ and so the image is guaranteed to be different as Python 3.7 runtimes
  will install matplotlib v3.5.x.

Add upperlimit_fixed_scan to API docs

Add return_results test

move to test_upperlimit_with_kwargs

Move the pop out before evaluation to make everything very clean and clear

Note what scan

Rename to auto_scan

docs: fix link

Provide better coverage and use np.allclose

docs: Add Beojan Stanislaus to contributor list

change auto_scan to toms748_scan

rename fixed_scan to linear_grid_scan

Make intervals module and change API to upper_limit

Rename to pyhf.infer.intervals.upper_limits

get upper_limits.upper_limit working

Also bring along old API

limit to just upper_limit by default

Rearrange

feat: Add internal API to warn of deprecation and future removal

* Add internal API pyhf.exceptions._deprecated_api_warning to alert users to API deprecation
  by raising a subclass of DeprecationWarning and future removal.
* Add test for pyhf.exceptions._deprecated_api_warning to ensure it gets picked up as
  DeprecationWarning.

Note deprecated API

Seperate into condifence intervals section

fix: Use function scope to avoid altering hypotest_args fixture

Make test name explicit

Use deprecated Sphinx note

Add versionadded directives

feat: Add internal API to warn of deprecation and future removal (#2012)

* Add internal API pyhf.exceptions._deprecated_api_warning to alert users to API deprecation
  by raising a subclass of DeprecationWarning and future removal.
* Add test for pyhf.exceptions._deprecated_api_warning to ensure it gets picked up as
  DeprecationWarning.

Update lower bound on scipy as toms748 added in scipy v1.2.0

fixup from autoscan test changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI CI systems, GitHub Actions fix A bug fix tests pytest
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Specify encoding="utf-8" in all open functions for future proofing against Python 3.15+
2 participants