[Python-announce] makepackage 0.1.8 released

2022-12-27 Thread Marcin Kozak
Hello,

I am happy to inform you about a new release of makepackage (v0.1.8). The
new version comes with
- `--cli` being the main flag for a package with the command-line
inference; the `-cli` will work, too, and even the `cli` flag will work,
the latter for backward compatibility;
- bug fix: after creating a package, a log is printed to the console
informing about what's been done.

The makepackage package is available from PyPi, and its code can be found
in GitHub (https://github.com/nyggus/makepackage).

For those who don't know, makepackage enables one to create a Python
package, with and without command-line interface, with just one simple
shell command. It works under both Linux and Windows.

Kind regards,
Marcin
___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com


[Python-announce] perftester: A framework for performance testing of Python functions

2022-09-09 Thread Marcin Kozak
The perftester package enables you to run performance tests of Python
functions/callables. Performance is understood in terms of both execution
time and memory usage. In addition, perftester enables you to run
benchmarks, an important functionality when you need to set limits for your
tests.

You have time_test(), time_benchmark(), memory_usage_test() and
memory_usage_benchmark() functions. In addition, the package offers a pp()
function, for pretty printing of the benchmarking results. Time
benchmarking and testing is based on timeit.repeat() function while memory
benchmarking and testing is based on memory_profiler.memory_usage()
function. The idea behind the package is to offer performance testing using
a simple API, so the functions' APIs are simple and intuitive.

You can run performance testing using perftester in two ways:
* by adding perftester functions to your pytests (or doctests); it's a
simple approach but makes units tests run much longer and the unit tests
are mixed up with performance tests
* by running perftester as a separate testing framework, using a
command-line interface; even if not that simple, this approach is still
quite simple, as you gather performance tests in dedicated files (starting
off with "perftester_" prefix (so, "perftester*.py")

In the latter case, you can also change the default settings in a dedicated
Python module. You can change settings also in other ways, using a config
object. But often, you do not need to do that, as you can do most of what
you need using the above function's APIs.

While perftester is lightweight, at the same time it offers various
functionalities. Hence, especially when deciding to use it as a testing
framework (and not part of pytests), one should spend some time on reading
the documentation. You will find it in the GitHub repository:
https://github.com/nyggus/perftester.

You can install perftester from PyPi (https://pypi.org/project/perftester/):
$ python -m pip install perftester

While there are various ways to benchmark and profile Python code,
perftester is, as far as I know, the first Python framework for performance
testing (not just benchmarking) of Python functions. If you know such a
tool, however, please let me know.

If you like perftester, please consider leaving a star in the repository.

So, happy perftesting!
Marcin
___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com


[Python-announce] makepackage: A lightweight tool for creating a Python package

2022-09-07 Thread Marcin Kozak
Packaging code is a frequent approach in both open-source and business
Python development. You can use various tools, such as Cookiecutter, or you
can package your package manually.

Now, you also have a much simpler solution, a makepackape Python package,
with which it takes just one simple shell command to create a package:
$ makepackage my_package

This will create a Python package named my_package. If you want to add
command-line interface to it, add a --cli flag:
$ makepackage my_package --cli

That's all you need! You will create a package with several functions,
documentation, doctests and pytests; you only need to fill in setup.py in
several places and LICENSE in one place.

makepackage's assumption is simplicity, so it does offer any additional
functionality. This means you can create just one structure (a common one)
of a Python package (with or without a CLI command). After you have called
the above command, you can start developing your package - fill in the
above-mentioned fields, and start replacing the existing functions and
tests. Is there a simpler way?

You can install makepackage from PyPi:
$ pip install makepackage

You can also check out the package's repository in GitHub:
https://github.com/nyggus/makepackage.

Best wishes,
Marcin
___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com


[Python-announce] rounder: A Python package for rounding numbers in complex objects

2022-08-30 Thread Marcin Kozak
Hi all!

When you work with numbers and need to print them, more often than not you
want to round them. You can use the built-in round() function:
>>> round(1.123, 2)
1.12
>>> x = [1.123, 44.32, 12.11234]
>>> [round(x_i, 2) for x_i in x]
[ 1.12, 44.32, 12.11]

However, when you want to round numbers in a more complex Python object,
you need to be careful; you may also need to write a dedicated function to
round numbers in this object, and you may need to update it if the object's
structure changes.

Now, you do not need to do that: use the rounder Python package instead. It
will round numbers in any non-nested or nested Python object, using the
following functions:
* round_object(obj, digits), which rounds numbers in the object to a
provided number of decimal digits
* ceil_object(obj), which rounds numbers up to the nearest integer
* floor_object(obj), which rounds numbers down to the nearest integer
* signif_object(obj, digits), which rounds numbers to a number of
significant digits

So, for example:

>>> obj = {'float': 1.345442, 'list': [1.1222, 1.1226, "string"], 'set':
{1.1222, 1.1226}, 'tuple': (1.1222, 1.1226)}
>>> round_object(obj, 2)
{'float': 1.35, 'list': [1.12, 1.12, "string"], 'set': {1.12}, 'tuple':
(1.12, 1.12)}
>>> signif_object(obj, 3)
{'float': 1.35, 'list': [1.12, 1.12, "string"], 'set': {1.12}, 'tuple':
(1.12, 1.12)}

The package offers also two other functions:
* signif(x, digits), to round a number to significant digits
* map_object(map_function, obj, use_copy=False)

The latter function is a generalized function that applies callable
map_function to all numbers in obj. Consider this simplistic example:
>>> map_object(lambda x: x**2, {'a': 3, 'b': [1, 2, 3]})
{'a': 9, 'b': [1, 4, 9]}

The package works with objects of many different types, not only those
shown above. It works under both Windows and Linux. You can install it from
PyPi:
$ pip install rounder

You will learn more about it from its GitHub repo:
https://github.com/nyggus/rounder.

Happy rounding!

Pozdrawiam,
Marcin
___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com


[Python-announce] Checking conditions with the easycheck package

2022-08-17 Thread Marcin Kozak
We all know that the assert statement should not be used in production
code. Instead, you can use assertion-like functions from the easycheck
package.

Consider the following example. You have a function that fits a statistical
model that requires sample size (n) to be at least 20. So,
>>> assert n >= 20
would not enable the function to continue if the condition is violated. But
it's the assert statement, which should not be used that way. Here's where
easycheck shines:
>>> easycheck.check_if(n >= 20)
is the easiest solution. It would throw AttributeError without a message.
But we can improve this a lot; for example:
>>> class TooSmallSampleSizeError(Exception): ...
>>> easycheck.check_if(n >=20, handle_with=TooSmallSampleSizeError,
message=f"Sample size of {n} is too small for the model to run")

You can also issue warnings with easycheck:
>>> class TooSmallSampleSizeWarning(Warning): ...
>>> easycheck.check_if(n >=20, TooSmallSampleSizeWarning, f"Sample of {n}
can be too small")

If n is smaller than 20, you will see the following warning:
"TooSmallSampleSizeWarning: Sample of 10 is too small"

The easycheck package offers functions dedicated to
- checking general conditions (like above)
- checking an object's type
- checking path(s)
- checking an object's length
- comparing floating-point numbers
- checking function arguments
- combining several conditions

Most of them have aliases dedicated to unit testing. The package's
advantages are the readability of the code, and the ease of using the
package's functions.

You can install easycheck from PyPi (pip install easycheck). You can find
easycheck on GitHub: https://github.com/nyggus/easycheck/. If you like it,
consider leaving a star. Contributions are also welcome!

Enjoy easycheck-ing,
Marcin
___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com