Parsers for CJWorkbench modules.
Workbench modules may optionally depend on the latest version of this Python
package for its cjwparse.api.parse_file() function.
Installation
This is meant to be used within a Docker container. It depends on executables
/usr/bin/(csv|json|xls|xlsx)-to-arrow.
Your Dockerfile might look something like this:
FROM arrow-tools:v0.0.11 AS arrow-tools
FROM python:3.8.1-buster AS main
COPY --from=arrow-tools /usr/bin/csv-to-arrow /usr/bin/csv-to-arrow
COPY --from=arrow-tools /usr/bin/json-to-arrow /usr/bin/json-to-arrow
COPY --from=arrow-tools /usr/bin/xls-to-arrow /usr/bin/xls-to-arrow
COPY --from=arrow-tools /usr/bin/xlsx-to-arrow /usr/bin/xlsx-to-arrow
# And now that these binaries are accessible, you can install cjwparse...
Usage
import pyarrow
from cjwparse.api import parse_file
# Convert a CSV file 'input.csv' to Arrow file 'output.arrow'
input_path = Path("input.csv")
input_path.write_bytes(b"A,B\n1,2")
output_path = Path("output.arrow")
parse_file(input_path, output_path=output_path, has_headers=False)
# Read the output
with pyarrow.ipc.open_file(output_path) as reader:
table = reader.read_all()
Developing
- Run tests:
docker build . - Write a failing unit test in
tests/ - Make it pass by editing code in
cjwparse/ black cjwparse maintenance tests && isort cjwparse maintenance tests && python3 ./setup.py extract_messages- Submit a pull request
Be very, very, very careful to preserve a consistent API. Workbench will upgrade this dependency without module authors' explicit consent. Add new features; fix bugs. Never change functionality.
I18n
Marking strings for translation
Strings in cjwparse can be marked for translation using
cjwparse.i18n._trans_cjwparse. Each translation message must have a
(unique) ID. ICU is supported for the content. For example:
from .i18n import _trans_cjwparse
err = "Error 404"
with_arguments = _trans_cjwparse(
"greatapi.exception.message",
"Something is wrong: {error}",
{"error": err}
)
without_arguments = _trans_cjwparse(
"greatapi.exception.general",
"Something is wrong",
)
Workbench is wired to accept the return value of _trans_cjwparse
wherever an error/warning or quick fix is expected.
Creating po catalogs
Calls to _trans_cjwparse can (and must) be parsed to create cjwparse's .po files.
Update the .po files with:
./setup.py extract_messages
The first time you run this, you'll need to install dependencies: pip3 install .[maintenance]
Unit testing
In case a _trans_cjwparse invocation needs to be unit tested, you can use cjwparse.testing.i18n.cjwparse_i18n_message
in a manner similar to the following:
from cjwparse.testing.i18n import cjwparse_i18n_message
import with_arguments, without_arguments
assert with_arguments == cjwparse_i18n_message("greatapi.exception.message", {"error": "Error 404"})
assert without_arguments == cjwparse_i18n_message("greatapi.exception.general")
Message deprecation
Never delete a trans() call: each message ID, once assigned, must be preserved
forever.
When there is no more code path to a trans() call, move it to
cjwparse/i18n/_deprecated_i18n_messages.py. The file is only read by
extraction code. It is never executed.
Publishing
- Write a new
__version__tocjwparse/__init__.py. Adhere to semver. (As changes must be backwards-compatible, the version will always start with1and look like1.x.y.) - Prepend notes to
CHANGELOG.mdabout the new version git commitgit tag v1.x.ygit push --tags && git push- Wait for Travis to push our changes to PyPI
Metadata
Release files for cjwparse 2.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cjwparse-2.0.2.tar.gz | 19.6 kB | Without provenance | Details for cjwparse-2.0.2.tar.gz |
Release files / cjwparse-2.0.2.tar.gz
| Download URL | cjwparse-2.0.2.tar.gz |
|---|---|
| Size | 19.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f389b80f6385edfc28bd5f91c4bbcc128fe11539bd80ef6b97b479b6949d3c20
|
|
BLAKE2b-256 checksum How to use checksums |
21c340e137421c5e4120b901ebb10d795e301d3b653326fa3bfe272819a32504
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.9.4
|
Security for cjwparse 2.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.