Skip to content

Commit

Permalink
Convert to fully use setup.py for PyPi installation
Browse files Browse the repository at this point in the history
Add pyproject.toml, setup.cfg
Add new target make pypi.
fix up requirements.txt

Signed-off-by: Daniel J Walsh <[email protected]>

Update

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Oct 1, 2024
1 parent 70fdfb7 commit 303af79
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 19 deletions.
41 changes: 33 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ install-requirements:
install-completions:
install ${SELINUXOPT} -d -m 755 $(DESTDIR)${SHAREDIR}/bash-completion/completions
register-python-argcomplete --shell bash ramalama > $(DESTDIR)${SHAREDIR}/bash-completion/completions/ramalama

install ${SELINUXOPT} -d -m 755 $(DESTDIR)${SHAREDIR}/fish/vendor_completions.d
register-python-argcomplete --shell fish ramalama > $(DESTDIR)${SHAREDIR}/fish/vendor_completions.d/ramalama.fish

Expand All @@ -53,10 +52,18 @@ install-completions:
# register-python-argcomplete --shell zsh ramalama > $(DESTDIR)${SHAREDIR}/zsh/site/_ramalama

.PHONY:
install-program:
install ${SELINUXOPT} -d -m 755 $(DESTDIR)$(BINDIR)
install ${SELINUXOPT} -m 755 ramalama.py \
$(DESTDIR)$(BINDIR)/ramalama
completions:
mkdir -p build/completions/bash-completion/completions
register-python-argcomplete --shell bash ramalama > build/completions/bash-completion/completions/ramalama

mkdir -p build/completions/fish/vendor_completions.d
register-python-argcomplete --shell fish ramalama > build/completions/fish/vendor_completions.d/ramalama.fish

mkdir -p build/completions/bash-completion/completions
register-python-argcomplete --shell bash ramalama > build/completions/bash-completion/completions/ramalama

mkdir -p build/completions/fish/vendor_completions.d
register-python-argcomplete --shell fish ramalama > build/completions/fish/vendor_completions.d/ramalama.fish

.PHONY:
install-shortnames:
Expand All @@ -65,7 +72,19 @@ install-shortnames:
$(DESTDIR)$(SHAREDIR)/ramalama

.PHONY:
install: install-program install-shortnames install-docs install-completions
completions:
mkdir -p build/completions/bash-completion/completions
register-python-argcomplete --shell bash ramalama > build/completions/bash-completion/completions/ramalama

mkdir -p build/completions/fish/vendor_completions.d
register-python-argcomplete --shell fish ramalama > build/completions/fish/vendor_completions.d/ramalama.fish

# FIXME: not available on Centos 9 yet.
# mkdir -p build/completions/zsh/site
# register-python-argcomplete --shell zsh ramalama > build/completions/zsh/site/_ramalama

.PHONY:
install: docs completions
RAMALAMA_VERSION=$(RAMALAMA_VERSION) \
pip install . --root $(DESTDIR) --prefix ${PREFIX}

Expand Down Expand Up @@ -99,10 +118,16 @@ ifeq ($(OS),Linux)
hack/xref-helpmsgs-manpages
endif

.PHONY:
pypi: clean
python3 -m build --sdist
python3 -m build --wheel
python3 -m twine upload dist/*

.PHONY: bats
bats:
RAMALAMA=$(CURDIR)/ramalama.py bats -T test/system/
_RAMALAMA_TEST_OPTS=--nocontainer RAMALAMA=$(CURDIR)/ramalama.py bats -T test/system/
RAMALAMA=$(CURDIR)/bin/ramalama bats -T test/system/
_RAMALAMA_TEST_OPTS=--nocontainer RAMALAMA=$(CURDIR)/bin/ramalama bats -T test/system/

.PHONY: ci
ci:
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ $ cat /usr/share/ramalama/shortnames.conf

## Install

## Install via PyPi

Ramalama is available via PyPi [https://pypi.org/project/ramalama](https://pypi.org/project/ramalama)

```
pip install ramalama
```

## Install by script

Install RamaLama by running this one-liner (on macOS run without sudo):

Linux:
Expand Down
2 changes: 1 addition & 1 deletion ramalama.py → bin/ramalama
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


def main(args):
sharedirs = ["/opt/homebrew/share/ramalama", "/usr/local/share/ramalama", "/usr/share/ramalama"]
sharedirs = ["./", "/opt/homebrew/share/ramalama", "/usr/local/share/ramalama", "/usr/share/ramalama"]
syspath = next((d for d in sharedirs if os.path.exists(d)), None)
sys.path.insert(0, syspath)

Expand Down
2 changes: 1 addition & 1 deletion hack/xref-helpmsgs-manpages
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $| = 1;
# BEGIN user-customizable section

# Path to ramalama executable
my $Default_RamaLama = "$FindBin::Bin/../ramalama.py";
my $Default_RamaLama = "$FindBin::Bin/../bin/ramalama";
my $RAMALAMA = $ENV{RAMALAMA} || $Default_RamaLama;

# Path to all doc files, including .rst and (down one level) markdown
Expand Down
50 changes: 50 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[project]
name = "ramalama"
version = "0.0.5"
dependencies = [
"argcomplete",
"omlmd",
"huggingface_hub[cli]",
]
requires-python = ">= 3.8"
maintainers = [
{ name="Dan Walsh", email = "[email protected]" },
{ name="Eric Curtin", email = "[email protected]" },
]
description = "RamaLama is a command line tool for working with AI LLM models."
readme = "README.md"
license = {file = "LICENSE"}
keywords = ["ramalama", "llama", "AI"]

[project.urls]
Homepage = "https://github.com/containers/ramalama"
Documentation = "https://github.com/containers/ramalama/tree/main/docs"
Repository = "https://github.com/containers/ramalama"
Issues = "https://github.com/containers/ramalama/issues"

[tool.black]
line-length = 100
skip-string-normalization = true
preview = true
target-version = ["py36"]
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.tox
| \.venv
| \.history
| build
| dist
| docs
| hack
)/
'''
[tool.isort]
profile = "black"
line_length = 100
[tool.pytest.ini_options]
log_cli = true
log_cli_level = "DEBUG"
log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)"
log_cli_date_format = "%Y-%m-%d %H:%M:%S"
4 changes: 3 additions & 1 deletion ramalama/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import importlib.metadata

"""Version of RamaLamaPy."""

__version__ = "0.1.0"
__version__ = importlib.metadata.version("ramalama")


def version(args):
Expand Down
6 changes: 2 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Any changes should be copied into pyproject.toml
argcomplete
requests>=2.24
setuptools
sphinx
tomli>=1.2.3; python_version<'3.11'
urllib3
wheel
omlmd
huggingface_hub[cli]
3 changes: 0 additions & 3 deletions rpm/python-ramalama.spec
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ Provides: %{pypi_name} = %{version}-%{release}
%{_mandir}/man1/ramalama*.1*
%{_datadir}/bash-completion/completions/%{pypi_name}
%{_datadir}/fish/vendor_completions.d/%{pypi_name}.fish
#
# FIXME: Not available on Centos/RHEL 9 yet
# %{_datadir}/zsh/site/_%{pypi_name}

%changelog
%autochangelog
20 changes: 20 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[metadata]
name = ramalama
description = RamaLama is a command line tool for working with AI LLM models.
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/containers/ramalama
platforms = any
project_urls =
Bug Tracker = https://github.com/containers/ramalamay/issues
keywords = ramalama

[options]
include_package_data = True

[bdist_wheel]
# python < 3.8 not supported
universal = false

[sdist]
formats = gztar
36 changes: 36 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
import setuptools
import os
from setuptools import find_packages
from setuptools.command.build_py import build_py as build_py_orig


def generate_man_pages(share_path, docs):
data_files = []

for path, _, files in os.walk(docs):
list_entry = (share_path, [os.path.join(path, f) for f in files if f.endswith(".1")])
data_files.append(list_entry)

return data_files


def generate_completions(share_path, completions):
data_files = []

def remove_prefix(s, prefix):
if s.startswith(prefix):
length = len(prefix) + 1
return s[length:]
else:
return s

for path, _, files in os.walk(completions):
if len(files) == 0:
continue
list_entry = (
os.path.join(share_path, remove_prefix(path, completions)),
[os.path.join(path, f) for f in files],
)
data_files.append(list_entry)
return data_files


class build_py(build_py_orig):
def find_package_modules(self, package, package_dir):
modules = super().find_package_modules(package, package_dir)
Expand All @@ -12,4 +44,8 @@ def find_package_modules(self, package, package_dir):
setuptools.setup(
packages=find_packages(),
cmdclass={"build_py": build_py},
scripts=["bin/ramalama"],
data_files=[("share/ramalama", ["shortnames/shortnames.conf"])]
+ generate_completions("share", "build/completions")
+ generate_man_pages("man/man1", "docs"),
)
2 changes: 1 addition & 1 deletion test/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ main() {

local os
os="$(uname -s)"
binfile=ramalama.py
binfile=bin/ramalama
chmod +x ${binfile} install.py
uname -a
/usr/bin/python3 --version
Expand Down

0 comments on commit 303af79

Please sign in to comment.