Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Uses f strings (#38)
Browse files Browse the repository at this point in the history
* Uses f strings

* Update requirements.txt

* Update config.yml

* Update config.yml

* Update config.yml

* Update config.yml

* Update config.yml

* Update config.yml

* Update _event_profiler_python.cpp

* const

* update pybind11 version
  • Loading branch information
sdpython committed Jul 20, 2022
1 parent eacc44d commit 61ce595
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 39 deletions.
25 changes: 10 additions & 15 deletions .circleci/config.yml
Expand Up @@ -2,12 +2,13 @@ version: 2
jobs:
build:
docker:
- image: circleci/python:3.10.1
- image: cimg/python:3.10.5

working_directory: ~/repo

steps:
- checkout
- run: python --version

- restore_cache:
keys:
Expand Down Expand Up @@ -47,9 +48,7 @@ jobs:
- run:
name: install dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip install -r requirements.txt
python -m pip install -r requirements.txt
- save_cache:
paths:
Expand All @@ -59,30 +58,26 @@ jobs:
- run:
name: gcc version
command: |
. venv/bin/activate
gcc --version
- run:
name: compile and build
command: |
. venv/bin/activate
python setup.py build_ext --inplace
python setup.py build_ext --inplace
- run:
name: run tests
command: |
. venv/bin/activate
python setup.py unittests
python setup.py unittests
- run:
name: wheel
command: |
. venv/bin/activate
python setup.py bdist_wheel
mkdir -p test-reports/dist
cp dist/*.whl test-reports/dist
mkdir -p test-reports/src
cp -r cpyquickhelper test-reports/src
python setup.py bdist_wheel
mkdir -p test-reports/dist
cp dist/*.whl test-reports/dist
mkdir -p test-reports/src
cp -r cpyquickhelper test-reports/src
#- run:
# name: documentation
Expand Down
2 changes: 1 addition & 1 deletion _doc/examples/plot_profiling.py
Expand Up @@ -146,7 +146,7 @@ def measure_implementation(impl):
ev.stop()

duration = end - begin
msg = "%s: %1.6f microsecond" % (impl, duration / N * 1e6)
msg = f"{impl}: {duration / N * 1000000.0:1.6f} microsecond"
return msg


Expand Down
2 changes: 1 addition & 1 deletion _unittests/ut_io/test_output_capture.py
Expand Up @@ -62,7 +62,7 @@ def callf():
self.assertEqual(out, b'cout1aout2')
else:
if not out.endswith(b'cout1\naout2\n'):
raise AssertionError("###{0}###".format(out))
raise AssertionError(f"###{out}###")

def test_c_output_capture_py(self):
def callf():
Expand Down
8 changes: 4 additions & 4 deletions _unittests/ut_profiling/test_event_profiler.py
Expand Up @@ -163,7 +163,7 @@ def test_debug(self):
end = perf_counter()
ev.stop()
duration = end - begin
msg = "evppy: %1.6f microsecond" % (duration / N * 1e6)
msg = f"evppy: {duration / N * 1000000.0:1.6f} microsecond"
self.assertNotEmpty(msg)
if __name__ == "__main__":
print(msg)
Expand All @@ -181,7 +181,7 @@ def test_debug_pybind11(self):
end = perf_counter()
ev.stop()
duration = end - begin
msg = "evcpy+: %1.6f microsecond" % (duration / N * 1e6)
msg = f"evcpy+: {duration / N * 1000000.0:1.6f} microsecond"
self.assertNotEmpty(msg)
if __name__ == "__main__":
print(msg)
Expand All @@ -197,7 +197,7 @@ def test_debug_c(self):
_profiling_delete()
_profiling_stop()
duration = end - begin
msg = "evcap+: %1.6f microsecond" % (duration / N * 1e6)
msg = f"evcap+: {duration / N * 1000000.0:1.6f} microsecond"
self.assertNotEmpty(msg)
if __name__ == "__main__":
print(msg)
Expand All @@ -215,7 +215,7 @@ def test_debug_logging(self):
end = perf_counter()
ev.stop()
duration = end - begin
msg = "logg: %1.6f microsecond" % (duration / N * 1e6)
msg = f"logg: {duration / N * 1000000.0:1.6f} microsecond"
self.assertNotEmpty(msg)
if __name__ == "__main__":
print(msg)
Expand Down
4 changes: 2 additions & 2 deletions cpyquickhelper/io/stdhelper.py
Expand Up @@ -35,7 +35,7 @@ def capture_output_c(function_to_call) -> Tuple:
if isinstance(res, tuple): # pragma: no cover
return (fout, ) + res
raise TypeError( # pragma no cover
"Unexpected return type '{0}'.".format(type(res)))
f"Unexpected return type '{type(res)}'.")


def capture_output_py(function_to_call) -> Tuple[str, str]:
Expand Down Expand Up @@ -77,4 +77,4 @@ def capture_output(function_to_call, lang="py"):
return capture_output_py(function_to_call)
if lang == "c":
return capture_output_c(function_to_call)
raise ValueError("lang must be 'py' or 'c' not '{0}'".format(lang))
raise ValueError(f"lang must be 'py' or 'c' not '{lang}'")
3 changes: 1 addition & 2 deletions cpyquickhelper/numbers/speed_measure.py
Expand Up @@ -41,8 +41,7 @@ def measure_time(stmt, context=None, repeat=10, number=50, div_by_number=False,
"""
if not callable(stmt) and not isinstance(stmt, str):
raise TypeError(
"stmt is not callable or a string but is of type %r."
"" % type(stmt))
f"stmt is not callable or a string but is of type {type(stmt)!r}.")
if context is None:
context = {}

Expand Down
8 changes: 4 additions & 4 deletions cpyquickhelper/numbers/weighted_dataframe.py
Expand Up @@ -81,7 +81,7 @@ def construct_from_string(cls, string):
If a class cannot be constructed from this 'string'.
"""
if not string.startswith("WD"): # pragma no cover
raise TypeError("Unable to parse '{0}'".format(string))
raise TypeError(f"Unable to parse '{string}'")
val = string[2:].strip('() ').split(",")
if len(val) == 1 and val[0]:
val = float(val[0])
Expand All @@ -90,10 +90,10 @@ def construct_from_string(cls, string):
elif len(val) == 0 or (len(val) == 1 and val[0] == ''):
val = numpy.nan
else: # pragma no cover
raise TypeError("Unable to parse '{0}'".format(string))
raise TypeError(f"Unable to parse '{string}'")
if isinstance(val, tuple):
if len(val) != 2: # pragma no cover
raise TypeError("Unable to parse '{0}'".format(string))
raise TypeError(f"Unable to parse '{string}'")
return WeightedDouble(val[0], val[1])
return WeightedDouble(val)

Expand Down Expand Up @@ -176,7 +176,7 @@ def __getattr__(self, attr):
return getattr(obj, attr)
if attr == '_ndarray':
return numpy.array(self)
raise AttributeError("Unkown attribute '{0}'".format(attr))
raise AttributeError(f"Unkown attribute '{attr}'")


class WeightedArray(PandasArray):
Expand Down
4 changes: 2 additions & 2 deletions cpyquickhelper/profiling/_event_profiler_python.cpp
Expand Up @@ -3,7 +3,7 @@

#ifndef SKIP_PYTHON
#include <pybind11/pybind11.h>
#include <pybind11/operators.h>
//#include <pybind11/operators.h>
#include <pybind11/stl.h>
#include <pybind11/numpy.h>
#include <pybind11/functional.h>
Expand Down Expand Up @@ -50,7 +50,7 @@ C++ buffer for @see cl EventProfiler.)pbdoc"
self.register_pyinstance((void*)f.ptr());
}, "Registers the python instance with holds this one.");

pyev.def("__iter__", [](CEventProfiler &v) {
pyev.def("__iter__", [](const CEventProfiler &v) {
return py::make_iterator(v.begin(), v.end());
}, py::keep_alive<0, 1>()); /* Keep vector alive while iterator is used */

Expand Down
2 changes: 1 addition & 1 deletion cpyquickhelper/profiling/event_profiler.py
Expand Up @@ -163,7 +163,7 @@ def _setup_profiler(self):
sys.setprofile(_profiling_log_event)
else:
raise ValueError( # pragma: no cover
"Unexpected value for impl=%r." % self._impl)
f"Unexpected value for impl={self._impl!r}.")

def _restore_profiler(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Expand Up @@ -9,7 +9,7 @@ nbconvert>=6.0.3,!=6.3.0,!=6.4.0,!=6.5.0
numpy>=1.16
pandas>=1.0
pillow
pybind11
pybind11<2.10.0
pycodestyle
pylint>=2.14.0
pyquickhelper>=1.11.3697
Expand Down
12 changes: 6 additions & 6 deletions setup.py
Expand Up @@ -11,7 +11,7 @@
#########

project_var_name = "cpyquickhelper"
versionPython = "%s.%s" % (sys.version_info.major, sys.version_info.minor)
versionPython = f"{sys.version_info.major}.{sys.version_info.minor}"
path = "Lib/site-packages/" + project_var_name
readme = 'README.rst'
history = "HISTORY.rst"
Expand Down Expand Up @@ -165,7 +165,7 @@ def get_extensions():
name = 'fast_dict_cpy'
ext_fast_dict_cpy = Extension(
pattern1 % name,
['cpyquickhelper/fastdata/%s.pyx' % name],
[f'cpyquickhelper/fastdata/{name}.pyx'],
include_dirs=[numpy.get_include()],
extra_compile_args=["-O3"],
define_macros=define_macros,
Expand Down Expand Up @@ -266,7 +266,7 @@ def get_extensions():
name = 'direct_blas_lapack'
ext_blas = Extension(
pattern1 % name,
['cpyquickhelper/numbers/%s.pyx' % name],
[f'cpyquickhelper/numbers/{name}.pyx'],
include_dirs=[numpy.get_include()],
extra_compile_args=["-O3"],
define_macros=define_macros)
Expand Down Expand Up @@ -358,7 +358,7 @@ def get_extensions():
ext_modules = get_extensions()
except ImportError as e:
warnings.warn(
"Unable to build C++ extension with missing dependencies %r." % e)
f"Unable to build C++ extension with missing dependencies {e!r}.")
ext_modules = None


Expand All @@ -379,7 +379,7 @@ def get_extensions():
packages=packages,
package_dir=package_dir,
package_data=package_data,
setup_requires=["pybind11", "cython", "scipy", "numpy", "pyquicksetup"],
install_requires=["pybind11", "numpy>=1.16",
setup_requires=["pybind11<2.10.0", "cython", "scipy", "numpy", "pyquicksetup"],
install_requires=["pybind11<2.10.0", "numpy>=1.16",
"cython", 'scipy', 'pandas>=1.0'],
)

0 comments on commit 61ce595

Please sign in to comment.