baldwin 0.0.8__py3-none-any.whl → 0.0.9__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.

Potentially problematic release.


This version of baldwin might be problematic. Click here for more details.

baldwin/__init__.py CHANGED
@@ -1,2 +1,4 @@
1
1
  """baldwin module."""
2
- __version__ = '0.0.8'
2
+ from __future__ import annotations
3
+
4
+ __version__ = '0.0.9'
baldwin/__main__.py CHANGED
@@ -1,4 +1,6 @@
1
1
  """Main entry point for the Baldwin CLI."""
2
+ from __future__ import annotations
3
+
2
4
  from .main import baldwin as main
3
5
 
4
6
  main()
baldwin/lib.py CHANGED
@@ -1,5 +1,6 @@
1
1
  """Baldwin library."""
2
- from collections.abc import Iterable
2
+ from __future__ import annotations
3
+
3
4
  from dataclasses import dataclass
4
5
  from datetime import datetime, timezone
5
6
  from importlib import resources
@@ -7,7 +8,7 @@ from itertools import chain
7
8
  from pathlib import Path
8
9
  from shlex import quote
9
10
  from shutil import which
10
- from typing import Any, Literal
11
+ from typing import TYPE_CHECKING, Any, Literal
11
12
  import logging
12
13
  import os
13
14
  import subprocess as sp
@@ -17,6 +18,9 @@ from git import Actor, Repo
17
18
  import platformdirs
18
19
  import tomlkit
19
20
 
21
+ if TYPE_CHECKING:
22
+ from collections.abc import Iterable
23
+
20
24
  log = logging.getLogger(__name__)
21
25
 
22
26
 
@@ -61,16 +65,24 @@ def init() -> None:
61
65
 
62
66
  def auto_commit() -> None:
63
67
  """Automated commit of changed and untracked files."""
68
+ def can_open(file: Path) -> bool:
69
+ """Check if a file can be opened."""
70
+ try:
71
+ with file.open('rb'):
72
+ pass
73
+ except OSError:
74
+ return False
75
+ return True
76
+
64
77
  repo = get_repo()
65
- diff_items = [Path.home() / e.a_path for e in repo.index.diff(None)
66
- if e.a_path is not None] # pragma: no cover
78
+ diff_items = [Path.home() / e.a_path for e in repo.index.diff(None) if e.a_path is not None]
67
79
  items_to_add = [
68
80
  *[p for p in diff_items if p.exists()], *[
69
- x for x in (Path.home() / y
70
- for y in repo.untracked_files) if x.is_file() and not is_binary(str(x))
81
+ x for x in (Path.home() / y for y in repo.untracked_files)
82
+ if can_open(x) and x.is_file() and not is_binary(str(x))
71
83
  ]
72
84
  ]
73
- items_to_remove = [p for p in diff_items if not p.exists()] # pragma: no cover
85
+ items_to_remove = [p for p in diff_items if not p.exists()]
74
86
  if items_to_add:
75
87
  format_(items_to_add)
76
88
  repo.index.add(items_to_add)
@@ -96,7 +108,13 @@ def repo_info() -> RepoInfo:
96
108
 
97
109
 
98
110
  def install_units() -> None:
99
- """Install systemd units for automatic committing."""
111
+ """
112
+ Install systemd units for automatic committing.
113
+
114
+ Raises
115
+ ------
116
+ FileNotFoundError
117
+ """
100
118
  bw = which('bw')
101
119
  if not bw:
102
120
  raise FileNotFoundError
@@ -105,8 +123,9 @@ def install_units() -> None:
105
123
  Description=Home directory VCS commit
106
124
 
107
125
  [Service]
108
- Type=oneshot
126
+ Environment=NO_COLOR=1
109
127
  ExecStart={bw} auto-commit
128
+ Type=oneshot
110
129
  """)
111
130
  log.debug('Wrote to `%s`.', service_file)
112
131
  timer_file = Path('~/.config/systemd/user/home-vcs.timer').expanduser()
@@ -176,7 +195,11 @@ def format_(filenames: Iterable[Path | str] | None = None,
176
195
  for d in repo.index.diff(None) if d.a_path is not None),
177
196
  *(x for x in (Path.home() / y for y in repo.untracked_files)
178
197
  if x.is_file() and not is_binary(str(x))))
179
- if not (filenames := list(filenames)) or not (prettier := which('prettier')):
198
+ if not (filenames := list(filenames)):
199
+ log.debug('No files to format.')
200
+ return
201
+ if not (prettier := which('prettier')):
202
+ log.debug('Prettier not found in PATH.')
180
203
  return
181
204
  with resources.path('baldwin.resources', 'prettier.config.json') as default_config_file:
182
205
  config_file = get_config().get('baldwin', {
baldwin/main.py CHANGED
@@ -1,3 +1,6 @@
1
+ """Commands."""
2
+ from __future__ import annotations
3
+
1
4
  import logging
2
5
 
3
6
  import click
@@ -11,6 +14,7 @@ from .lib import (
11
14
  repo_info,
12
15
  set_git_env_vars,
13
16
  )
17
+ from .utils import setup_logging
14
18
 
15
19
  log = logging.getLogger(__name__)
16
20
 
@@ -22,7 +26,7 @@ __all__ = ('baldwin', 'git')
22
26
  def baldwin(*, debug: bool = False) -> None:
23
27
  """Manage a home directory with Git."""
24
28
  set_git_env_vars()
25
- logging.basicConfig(level=logging.DEBUG if debug else logging.ERROR)
29
+ setup_logging(debug=debug)
26
30
 
27
31
 
28
32
  @click.command(context_settings={
baldwin/utils.py ADDED
@@ -0,0 +1,46 @@
1
+ """Utilities."""
2
+ from __future__ import annotations
3
+
4
+ import logging
5
+ import logging.config
6
+
7
+ log = logging.getLogger(__name__)
8
+
9
+
10
+ def setup_logging(*,
11
+ debug: bool = False,
12
+ force_color: bool = False,
13
+ no_color: bool = False) -> None: # pragma: no cover
14
+ """Set up logging configuration."""
15
+ logging.config.dictConfig({
16
+ 'disable_existing_loggers': True,
17
+ 'root': {
18
+ 'level': 'DEBUG' if debug else 'INFO',
19
+ 'handlers': ['console'],
20
+ },
21
+ 'formatters': {
22
+ 'default': {
23
+ '()': 'colorlog.ColoredFormatter',
24
+ 'force_color': force_color,
25
+ 'format': (
26
+ '%(light_cyan)s%(asctime)s%(reset)s | %(log_color)s%(levelname)-8s%(reset)s | '
27
+ '%(light_green)s%(name)s%(reset)s:%(light_red)s%(funcName)s%(reset)s:'
28
+ '%(blue)s%(lineno)d%(reset)s - %(message)s'),
29
+ 'no_color': no_color,
30
+ }
31
+ },
32
+ 'handlers': {
33
+ 'console': {
34
+ 'class': 'colorlog.StreamHandler',
35
+ 'formatter': 'default',
36
+ }
37
+ },
38
+ 'loggers': {
39
+ 'baldwin': {
40
+ 'level': 'DEBUG' if debug else 'INFO',
41
+ 'handlers': ['console'],
42
+ 'propagate': False,
43
+ }
44
+ },
45
+ 'version': 1
46
+ })
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: baldwin
3
- Version: 0.0.8
3
+ Version: 0.0.9
4
4
  Summary: Simple tracking of your home directory with easy-to-read diffs.
5
5
  License: MIT
6
6
  Keywords: command line,file management,git,version control
@@ -16,14 +16,13 @@ Classifier: Programming Language :: Python :: 3.11
16
16
  Classifier: Programming Language :: Python :: 3.12
17
17
  Classifier: Programming Language :: Python :: 3.13
18
18
  Classifier: Typing :: Typed
19
- Provides-Extra: erdantic
20
19
  Requires-Dist: binaryornot (>=0.4.4,<0.5.0)
21
20
  Requires-Dist: click (>=8.1.8,<9.0.0)
22
- Requires-Dist: erdantic (<2.0) ; extra == "erdantic"
21
+ Requires-Dist: colorlog (>=6.9.0,<7.0.0)
23
22
  Requires-Dist: gitpython (>=3.1.44,<4.0.0)
24
23
  Requires-Dist: platformdirs (>=4.3.6,<5.0.0)
25
24
  Requires-Dist: tomlkit (>=0.13.2,<0.14.0)
26
- Requires-Dist: typing-extensions (>=4.13.1,<5.0.0)
25
+ Requires-Dist: typing-extensions (>=4.13.2,<5.0.0)
27
26
  Project-URL: Documentation, https://baldwin.readthedocs.org
28
27
  Project-URL: Homepage, https://tatsh.github.io/baldwin/
29
28
  Project-URL: Issues, https://github.com/Tatsh/baldwin/issues
@@ -32,6 +31,7 @@ Description-Content-Type: text/markdown
32
31
 
33
32
  # Simple home directory versioning
34
33
 
34
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
35
35
  [![QA](https://github.com/Tatsh/baldwin/actions/workflows/qa.yml/badge.svg)](https://github.com/Tatsh/baldwin/actions/workflows/qa.yml)
36
36
  [![Tests](https://github.com/Tatsh/baldwin/actions/workflows/tests.yml/badge.svg)](https://github.com/Tatsh/baldwin/actions/workflows/tests.yml)
37
37
  [![Coverage Status](https://coveralls.io/repos/github/Tatsh/baldwin/badge.svg?branch=master)](https://coveralls.io/github/Tatsh/baldwin?branch=master)
@@ -39,7 +39,9 @@ Description-Content-Type: text/markdown
39
39
  ![PyPI - Version](https://img.shields.io/pypi/v/baldwin)
40
40
  ![GitHub tag (with filter)](https://img.shields.io/github/v/tag/Tatsh/baldwin)
41
41
  ![GitHub](https://img.shields.io/github/license/Tatsh/baldwin)
42
- ![GitHub commits since latest release (by SemVer including pre-releases)](https://img.shields.io/github/commits-since/Tatsh/baldwin/v0.0.8/master)
42
+ ![GitHub commits since latest release (by SemVer including pre-releases)](https://img.shields.io/github/commits-since/Tatsh/baldwin/v0.0.9/master)
43
+
44
+ [![@Tatsh](https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fpublic.api.bsky.app%2Fxrpc%2Fapp.bsky.actor.getProfile%2F%3Factor%3Ddid%3Aplc%3Auq42idtvuccnmtl57nsucz72%26query%3D%24.followersCount%26style%3Dsocial%26logo%3Dbluesky%26label%3DFollow%2520%40Tatsh&query=%24.followersCount&style=social&logo=bluesky&label=Follow%20%40Tatsh)](https://bsky.app/profile/tatsh.bsky.social)
43
45
 
44
46
  This is a conversion of my simple scripts to version my home directory with very specific excludes
45
47
  and formatting every file upon commit so that readable diffs can be generated.
@@ -0,0 +1,14 @@
1
+ baldwin/__init__.py,sha256=pPCFLb4adFkSqhONgCTDYBp-kFFmxVzic80FQZzio4o,80
2
+ baldwin/__main__.py,sha256=vLM990SXfS71YjwD7vs3TN8UMe03UrgzA2tvKwjV9bk,122
3
+ baldwin/lib.py,sha256=nGWjtmbk8CkCevQ0qDv4UxM_vjYqGE1hCClp9cAfZQ0,8371
4
+ baldwin/main.py,sha256=JGbHj6ZRas-acoNHFH1Lmbp4-d96d9X5SWpN8fqz1qA,2073
5
+ baldwin/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ baldwin/resources/default_gitattributes.txt,sha256=uGoWTSVgPmdGB2EUIROkTz3FikGpNGhdS95SuuvoCRo,984
7
+ baldwin/resources/default_gitignore.txt,sha256=oyxukNyK6F778C2jc7oIwosP7ou1WTdbuWwkpgGZtJA,3022
8
+ baldwin/resources/prettier.config.json,sha256=-Hher3B02YflULYn0IYOG_a-rDxpaaaQ0QXD30-5IgQ,387
9
+ baldwin/utils.py,sha256=4lcYY7DErJS5GWh3utf1d697ZIMw6Q1GEEf6NCeSdak,1420
10
+ baldwin-0.0.9.dist-info/LICENSE.txt,sha256=Y6e04wkVzxa82z5bhkF3-38WGKbISh0E28Eo0IxiOBU,1082
11
+ baldwin-0.0.9.dist-info/METADATA,sha256=c0AB0Cnq_8sQC4tjxsehdgJJ-pQAJTyOp7P5bC4nCU8,5309
12
+ baldwin-0.0.9.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
13
+ baldwin-0.0.9.dist-info/entry_points.txt,sha256=16CO-Z2MW3o6hkxwJplFgnyJuHuTngwrPqCNdSQAOcc,65
14
+ baldwin-0.0.9.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 2.1.2
2
+ Generator: poetry-core 2.1.3
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,13 +0,0 @@
1
- baldwin/__init__.py,sha256=F--2vlUtecqV6dfCulqfPca9vSmeZCWcSlq3MltMgfQ,44
2
- baldwin/__main__.py,sha256=7xKOM7FqRjhwJgK30RfKKpTNZCw0DJp5EiKo2KhtqSY,86
3
- baldwin/lib.py,sha256=U3NLmy9VGk_pC_veb3r4pHqvDJSwuRIikewWnAZxUvQ,7942
4
- baldwin/main.py,sha256=PrSKsF5zdG9VzWvZUpBkmfhpkweTbVnb8kNroiMSlNA,2030
5
- baldwin/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- baldwin/resources/default_gitattributes.txt,sha256=uGoWTSVgPmdGB2EUIROkTz3FikGpNGhdS95SuuvoCRo,984
7
- baldwin/resources/default_gitignore.txt,sha256=oyxukNyK6F778C2jc7oIwosP7ou1WTdbuWwkpgGZtJA,3022
8
- baldwin/resources/prettier.config.json,sha256=-Hher3B02YflULYn0IYOG_a-rDxpaaaQ0QXD30-5IgQ,387
9
- baldwin-0.0.8.dist-info/LICENSE.txt,sha256=Y6e04wkVzxa82z5bhkF3-38WGKbISh0E28Eo0IxiOBU,1082
10
- baldwin-0.0.8.dist-info/METADATA,sha256=2KKR3CwsxeSDUqAQEuU2uQ9ChdL_3pOwkfR4HBMrBSM,4819
11
- baldwin-0.0.8.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
12
- baldwin-0.0.8.dist-info/entry_points.txt,sha256=16CO-Z2MW3o6hkxwJplFgnyJuHuTngwrPqCNdSQAOcc,65
13
- baldwin-0.0.8.dist-info/RECORD,,