Skip to content

Commit

Permalink
1.1.2
Browse files Browse the repository at this point in the history
2. Provide `.dockerignore` file for removing unexpected files in the built docker image.
3. Improve the quality of codes.
4. Make the `flake8` warning validator omit the issues exempted by `black`.
  • Loading branch information
cainmagi committed Feb 14, 2024
1 parent 6927627 commit d4a7ca7
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
max-line-length = 88
extend-ignore =
# See https://github.com/PyCQA/pycodestyle/issues/373
E203, E501
E203, E501, W503, E701, E704
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --ignore=E203,E501 --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --ignore=E203,E501,W503,E701,E704 --statistics
- name: Test with pytest
run: |
python -m pytest tests --slow
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@

### 1.1.2 @ 2/14/2024

#### :mega: New

1. Provide `.dockerignore` file for removing unexpected files in the built docker image.

#### :wrench: Fix

1. Fix: Remove an unexpected in-release package `version` which should only appear during the package building.

#### :floppy_disk: Change

1. Improve the quality of codes.
2. Make the `flake8` warning validator omit the issues exempted by `black`.

### 1.1.1 @ 2/5/2024

#### :wrench: Fix
Expand Down
104 changes: 104 additions & 0 deletions Dockerfile.dockergitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Ignore temp files.
/alpha*
/data*
/legacy*
/docs*
/temp*
/.vscode/*

# Git/Github folders.
.git/
.github/

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
3 changes: 3 additions & 0 deletions pyrightconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
".VSCodeCounter",
".github",
".git",
"dist",
"build",
"*.egg-info",
"**/node_modules",
"**/__pycache__",
"typestubs"
Expand Down
2 changes: 1 addition & 1 deletion syncstream/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def read_serialized(
for val in self.read(size=size)
)

def serve(self, app: flask.Flask) -> None:
def serve(self, app: flask.Flask) -> None: # noqa: C901
"""Provide the service of the host buffer.
The service would be equipped as an independent thread. Each time the request
Expand Down
88 changes: 52 additions & 36 deletions syncstream/mproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,56 @@ def parse_lines(self, lines: Sequence[Union[str, T]]) -> None:
"""
self.storage.extend(lines)

def __read_all(self) -> Tuple[Union[T, str], ...]:
"""Real all lines.
Private method. Use it to read all lines stored in this buffer.
"""
has_last_line = self.last_line.tell() > 0
n_lines = len(self.storage)
if has_last_line:
len_max = self.storage.maxlen
if len_max and n_lines == len_max:
value = self.storage.popleft()
results = (*self.storage, self.last_line.getvalue())
self.storage.appendleft(value)
elif n_lines > 0:
results = (*self.storage, self.last_line.getvalue())
else:
results = (self.last_line.getvalue(),)
return results
else:
return tuple(self.storage)

def __read_n(self, size: int) -> Tuple[Union[T, str], ...]:
"""Real given number of lines.
Private method. Use it to read some lines specified in the argument `size`.
"""
has_last_line = self.last_line.tell() > 0
n_lines = len(self.storage)
len_max = self.storage.maxlen
if has_last_line and len_max and n_lines == len_max:
preserved_value = self.storage.popleft()
else:
preserved_value = None
n_read = min(
size - 1 if has_last_line else size,
n_lines if preserved_value is None else n_lines - 1,
)
results = list()
if n_read > 0:
self.storage.rotate(n_read)
for _ in range(n_read):
value = self.storage.popleft()
results.append(value)
self.storage.append(value)
if has_last_line:
results.append(self.last_line.getvalue())
if preserved_value is not None:
self.storage.appendleft(preserved_value)
return tuple(results)

def read(self, size: Optional[int] = None) -> Tuple[Union[T, str], ...]:
"""Read the records.
Expand All @@ -153,44 +203,10 @@ def read(self, size: Optional[int] = None) -> Tuple[Union[T, str], ...]:
A sequence of fetched record items. Results are sorted in the FIFO order.
"""
with self.__last_line_lock:
has_last_line = self.last_line.tell() > 0
n_lines = len(self.storage)
if size is None:
if has_last_line:
len_max = self.storage.maxlen
if len_max and n_lines == len_max:
value = self.storage.popleft()
results = (*self.storage, self.last_line.getvalue())
self.storage.appendleft(value)
elif n_lines > 0:
results = (*self.storage, self.last_line.getvalue())
else:
results = (self.last_line.getvalue(),)
return results
else:
return tuple(self.storage)
return self.__read_all()
elif size > 0:
len_max = self.storage.maxlen
if has_last_line and len_max and n_lines == len_max:
preserved_value = self.storage.popleft()
else:
preserved_value = None
n_read = min(
size - 1 if has_last_line else size,
n_lines if preserved_value is None else n_lines - 1,
)
results = list()
if n_read > 0:
self.storage.rotate(n_read)
for _ in range(n_read):
value = self.storage.popleft()
results.append(value)
self.storage.append(value)
if has_last_line:
results.append(self.last_line.getvalue())
if preserved_value is not None:
self.storage.appendleft(preserved_value)
return tuple(results)
return self.__read_n(size=size)
else:
return tuple()

Expand Down
Loading

0 comments on commit d4a7ca7

Please sign in to comment.