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

Str first #1

Merged
merged 11 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]

ignore = W503,E501
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
# You can use PyPy versions in python-version.
# For example, pypy2.7 and pypy3.9
matrix:
python-version: ["3.9", "3.10", "3.11", "pypy3.9"]
python-version: ["3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ __pycache__
test-output.xml
site/*
docs/pydoc.md
*.prof
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
rev: 6.0.0
hooks:
- id: flake8
args: [--ignore, E501]
args: ['--config=.flake8']
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.2
hooks:
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@
"python.testing.unittestEnabled": false,
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"python.analysis.extraPaths": ["${workspaceFolder}/merge-files/src"],
"python.envFile": "${workspaceFolder}/.env"
"python.envFile": "${workspaceFolder}/.env",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none"
}
34 changes: 22 additions & 12 deletions arranges/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@ type. The reason for this is so the machine-generated command line help is
flat and readable by humans.

It it kinda grew into a monster so I've split it out into this separate
package. It gives a couple of classes for dealing with ranges:

* `Range`, a class that can be constructed from Python-style slice notation
strings (e.g. `"1:10"`, `"0x00:0xff`, `":"`), range-likes, iterables of
int-like objects. It has convenient properties lke being iterable, immutable,
has a stable string representation and matching hash, it can be treated
like a `set` and its constructor is compatible with `range` and `slice`.
* The `Ranges` class is similar but supports holes in ranges - it's an ordered,
mutable list of non-overlapping `Range` objects that simplifies as data is
added.
package. The main feature is a pair of classes that can represent ranges:

* `Segment` is a class that can be treated like a `set` and its constructor is
compatible with `range` and `slice`. It is derived from `str` so serializes
without custom JSON encoders. It is immutable, hashable and has a stable
string representation.
* `Ranges` is an ordered `tuple` of `Segment`s. It is also immutable and
derived from `str` so serializes without custom JSON encoders like the above.
It can be constructed from comma-separated Python-style slice notation strings
(e.g. `"1:10, 20:"`, `"0x00:0xff` and `":"`), integers, `slice`s, `range`s,
integers and (nested) iterables of the above.
* An `inf` singleton that is a `float` with a value of `math.inf` but has an
`__index__` that returns `sys.maxsize` and compares equal to infinity and
`maxsize`, and its string representation is `"inf"`.

The range classes are designed to be used as fields in Pydantic `BaseModel`s,
but they can be used anywhere you need a range. They are not designed with
speed in mind, and comparisons usually use the canonical string form by
converting other things into `Ranges` objects.

## Constraints

Expand All @@ -26,8 +35,9 @@ I made it to select lines or bytes in a stream of data, so it:
* only supports `int`s;
* does not allow negative indices, the minimum is 0 and the maximum is
unbounded;
* it's compatible with `range` and `slice`, but `step` is fixed to `1`. This
may change in the future;
* it's compatible with `range` and `slice`, but `step` is fixed to `1`. If
you pass something with a step into its constructor it'll be converted to
a list of `int`s (`range(0, 10, 2)` becomes `"0,2,4,6,8"`);
* does not support duplicate ranges. Ranges are merged together as they are
added to the `Ranges` object;
* it is unpydantic in that its constructors are duck-typed, which is what I
Expand Down
6 changes: 3 additions & 3 deletions arranges/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[project]
name = "arranges"
description = "Mergable range object for use in Pydantic classes"
version = "0.0.6"
version = "0.1.0"
authors = [
{ name = "Gareth Davidson", email = "[email protected]" }
]

readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.10"
classifiers = [
"Programming Language :: Python :: 3",
"License :: Public Domain", # WTFPL
Expand All @@ -21,7 +21,7 @@ dependencies = [

[project.optional-dependencies]
dev = [
"pydantic",
"pydantic==2.3.0",
"flake8",
"pre-commit",
"pytest",
Expand Down
2 changes: 1 addition & 1 deletion arranges/src/arranges/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from arranges.range import Range # noqa
from arranges.ranges import Ranges # noqa
from arranges.segment import Segment # noqa
from arranges.utils import inf # noqa
Loading