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

Include copy of https://github.com/uktrade/iterable-subprocess #538

Merged
merged 14 commits into from
Nov 23, 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
2 changes: 1 addition & 1 deletion .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: 3.11
architecture: x64
- name: Checkout
uses: actions/checkout@v3
Expand Down
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ documentation is covered by the MIT license.
THE SOFTWARE.

See CONTRIBUTORS file for a full list of contributors.

# 3rd-party code

A copy of https://github.com/uktrade/iterable-subprocess is included at
`datalad_next/iterable_subprocess`. It was written by
Michal Charemza for UK Department of Business and Trade, and was made
available under the terms of the MIT license.
See `datalad_next/iterable_subprocess/LICENSE`.
17 changes: 17 additions & 0 deletions datalad_next/consts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Common constants
"""

# import from "utils", but these really are constants
from datalad.utils import (
on_linux,
on_windows,
)

try:
from shutil import COPY_BUFSIZE
except ImportError: # pragma: no cover
# too old
# from PY3.10
COPY_BUFSIZE = 1024 * 1024 if on_windows else 64 * 1024

from datalad.consts import PRE_INIT_COMMIT_SHA
46 changes: 21 additions & 25 deletions datalad_next/iter_collections/gitworktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
Tuple,
)

from datalad_next.runners import (
DEVNULL,
LineSplitter,
ThreadedRunner,
StdOutCaptureGeneratorProtocol,
from datalad_next.runners import iter_subproc
from datalad_next.itertools import (
decode_bytes,
itemize,
)

from .utils import (
Expand Down Expand Up @@ -250,23 +249,20 @@ def _lsfiles_line2props(


def _git_ls_files(path, *args):
# we use a plain runner to avoid the overhead of a GitRepo instance
runner = ThreadedRunner(
cmd=[
'git', 'ls-files',
# we rely on zero-byte splitting below
'-z',
# otherwise take whatever is coming in
*args,
],
protocol_class=StdOutCaptureGeneratorProtocol,
stdin=DEVNULL,
# run in the directory we want info on
cwd=path,
)
line_splitter = LineSplitter('\0', keep_ends=False)
# for each command output chunk received by the runner
for content in runner.run():
# for each zerobyte-delimited "line" in the output
for line in line_splitter.process(content.decode('utf-8')):
yield line
with iter_subproc(
[
'git', '-C', str(path),
'ls-files',
# we rely on zero-byte splitting below
'-z',
# otherwise take whatever is coming in
*args,
],
) as r:
yield from decode_bytes(
itemize(
r,
separator=b'\0',
keep_ends=False,
)
)
2 changes: 2 additions & 0 deletions datalad_next/iterable_subprocess/.coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
branch = True
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Deploy package to PyPI

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v3
with:
python-version: 3.11

- name: Update version in pyproject.toml from current git tag
run: >-
sed -i "s/0\\.0\\.0\\.dev0/${GITHUB_REF/refs\/tags\/v/}/g" pyproject.toml

- run: |
pip install build
python -m build

- uses: actions/upload-artifact@v3
with:
path: ./dist

deploy:
needs: ['build']
environment: 'pypi'

name: upload release to PyPI
runs-on: ubuntu-latest
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- uses: actions/download-artifact@v3

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages_dir: artifact/
37 changes: 37 additions & 0 deletions datalad_next/iterable_subprocess/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Tests
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:
name: Test
runs-on: ubuntu-20.04
strategy:
matrix:
python-version:
- "3.6.7"
- "3.7.1"
- "3.8.0"
- "3.9.0"
- "3.10.0"
- "3.11.0"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
with:
python-version: '${{ matrix.python-version }}'
- name: "Install funzip"
run: |
sudo apt-get update
sudo apt-get install unzip
- name: "Install package and python dependencies"
run: |
pip install .[dev]
- name: "Test"
run: |
pytest --cov
- uses: codecov/codecov-action@v3
129 changes: 129 additions & 0 deletions datalad_next/iterable_subprocess/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# 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/

# PyBuilder
target/

# 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

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# 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/
21 changes: 21 additions & 0 deletions datalad_next/iterable_subprocess/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Department for International Trade

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading
Loading