python-cath 0.2.0__py3-none-any.whl → 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_cath/__init__.py +2 -6
- python_cath/__main__.py +10 -18
- python_cath/concat.py +49 -0
- {python_cath-0.2.0.dist-info → python_cath-0.3.0.dist-info}/METADATA +15 -122
- python_cath-0.3.0.dist-info/RECORD +10 -0
- {python_cath-0.2.0.dist-info → python_cath-0.3.0.dist-info}/WHEEL +1 -1
- python_cath-0.2.0.dist-info/RECORD +0 -9
- {python_cath-0.2.0.dist-info → python_cath-0.3.0.dist-info}/entry_points.txt +0 -0
- {python_cath-0.2.0.dist-info → python_cath-0.3.0.dist-info/licenses}/LICENSE +0 -0
python_cath/__init__.py
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# mypy: disable-error-code="attr-defined"
|
|
2
2
|
"""Cat files w/ headers"""
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
from importlib.metadata import version, PackageNotFoundError
|
|
6
|
-
except ImportError: # pragma: no cover
|
|
7
|
-
from importlib_metadata import version, PackageNotFoundError
|
|
8
|
-
|
|
4
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
9
5
|
|
|
10
6
|
try:
|
|
11
7
|
__version__ = version(__name__)
|
python_cath/__main__.py
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# mypy: disable-error-code="attr-defined"
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import random
|
|
5
|
-
from enum import Enum
|
|
6
|
-
from typing import List, Optional
|
|
3
|
+
from typing import List
|
|
7
4
|
|
|
8
5
|
import typer
|
|
9
|
-
from rich.console import Console
|
|
10
|
-
|
|
11
6
|
from python_cath import __version__
|
|
12
|
-
from python_cath.
|
|
7
|
+
from python_cath.concat import concat
|
|
8
|
+
from rich.console import Console
|
|
13
9
|
|
|
14
10
|
app = typer.Typer(
|
|
15
|
-
name="python-cath",
|
|
11
|
+
name="python-cath",
|
|
12
|
+
help="Cat files w/ headers",
|
|
13
|
+
add_completion=False,
|
|
16
14
|
)
|
|
17
15
|
console = Console()
|
|
18
16
|
|
|
19
17
|
|
|
20
|
-
def version_callback(value: bool):
|
|
18
|
+
def version_callback(value: bool) -> None:
|
|
21
19
|
"""Prints the version of the package."""
|
|
22
20
|
if value:
|
|
23
21
|
console.print(
|
|
@@ -26,16 +24,10 @@ def version_callback(value: bool):
|
|
|
26
24
|
raise typer.Exit()
|
|
27
25
|
|
|
28
26
|
|
|
29
|
-
def concat(file_list, output_file):
|
|
30
|
-
os.system(f"head -1 {file_list[0]} > {output_file}")
|
|
31
|
-
for afile in file_list:
|
|
32
|
-
os.system(f"tail -n +2 {afile} >> {output_file}")
|
|
33
|
-
|
|
34
|
-
|
|
35
27
|
@app.command()
|
|
36
28
|
def main(
|
|
37
29
|
file_list: List[str] = typer.Argument(...),
|
|
38
30
|
output_file: str = typer.Argument(...),
|
|
39
|
-
):
|
|
40
|
-
"""
|
|
31
|
+
) -> None:
|
|
32
|
+
"""Concatenate CSV files with a shared header into output_file."""
|
|
41
33
|
concat(file_list, output_file)
|
python_cath/concat.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import shutil
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def concat(file_list, output_file):
|
|
6
|
+
"""Concatenate CSV files that share the same header.
|
|
7
|
+
|
|
8
|
+
Args:
|
|
9
|
+
file_list: Paths to input files.
|
|
10
|
+
output_file: Path to write the concatenated output.
|
|
11
|
+
|
|
12
|
+
Raises:
|
|
13
|
+
ValueError: If no input files are provided, any file has an empty
|
|
14
|
+
header, an input file path collides with the output file, or
|
|
15
|
+
file headers differ.
|
|
16
|
+
"""
|
|
17
|
+
file_list = list(file_list)
|
|
18
|
+
if not file_list:
|
|
19
|
+
raise ValueError("file_list must not be empty")
|
|
20
|
+
|
|
21
|
+
real_output = os.path.realpath(output_file)
|
|
22
|
+
for afile in file_list:
|
|
23
|
+
if os.path.realpath(afile) == real_output:
|
|
24
|
+
raise ValueError(
|
|
25
|
+
f"Input file {afile!r} is the same path as the output file"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
# First pass: read and validate headers one file at a time
|
|
29
|
+
file_headers = {}
|
|
30
|
+
for afile in file_list:
|
|
31
|
+
with open(afile, encoding="utf-8") as fh:
|
|
32
|
+
header = fh.readline().rstrip("\n")
|
|
33
|
+
if not header:
|
|
34
|
+
raise ValueError(f"File {afile!r} has an empty or missing header")
|
|
35
|
+
file_headers[afile] = header
|
|
36
|
+
|
|
37
|
+
unique_headers = set(file_headers.values())
|
|
38
|
+
if len(unique_headers) > 1:
|
|
39
|
+
detail = ", ".join(f"{f!r}: {h!r}" for f, h in file_headers.items())
|
|
40
|
+
raise ValueError(f"Headers do not match: {detail}")
|
|
41
|
+
|
|
42
|
+
# Second pass: write output one file at a time
|
|
43
|
+
shared_header = next(iter(unique_headers))
|
|
44
|
+
with open(output_file, "w", encoding="utf-8") as out:
|
|
45
|
+
out.write(shared_header + "\n")
|
|
46
|
+
for afile in file_list:
|
|
47
|
+
with open(afile, encoding="utf-8") as fh:
|
|
48
|
+
fh.readline() # skip header
|
|
49
|
+
shutil.copyfileobj(fh, out)
|
|
@@ -1,24 +1,27 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: python-cath
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Cat files w/ headers
|
|
5
|
-
Home-page: https://github.com/samesense/python-cath
|
|
6
5
|
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
7
|
Author: samesense
|
|
8
8
|
Author-email: candptea@gmail.com
|
|
9
|
-
Requires-Python: >=3.
|
|
9
|
+
Requires-Python: >=3.10,<4.0
|
|
10
10
|
Classifier: Development Status :: 3 - Alpha
|
|
11
11
|
Classifier: Intended Audience :: Developers
|
|
12
12
|
Classifier: License :: OSI Approved :: MIT License
|
|
13
13
|
Classifier: Operating System :: OS Independent
|
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
20
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
18
|
-
Requires-Dist:
|
|
19
|
-
Requires-Dist:
|
|
20
|
-
Requires-Dist:
|
|
21
|
-
|
|
21
|
+
Requires-Dist: pre-commit (>=3.0.0,<4.0.0)
|
|
22
|
+
Requires-Dist: rich (>=10.0.0)
|
|
23
|
+
Requires-Dist: typer[all] (>=0.9.0,<0.10.0)
|
|
24
|
+
Project-URL: Homepage, https://github.com/samesense/python-cath
|
|
22
25
|
Project-URL: Repository, https://github.com/samesense/python-cath
|
|
23
26
|
Description-Content-Type: text/markdown
|
|
24
27
|
|
|
@@ -39,116 +42,6 @@ Description-Content-Type: text/markdown
|
|
|
39
42
|
Cat files w/ headers
|
|
40
43
|
</div>
|
|
41
44
|
|
|
42
|
-
## Very first steps
|
|
43
|
-
|
|
44
|
-
### Initial
|
|
45
|
-
|
|
46
|
-
1. Initialize `git` inside your repo:
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
git init
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
2. If you don't have `Poetry` installed run:
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
make download-poetry
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
3. Initialize poetry and install `pre-commit` hooks:
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
make install
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
4. Upload initial code to GitHub (ensure you've run `make install` to use `pre-commit`):
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
git add .
|
|
68
|
-
git commit -m ":tada: Initial commit"
|
|
69
|
-
git remote add origin https://github.com/samesense/python-cath.git
|
|
70
|
-
git push -u origin master
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
### Initial setting up
|
|
74
|
-
|
|
75
|
-
- Set up [Dependabot](https://docs.github.com/en/github/administering-a-repository/enabling-and-disabling-version-updates#enabling-github-dependabot-version-updates) to ensure you have the latest dependencies.
|
|
76
|
-
- Set up [Stale bot](https://github.com/apps/stale) for automatic issue closing.
|
|
77
|
-
|
|
78
|
-
### Poetry
|
|
79
|
-
|
|
80
|
-
All manipulations with dependencies are executed through Poetry. If you're new to it, look through [the documentation](https://python-poetry.org/docs/).
|
|
81
|
-
|
|
82
|
-
<details>
|
|
83
|
-
<summary>Notes about Poetry</summary>
|
|
84
|
-
<p>
|
|
85
|
-
|
|
86
|
-
Poetry's [commands](https://python-poetry.org/docs/cli/#commands) are very intuitive and easy to learn, like:
|
|
87
|
-
|
|
88
|
-
- `poetry add numpy`
|
|
89
|
-
- `poetry run pytest`
|
|
90
|
-
- `poetry build`
|
|
91
|
-
- etc
|
|
92
|
-
|
|
93
|
-
</p>
|
|
94
|
-
</details>
|
|
95
|
-
|
|
96
|
-
### Building your package
|
|
97
|
-
|
|
98
|
-
Building a new version of the application contains steps:
|
|
99
|
-
|
|
100
|
-
- Bump the version of your package `poetry version <version>`. You can pass the new version explicitly, or a rule such as `major`, `minor`, or `patch`. For more details, refer to the [Semantic Versions](https://semver.org/) standard.
|
|
101
|
-
- Make a commit to `GitHub`.
|
|
102
|
-
- Create a `GitHub release`.
|
|
103
|
-
- And... publish 🙂 `poetry publish --build`
|
|
104
|
-
|
|
105
|
-
## What's next
|
|
106
|
-
|
|
107
|
-
Well, that's up to you. I can only recommend the packages and articles that helped me.
|
|
108
|
-
|
|
109
|
-
Packages:
|
|
110
|
-
|
|
111
|
-
- [`Typer`](https://github.com/tiangolo/typer) is great for creating CLI applications.
|
|
112
|
-
- [`Rich`](https://github.com/willmcgugan/rich) makes it easy to add beautiful formatting in the terminal.
|
|
113
|
-
- [`FastAPI`](https://github.com/tiangolo/fastapi) is a type-driven asynchronous web framework.
|
|
114
|
-
- [`IceCream`](https://github.com/gruns/icecream) is a little library for sweet and creamy debugging
|
|
115
|
-
|
|
116
|
-
Articles:
|
|
117
|
-
|
|
118
|
-
- [Open Source Guides](https://opensource.guide/)
|
|
119
|
-
- [GitHub Actions Documentation](https://help.github.com/en/actions)
|
|
120
|
-
- Maybe you would like to add [gitmoji](https://gitmoji.carloscuesta.me/) to commit names. This is really funny. 😄
|
|
121
|
-
|
|
122
|
-
## 🚀 Features
|
|
123
|
-
|
|
124
|
-
For your development we've prepared:
|
|
125
|
-
|
|
126
|
-
- Supports for `Python 3.7` and higher.
|
|
127
|
-
- [`Poetry`](https://python-poetry.org/) as the dependencies manager. See configuration in [`pyproject.toml`](https://github.com/samesense/python-cath/blob/master/pyproject.toml) and [`setup.cfg`](https://github.com/samesense/python-cath/blob/master/setup.cfg).
|
|
128
|
-
- Power of [`black`](https://github.com/psf/black), [`isort`](https://github.com/timothycrosley/isort) and [`pyupgrade`](https://github.com/asottile/pyupgrade) formatters.
|
|
129
|
-
- Ready-to-use [`pre-commit`](https://pre-commit.com/) hooks with formatters above.
|
|
130
|
-
- Type checks with the configured [`mypy`](https://mypy.readthedocs.io).
|
|
131
|
-
- Testing with [`pytest`](https://docs.pytest.org/en/latest/).
|
|
132
|
-
- Docstring checks with [`darglint`](https://github.com/terrencepreilly/darglint).
|
|
133
|
-
- Security checks with [`safety`](https://github.com/pyupio/safety) and [`bandit`](https://github.com/PyCQA/bandit).
|
|
134
|
-
- Well-made [`.editorconfig`](https://github.com/samesense/python-cath/blob/master/.editorconfig), [`.dockerignore`](https://github.com/samesense/python-cath/blob/master/.dockerignore), and [`.gitignore`](https://github.com/samesense/python-cath/blob/master/.gitignore). You don't have to worry about those things.
|
|
135
|
-
|
|
136
|
-
For building and deployment:
|
|
137
|
-
|
|
138
|
-
- `GitHub` integration.
|
|
139
|
-
- [`Makefile`](https://github.com/samesense/python-cath/blob/master/Makefile#L89) for building routines. Everything is already set up for security checks, codestyle checks, code formatting, testing, linting, docker builds, etc. More details at [Makefile summary](#makefile-usage)).
|
|
140
|
-
- [Dockerfile](https://github.com/samesense/python-cath/blob/master/docker/Dockerfile) for your package.
|
|
141
|
-
- `Github Actions` with predefined [build workflow](https://github.com/samesense/python-cath/blob/master/.github/workflows/build.yml) as the default CI/CD.
|
|
142
|
-
- Always up-to-date dependencies with [`@dependabot`](https://dependabot.com/) (You will only [enable it](https://docs.github.com/en/github/administering-a-repository/enabling-and-disabling-version-updates#enabling-github-dependabot-version-updates)).
|
|
143
|
-
- Automatic drafts of new releases with [`Release Drafter`](https://github.com/marketplace/actions/release-drafter). It creates a list of changes based on labels in merged `Pull Requests`. You can see labels (aka `categories`) in [`release-drafter.yml`](https://github.com/samesense/python-cath/blob/master/.github/release-drafter.yml). Works perfectly with [Semantic Versions](https://semver.org/) specification.
|
|
144
|
-
|
|
145
|
-
For creating your open source community:
|
|
146
|
-
|
|
147
|
-
- Ready-to-use [Pull Requests templates](https://github.com/samesense/python-cath/blob/master/.github/PULL_REQUEST_TEMPLATE.md) and several [Issue templates](https://github.com/samesense/python-cath/tree/master/.github/ISSUE_TEMPLATE).
|
|
148
|
-
- Files such as: `LICENSE`, `CONTRIBUTING.md`, `CODE_OF_CONDUCT.md`, and `SECURITY.md` are generated automatically.
|
|
149
|
-
- [`Stale bot`](https://github.com/apps/stale) that closes abandoned issues after a period of inactivity. (You will only [need to setup free plan](https://github.com/marketplace/stale)). Configuration is [here](https://github.com/samesense/python-cath/blob/master/.github/.stale.yml).
|
|
150
|
-
- [Semantic Versions](https://semver.org/) specification with [`Release Drafter`](https://github.com/marketplace/actions/release-drafter).
|
|
151
|
-
|
|
152
45
|
## Installation
|
|
153
46
|
|
|
154
47
|
```bash
|
|
@@ -168,7 +61,7 @@ python-cath --help
|
|
|
168
61
|
```
|
|
169
62
|
|
|
170
63
|
```bash
|
|
171
|
-
python-cath
|
|
64
|
+
python-cath file1 file2 outfile
|
|
172
65
|
```
|
|
173
66
|
|
|
174
67
|
or if installed with `Poetry`:
|
|
@@ -178,7 +71,7 @@ poetry run python-cath --help
|
|
|
178
71
|
```
|
|
179
72
|
|
|
180
73
|
```bash
|
|
181
|
-
poetry run python-cath
|
|
74
|
+
poetry run python-cath file1 file2 outfile
|
|
182
75
|
```
|
|
183
76
|
|
|
184
77
|
### Makefile usage
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
python_cath/__init__.py,sha256=jWtDUGUgV39IeDqwlQ9ziOy9ceofcf1hsppd2C_t9Yw,250
|
|
2
|
+
python_cath/__main__.py,sha256=t3LBYcsZ4lcNo4SUc828O6DoeCZmKlAPazDNfd1n9K8,788
|
|
3
|
+
python_cath/concat.py,sha256=RYSWSePSbdWI9JlzFlIVtoa7rH1-LmiruorjDc9jKZY,1731
|
|
4
|
+
python_cath/example.py,sha256=LGLU6ShWSJtu2zPbGXmQJw5ktJkNlGnRhFjY8OTlePM,366
|
|
5
|
+
python_cath/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
python_cath-0.3.0.dist-info/METADATA,sha256=CwdIGPs5Gmh6nwDtwfLr_VXqGRyYeJ4f7RpXV9XpmJ4,7674
|
|
7
|
+
python_cath-0.3.0.dist-info/WHEEL,sha256=kJCRJT_g0adfAJzTx2GUMmS80rTJIVHRCfG0DQgLq3o,88
|
|
8
|
+
python_cath-0.3.0.dist-info/entry_points.txt,sha256=CKAIA5eO7sx0McMvZxxXm01CYasNWeOfB3MWbkNcP7I,56
|
|
9
|
+
python_cath-0.3.0.dist-info/licenses/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
python_cath-0.3.0.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
python_cath/__init__.py,sha256=HIJeYPnh_ZqTjg5-1pf6_VFBPCMeva5APJJkOfYH2wc,352
|
|
2
|
-
python_cath/__main__.py,sha256=g1nyvrk8xV1R2xDYYAjizoDA3A6Gi8lULxzi17LU0fs,965
|
|
3
|
-
python_cath/example.py,sha256=LGLU6ShWSJtu2zPbGXmQJw5ktJkNlGnRhFjY8OTlePM,366
|
|
4
|
-
python_cath/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
python_cath-0.2.0.dist-info/entry_points.txt,sha256=CKAIA5eO7sx0McMvZxxXm01CYasNWeOfB3MWbkNcP7I,56
|
|
6
|
-
python_cath-0.2.0.dist-info/LICENSE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
python_cath-0.2.0.dist-info/WHEEL,sha256=Q99itqWYDhV793oHzqzi24q7L7Kdiz6cb55YDfTXphE,84
|
|
8
|
-
python_cath-0.2.0.dist-info/METADATA,sha256=n-dcIO0A0jCe-8vQPDt05fewI5ZU5e1l3fw0Aa8NSCM,13310
|
|
9
|
-
python_cath-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|