Skip to content

Commit

Permalink
rename pydantic_pkgr to abx_pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
pirate committed Nov 12, 2024
1 parent 4a0dc71 commit 5b35868
Show file tree
Hide file tree
Showing 29 changed files with 100 additions and 463 deletions.
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

**It's an ORM for your package managers, providing a nice python types for packages + installers.**

**This is a [Python library](https://pypi.org/project/pydantic-pkgr/) for installing & managing packages locally with a variety of package managers.**
**This is a [Python library](https://pypi.org/project/abx-pkg/) for installing & managing packages locally with a variety of package managers.**
It's designed for when `requirements.txt` isn't enough, and you have to detect or install dependencies at runtime.


```shell
pip install pydantic-pkgr # will be renamed to abx-pkg soon
pip install abx-pkg # will be renamed to abx-pkg soon
```


Expand All @@ -41,7 +41,7 @@ pip install pydantic-pkgr # will be renamed to abx-pkg soon
<br/>

```python
from pydantic_pkgr import *
from abx_pkg import *

apt, brew, pip, npm, env = AptProvider(), BrewProvider(), PipProvider(), NpmProvider(), EnvProvider()

Expand All @@ -63,7 +63,7 @@ for binary in dependencies:

```python
from pydantic import InstanceOf
from pydantic_pkgr import Binary, BinProvider, BrewProvider, EnvProvider
from abx_pkg import Binary, BinProvider, BrewProvider, EnvProvider

# you can also define binaries as classes, making them usable for type checking
class CurlBinary(Binary):
Expand All @@ -77,7 +77,7 @@ curl.exec(cmd=['--version']) # curl 8.4.0
```

```python
from pydantic_pkgr import Binary, EnvProvider, PipProvider
from abx_pkg import Binary, EnvProvider, PipProvider

# We also provide direct package manager (aka BinProvider) APIs
apt = AptProvider()
Expand Down Expand Up @@ -115,10 +115,10 @@ print(ffmpeg.model_json_schema()) # ... OpenAPI-ready JSON schema showing all
## Usage

```bash
pip install pydantic-pkgr
pip install abx-pkg
```

### [`BinProvider`](https://github.com/ArchiveBox/abx-pkg/blob/main/pydantic_pkgr/binprovider.py#:~:text=class%20BinProvider)
### [`BinProvider`](https://github.com/ArchiveBox/abx-pkg/blob/main/abx_pkg/binprovider.py#:~:text=class%20BinProvider)

**Implementations: `EnvProvider`, `AptProvider`, `BrewProvider`, `PipProvider`, `NpmProvider`**

Expand All @@ -140,7 +140,7 @@ This type represents a "provider of binaries", e.g. a package manager like `apt`
```python
import platform
from typing import List
from pydantic_pkgr import EnvProvider, PipProvider, AptProvider, BrewProvider
from abx_pkg import EnvProvider, PipProvider, AptProvider, BrewProvider

### Example: Finding an existing install of bash using the system $PATH environment
env = EnvProvider()
Expand All @@ -166,7 +166,7 @@ print(django_bin.abspath) # Path('/usr/lib/python3.10/site-packages/
print(django_bin.version) # SemVer('5.0.2')
```

### [`Binary`](https://github.com/ArchiveBox/abx-pkg/blob/main/pydantic_pkgr/binary.py#:~:text=class%20Binary)
### [`Binary`](https://github.com/ArchiveBox/abx-pkg/blob/main/abx_pkg/binary.py#:~:text=class%20Binary)

This type represents a single binary dependency aka a package (e.g. `wget`, `curl`, `ffmpeg`, etc.).
It can define one or more `BinProvider`s that it supports, along with overrides to customize the behavior for each.
Expand All @@ -180,7 +180,7 @@ It can define one or more `BinProvider`s that it supports, along with overrides
- `sha256: str`

```python
from pydantic_pkgr import BinProvider, Binary, BinProviderName, BinName, ProviderLookupDict, SemVer
from abx_pkg import BinProvider, Binary, BinProviderName, BinName, ProviderLookupDict, SemVer

class CustomBrewProvider(BrewProvider):
name: str = 'custom_brew'
Expand Down Expand Up @@ -215,7 +215,7 @@ print(ytdlp.is_valid) # True
```

```python
from pydantic_pkgr import BinProvider, Binary, BinProviderName, BinName, ProviderLookupDict, SemVer
from abx_pkg import BinProvider, Binary, BinProviderName, BinName, ProviderLookupDict, SemVer

#### Example: Create a binary that uses Podman if available, or Docker otherwise
class DockerBinary(Binary):
Expand Down Expand Up @@ -255,10 +255,10 @@ print(custom_docker.version) # SemVer('5.0.2')
print(custom_docker.is_valid) # True
```

### [`SemVer`](https://github.com/ArchiveBox/abx-pkg/blob/main/pydantic_pkgr/semver.py#:~:text=class%20SemVer)
### [`SemVer`](https://github.com/ArchiveBox/abx-pkg/blob/main/abx_pkg/semver.py#:~:text=class%20SemVer)

```python
from pydantic_pkgr import SemVer
from abx_pkg import SemVer

### Example: Use the SemVer type directly for parsing & verifying version strings
SemVer.parse('Google Chrome 124.0.6367.208+beta_234. 234.234.123') # SemVer(124, 0, 6367')
Expand Down Expand Up @@ -290,7 +290,7 @@ With a few more packages, you get type-checked Django fields & forms that suppor
> - [`django-admin-data-views`](https://github.com/MrThearMan/django-admin-data-views)
> - [`django-pydantic-field`](https://github.com/surenkov/django-pydantic-field)
> - [`django-jsonform`](https://django-jsonform.readthedocs.io/)
> `pip install pydantic-pkgr django-admin-data-views django-pydantic-field django-jsonform`
> `pip install abx-pkg django-admin-data-views django-pydantic-field django-jsonform`

<br/>

Expand All @@ -307,7 +307,7 @@ Example Django `models.py` showing how to store `Binary` and `BinProvider` insta
from typing import List
from django.db import models
from pydantic import InstanceOf
from pydantic_pkgr import BinProvider, Binary, SemVer
from abx_pkg import BinProvider, Binary, SemVer
from django_pydantic_field import SchemaField

class InstalledBinary(models.Model):
Expand Down Expand Up @@ -349,7 +349,7 @@ obj.binary.exec(['--version']) # curl 7.81.0 (x86_64-apple-
<img height="220" alt="Django Admin binaries list view" src="https://github.com/ArchiveBox/abx-pkg/assets/511499/a9980217-f39e-434e-b266-20cd6feb17c3" align="top"><img height="220" alt="Django Admin binaries detail view" src="https://github.com/ArchiveBox/abx-pkg/assets/511499/d4d9086e-c8f4-4b6e-8ee8-8c8a864715b0" align="top">

```bash
pip install pydantic-pkgr django-admin-data-views
pip install abx-pkg django-admin-data-views
```
*For more info see the [`django-admin-data-views`](https://github.com/MrThearMan/django-admin-data-views) docs...*

Expand All @@ -358,24 +358,24 @@ Then add this to your `settings.py`:
INSTALLED_APPS = [
# ...
'admin_data_views'
'pydantic_pkgr'
'abx_pkg'
# ...
]

# point these to a function that gets the list of all binaries / a single binary
PYDANTIC_PKGR_GET_ALL_BINARIES = 'pydantic_pkgr.views.get_all_binaries'
PYDANTIC_PKGR_GET_BINARY = 'pydantic_pkgr.views.get_binary'
ABX_PKG_GET_ALL_BINARIES = 'abx_pkg.views.get_all_binaries'
ABX_PKG_GET_BINARY = 'abx_pkg.views.get_binary'

ADMIN_DATA_VIEWS = {
"NAME": "Environment",
"URLS": [
{
"route": "binaries/",
"view": "pydantic_pkgr.views.binaries_list_view",
"view": "abx_pkg.views.binaries_list_view",
"name": "binaries",
"items": {
"route": "<str:key>/",
"view": "pydantic_pkgr.views.binary_detail_view",
"view": "abx_pkg.views.binary_detail_view",
"name": "binary",
},
},
Expand All @@ -398,7 +398,7 @@ class YourSiteAdmin(admin.AdminSite):
custom_admin = YourSiteAdmin()
custom_admin.register(get_user_model())
...
from pydantic_pkgr.admin import register_admin_views
from abx_pkg.admin import register_admin_views
register_admin_views(custom_admin)
</code></pre>
</details>
Expand Down Expand Up @@ -453,7 +453,7 @@ admin.site.register(MyModel, MyModelAdmin)
```python
from subprocess import run, PIPE

from pydantic_pkgr import BinProvider, BinProviderName, BinName, SemVer
from abx_pkg import BinProvider, BinProviderName, BinName, SemVer

class CargoProvider(BinProvider):
name: BinProviderName = 'cargo'
Expand Down Expand Up @@ -514,17 +514,17 @@ print(rg.version) # SemVer(14, 1, 0)

[coverage-badge]: https://coveralls.io/repos/github/ArchiveBox/abx-pkg/badge.svg?branch=main
[status-badge]: https://img.shields.io/github/actions/workflow/status/ArchiveBox/abx-pkg/test.yml?branch=main
[pypi-badge]: https://img.shields.io/pypi/v/pydantic-pkgr?v=1
[pypi-badge]: https://img.shields.io/pypi/v/abx-pkg?v=1
[licence-badge]: https://img.shields.io/github/license/ArchiveBox/abx-pkg?v=1
[repo-badge]: https://img.shields.io/github/last-commit/ArchiveBox/abx-pkg?v=1
[issues-badge]: https://img.shields.io/github/issues-raw/ArchiveBox/abx-pkg?v=1
[version-badge]: https://img.shields.io/pypi/pyversions/pydantic-pkgr?v=1
[downloads-badge]: https://img.shields.io/pypi/dm/pydantic-pkgr?v=1
[django-badge]: https://img.shields.io/pypi/djversions/pydantic-pkgr?v=1
[version-badge]: https://img.shields.io/pypi/pyversions/abx-pkg?v=1
[downloads-badge]: https://img.shields.io/pypi/dm/abx-pkg?v=1
[django-badge]: https://img.shields.io/pypi/djversions/abx-pkg?v=1

[coverage]: https://coveralls.io/github/ArchiveBox/abx-pkg?branch=main
[status]: https://github.com/ArchiveBox/abx-pkg/actions/workflows/test.yml
[pypi]: https://pypi.org/project/pydantic-pkgr
[pypi]: https://pypi.org/project/abx-pkg
[licence]: https://github.com/ArchiveBox/abx-pkg/blob/main/LICENSE
[repo]: https://github.com/ArchiveBox/abx-pkg/commits/main
[issues]: https://github.com/ArchiveBox/abx-pkg/issues
2 changes: 1 addition & 1 deletion pydantic_pkgr/__init__.py → abx_pkg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__package__ = "pydantic_pkgr"
__package__ = "abx_pkg"

from .base_types import (
BinName,
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions pydantic_pkgr/apps.py → abx_pkg/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.apps import AppConfig


class PydanticPkgrConfig(AppConfig):
class AbxPkgConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'pydantic_pkgr'
name = 'abx_pkg'
2 changes: 1 addition & 1 deletion pydantic_pkgr/base_types.py → abx_pkg/base_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__package__ = "pydantic_pkgr"
__package__ = "abx_pkg"

import os
import shutil
Expand Down
2 changes: 1 addition & 1 deletion pydantic_pkgr/binary.py → abx_pkg/binary.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__package__ = 'pydantic_pkgr'
__package__ = 'abx_pkg'

from typing import Any, Optional, Dict, List
from typing_extensions import Self
Expand Down
2 changes: 1 addition & 1 deletion pydantic_pkgr/binprovider.py → abx_pkg/binprovider.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__package__ = "pydantic_pkgr"
__package__ = "abx_pkg"

import os
import sys
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
__package__ = 'pydantic_pkgr'
__package__ = 'abx_pkg'

import os
import sys
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#!/usr/bin/env python
__package__ = "pydantic_pkgr"
__package__ = "abx_pkg"

import sys
import time
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

#!/usr/bin/env python3
__package__ = "pydantic_pkgr"
__package__ = "abx_pkg"

import os
import sys
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#!/usr/bin/env python3

__package__ = "pydantic_pkgr"
__package__ = "abx_pkg"

import os
import sys
Expand All @@ -26,7 +26,7 @@

USER_CACHE_PATH = Path(tempfile.gettempdir()) / 'npm-cache'
try:
user_cache_path = user_cache_path(appname='npm', appauthor='pydantic-pkgr', ensure_exists=True)
user_cache_path = user_cache_path(appname='npm', appauthor='abx-pkg', ensure_exists=True)
if os.access(user_cache_path, os.W_OK):
USER_CACHE_PATH = user_cache_path
except Exception:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

__package__ = "pydantic_pkgr"
__package__ = "abx_pkg"

import os
import sys
Expand All @@ -26,7 +26,7 @@

USER_CACHE_PATH = Path(tempfile.gettempdir()) / 'pip-cache'
try:
user_cache_path = user_cache_path(appname='pip', appauthor='pydantic-pkgr', ensure_exists=True)
user_cache_path = user_cache_path(appname='pip', appauthor='abx-pkg', ensure_exists=True)
if os.access(user_cache_path, os.W_OK):
USER_CACHE_PATH = user_cache_path
except Exception:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
__package__ = 'pydantic_pkgr'
__package__ = 'abx_pkg'

import os
import sys
Expand Down
2 changes: 1 addition & 1 deletion pydantic_pkgr/models.py → abx_pkg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# from django.db import models
# from django_pydantic_field import SchemaField
#
# from pydantic_pkgr import BinProvider, EnvProvider, Binary
# from abx_pkg import BinProvider, EnvProvider, Binary
#
# DEFAULT_PROVIDER = EnvProvider()
#
Expand Down
2 changes: 1 addition & 1 deletion pydantic_pkgr/semver.py → abx_pkg/semver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__package__ = 'pydantic_pkgr'
__package__ = 'abx_pkg'

import re
import subprocess
Expand Down
25 changes: 25 additions & 0 deletions abx_pkg/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from typing import Callable

from django.conf import settings
from django.utils.module_loading import import_string


ABX_PKG_GET_ALL_BINARIES = getattr(settings, 'ABX_PKG_GET_ALL_BINARIES', 'abx_pkg.views.get_all_binaries')
ABX_PKG_GET_BINARY = getattr(settings, 'ABX_PKG_GET_BINARY', 'abx_pkg.views.get_binary')


if isinstance(ABX_PKG_GET_ALL_BINARIES, str):
get_all_abx_pkg_binaries = import_string(ABX_PKG_GET_ALL_BINARIES)
elif isinstance(ABX_PKG_GET_ALL_BINARIES, Callable):
get_all_abx_pkg_binaries = ABX_PKG_GET_ALL_BINARIES
else:
raise ValueError('ABX_PKG_GET_ALL_BINARIES must be a function or dotted import path to a function')

if isinstance(ABX_PKG_GET_BINARY, str):
get_abx_pkg_binary = import_string(ABX_PKG_GET_BINARY)
elif isinstance(ABX_PKG_GET_BINARY, Callable):
get_abx_pkg_binary = ABX_PKG_GET_BINARY
else:
raise ValueError('ABX_PKG_GET_BINARY must be a function or dotted import path to a function')


Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__package__ = 'pydantic_pkgr'
__package__ = 'abx_pkg'


# Unfortunately it must be kept in the same file as BinProvider because of the circular type reference between them
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions pydantic_pkgr/views.py → abx_pkg/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_binary(name: str) -> Binary:

from . import settings

for binary in settings.PYDANTIC_PKGR_GET_ALL_BINARIES():
for binary in settings.ABX_PKG_GET_ALL_BINARIES():
if binary.name == key:
return binary
return None
Expand All @@ -41,7 +41,7 @@ def binaries_list_view(request: HttpRequest, **kwargs) -> TableContext:
"Description": [],
}

for binary in settings.get_all_pkgr_binaries():
for binary in settings.get_all_abx_pkg_binaries():
binary = binary.load_or_install()

rows['Binary'].append(ItemLink(binary.name, key=binary.name))
Expand All @@ -63,7 +63,7 @@ def binary_detail_view(request: HttpRequest, key: str, **kwargs) -> ItemContext:

from . import settings

binary = settings.get_pkgr_binary(key)
binary = settings.get_abx_pkg_binary(key)

assert binary, f'Could not find a binary matching the specified name: {key}'

Expand Down
6 changes: 3 additions & 3 deletions django_example_project/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@


```bash
git clone 'https://github.com/ArchiveBox/pydantic-pkgr'
cd pydantic-pkgr
git clone 'https://github.com/ArchiveBox/abx-pkg'
cd abx-pkg

pip install -e . # install pydantic_pkgr from source
pip install -e . # install abx_pkg from source

cd django_example_project/ # then go into the demo project dir

Expand Down
2 changes: 1 addition & 1 deletion django_example_project/project/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db import models
from django_pydantic_field import SchemaField

from pydantic_pkgr import BinProvider, EnvProvider, Binary, SemVer
from abx_pkg import BinProvider, EnvProvider, Binary, SemVer


DEFAULT_PROVIDER = EnvProvider()
Expand Down
Loading

0 comments on commit 5b35868

Please sign in to comment.