Skip to content

Commit

Permalink
fix: PAN-1832 include config on wheel (#10)
Browse files Browse the repository at this point in the history
* fix: PAN-1832 include config on wheel
  • Loading branch information
jpantos authored Jul 30, 2024
1 parent 8b31cec commit 45cc8f7
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 238 deletions.
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
**/__pycache__/
*.egg-info/
*.key*
*.keystore*
*.swp
.coverage
.DS_store
.venv/
.vscode/
build/
dist/
find.sh
local/
.pytest_cache
.mypy_cache
Dockerfile
*.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Test image
run: |
docker run --rm ghcr.io/pantos-io/client-cli:latest --help
docker run --rm ghcr.io/pantos-io/client-cli:latest --help
build-and-run:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ build/
dist/
find.sh
local/
.pytest_cache
.mypy_cache
31 changes: 15 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
FROM python:3.12-alpine

ARG environment=testnet
ARG version=1.1.0

ENV PANTOS_CLIENT_VERSION=${version}
FROM python:3.12-alpine AS build

RUN apk update && apk add gcc libc-dev libffi-dev \
&& apk cache clean

RUN python3 -m pip install poetry

WORKDIR /pantos-cli

COPY pyproject.toml poetry.lock ./
COPY . .

RUN python3 -m pip install poetry
RUN poetry build

FROM python:3.12-alpine AS production

WORKDIR /pantos-cli

COPY --from=build /pantos-cli/dist/*.whl .

RUN poetry install --only main --no-interaction --no-cache --no-root
RUN python3 -m pip install *.whl

RUN mkdir -p ./pantos/cli
RUN pip cache purge && rm -rf ~/.cache/pip

COPY pantos/cli ./pantos/cli
COPY client-cli.yml .
COPY client-library.yml .
COPY client-cli.env .
COPY client-library.env .
RUN rm *.whl

ENTRYPOINT ["poetry", "run", "python3", "-m", "pantos.cli"]
ENTRYPOINT ["pantos-cli"]
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,8 @@ wheel:
poetry build

.PHONY: docker
docker: dist/pantos_client_cli-$(PANTOS_CLIENT_CLI_VERSION).docker

dist/pantos_client_cli-$(PANTOS_CLIENT_CLI_VERSION).docker: Dockerfile pantos/ client-cli.yml client-library.yml client-library.publish.env submodules/client-library/pantos/client/library/ pyproject.toml submodules/common/pantos/common/
docker:
docker build -t pantosio/pantos-client .
mkdir -p dist
docker save pantosio/pantos-client > dist/pantos_client_cli-$(PANTOS_CLIENT_CLI_VERSION).docker

.PHONY: install
install: dist/pantos_client_cli-$(PANTOS_CLIENT_CLI_VERSION)-py3-none-any.whl
Expand Down
41 changes: 0 additions & 41 deletions pantos-client-cli.conf

This file was deleted.

175 changes: 0 additions & 175 deletions pantos-client-library.conf

This file was deleted.

26 changes: 26 additions & 0 deletions pantos/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import argparse
import decimal
import getpass
import importlib.resources
import pathlib
import shutil
import sys
import typing
import uuid
Expand All @@ -31,6 +33,8 @@ def main() -> None:
_execute_command_transfer(arguments)
elif arguments.command == 'status':
_execute_command_status(arguments)
elif arguments.command == 'create-config':
_execute_command_create_config(arguments)
else:
raise NotImplementedError
except Exception as error:
Expand Down Expand Up @@ -125,6 +129,12 @@ def _create_argument_parser() -> argparse.ArgumentParser:
help='The number of blocks to query for the transfer on the '
'destination blockchain. If not specified, the query will '
'include all blocks from the latest to the genesis block.')
parser_config = subparsers.add_parser('create-config',
help='Create a new empty env file')
parser_config.add_argument(
'-p', '--path', type=pathlib.Path, default=None,
help='Path where to create the env file, defaults to the '
'current working directory')
return parser


Expand Down Expand Up @@ -199,6 +209,22 @@ def _execute_command_status(arguments: argparse.Namespace) -> None:
transfer_status)


def _execute_command_create_config(arguments: argparse.Namespace) -> None:
path = arguments.path
if path is None:
path = pathlib.Path.cwd()

path.mkdir(parents=True, exist_ok=True)

# List and copy all .env files from the pantos resource directory
resource_path = importlib.resources.files('pantos')
for env_file in resource_path.iterdir():
env_file_path = pathlib.Path(env_file.name)
if env_file_path.suffix == '.env':
shutil.copy(env_file_path, path / env_file_path.name)
print(f'Created .env files in {path}')


def _load_private_key(
blockchain: api.Blockchain,
keystore_path: typing.Optional[pathlib.Path] = None) -> api.PrivateKey:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ readme = "README.md"
packages = [
{ include = "pantos"}
]
include = [
"pantos/client-library.yml",
"pantos/client-library.env",
"pantos/client-cli.yml",
"pantos/client-cli.env",
]

[tool.setuptools.packages.find]
where = ["."]
Expand Down Expand Up @@ -44,3 +50,6 @@ python-dotenv = "1.0.1"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.scripts]
pantos-cli = "pantos.cli.__main__:main"
Loading

0 comments on commit 45cc8f7

Please sign in to comment.