Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
python -m build
twine check dist/*
twine upload dist/* --skip-existing
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install .[test]
python -m pip install -r requirements_dev.txt
python -m pip install .[dev]
- name: Test with pytest and coverage
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_API_BASE_URL: ${{ secrets.OPENAI_API_BASE_URL }}
run: |
askchat hello
pip install coverage
coverage run -m pytest tests/
- name: Upload coverage to Codecov
Expand Down
97 changes: 0 additions & 97 deletions askchat/__init__.py

This file was deleted.

79 changes: 79 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
[build-system]
requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[project]
name = "askchat"
dynamic = ["version"]
description = "Interact with ChatGPT in terminal via chattool"
readme = "README.md"
license = {text = "MIT"}
authors = [
{name = "Rex Wang", email = "[email protected]"}
]
keywords = ["askchat"]
classifiers = [
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
]
requires-python = ">=3.6"
dependencies = [
"chattool>=4.0.0",
"python-dotenv>=0.17.0",
"Click>=8.0",
"platformdirs>=2.0.0"
]

[project.urls]
Homepage = "https://github.com/cubenlp/askchat"
Repository = "https://github.com/cubenlp/askchat"

[project.scripts]
ask = "askchat.ask:main"
askchat = "askchat.cli:main"
askenv = "askchat.askenv:cli"

[project.optional-dependencies]
dev = [
"pip>=25.0",
"bump2version",
"wheel",
"watchdog",
"flake8",
"tox",
"coverage",
"Sphinx",
"twine",
"pytest"
]

[tool.setuptools]
include-package-data = true
zip-safe = false

[tool.setuptools.packages.find]
where = ["src"]
include = ["askchat*"]

[tool.setuptools.dynamic]
version = {attr = "askchat.__version__"}

[tool.setuptools.package-dir]
"" = "src"

[tool.pytest.ini_options]
addopts = "--ignore=setup.py"
testpaths = ["tests"]

[tool.flake8]
exclude = ["docs"]

[tool.bdist_wheel]
universal = true
10 changes: 0 additions & 10 deletions requirements_dev.txt

This file was deleted.

14 changes: 0 additions & 14 deletions setup.cfg

This file was deleted.

44 changes: 0 additions & 44 deletions setup.py

This file was deleted.

17 changes: 17 additions & 0 deletions src/askchat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Top-level package for askchat."""

__author__ = """Rex Wang"""
__email__ = '[email protected]'
__version__ = '2.0.0'

from .elements import ChatFileCompletionType, EnvNameCompletionType
from .utils import show_resp, set_keys, initialize_config, write_config

__all__ = [
"ChatFileCompletionType",
"EnvNameCompletionType",
"show_resp",
"set_keys",
"initialize_config",
"write_config",
]
File renamed without changes.
29 changes: 15 additions & 14 deletions askchat/askenv.py → src/askchat/askenv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import click
from askchat import write_config, ENV_PATH, MAIN_ENV_PATH, EnvNameCompletionType
from askchat import write_config, EnvNameCompletionType
from chattool.const import CHATTOOL_ENV_DIR, CHATTOOL_ENV_FILE
from dotenv import set_key

help_message = """Manage askchat environments.
Expand All @@ -13,13 +14,13 @@
@click.group(help=help_message)
def cli():
"""askenv CLI for managing askchat environments."""
if not ENV_PATH.exists():
ENV_PATH.mkdir(parents=True)
if not CHATTOOL_ENV_DIR.exists():
CHATTOOL_ENV_DIR.mkdir(parents=True)

@cli.command()
def list():
"""List all environment configurations."""
configs = [env for env in ENV_PATH.glob('*.env')]
configs = [env for env in CHATTOOL_ENV_DIR.glob('*.env')]
if configs:
click.echo("Available environments:")
for config in configs:
Expand All @@ -36,7 +37,7 @@ def list():
@click.option('--interactive', '-i', is_flag=True, default=False, help='Enable interactive mode for inputting options')
def new(name, api_key, base_url, api_base, model, interactive):
"""Create a new environment configuration."""
config_path = ENV_PATH / f'{name}.env'
config_path = CHATTOOL_ENV_DIR / f'{name}.env'
if config_path.exists():
click.echo(f"Warning: Overwriting existing environment '{name}'.")
click.confirm("Do you want to continue?", abort=True)
Expand All @@ -54,7 +55,7 @@ def new(name, api_key, base_url, api_base, model, interactive):
def delete(name, default):
"""Delete an environment configuration."""
if default:
default_config_path = MAIN_ENV_PATH
default_config_path = CHATTOOL_ENV_DIR / 'default.env'
if default_config_path.exists():
default_config_path.unlink()
click.echo("Default environment configuration deleted.")
Expand All @@ -64,7 +65,7 @@ def delete(name, default):
if not name:
click.echo("Please specify an environment name or use --default to delete the default configuration.")
return
config_path = ENV_PATH / f'{name}.env'
config_path = CHATTOOL_ENV_DIR / f'{name}.env'
if config_path.exists():
config_path.unlink()
click.echo(f"Environment '{name}' deleted.")
Expand All @@ -75,7 +76,7 @@ def delete(name, default):
@click.argument('name', required=False, type=EnvNameCompletionType())
def show(name):
"""Print environment variables. Show default if no name is provided."""
config_path = ENV_PATH / f'{name}.env' if name else MAIN_ENV_PATH
config_path = CHATTOOL_ENV_DIR / f'{name}.env' if name else CHATTOOL_ENV_FILE
if config_path.exists():
with config_path.open() as f:
click.echo(f.read())
Expand All @@ -89,9 +90,9 @@ def show(name):
@click.argument('name')
def save(name):
"""Save the current environment variables to a file."""
if MAIN_ENV_PATH.exists():
content = MAIN_ENV_PATH.read_text()
config_path = ENV_PATH / f'{name}.env'
if CHATTOOL_ENV_FILE.exists():
content = CHATTOOL_ENV_FILE.read_text()
config_path = CHATTOOL_ENV_DIR / f'{name}.env'
if config_path.exists():
click.echo(f"Warning: Overwriting existing environment '{name}'.")
click.confirm("Do you want to continue?", abort=True)
Expand All @@ -104,10 +105,10 @@ def save(name):
@click.argument('name', type=EnvNameCompletionType())
def use(name):
"""Activate an environment by replacing the .env file."""
config_path = ENV_PATH / f'{name}.env'
config_path = CHATTOOL_ENV_DIR / f'{name}.env'
if config_path.exists():
content = config_path.read_text()
MAIN_ENV_PATH.write_text(content)
CHATTOOL_ENV_FILE.write_text(content)
click.echo(f"Environment '{name}' activated.")
else:
click.echo(f"Environment '{name}' not found.")
Expand All @@ -123,7 +124,7 @@ def config(name, api_key, base_url, api_base, model):
if not any([api_key, base_url, api_base, model]):
click.echo("No updates made. Provide at least one option to update.")
return
config_path = ENV_PATH / f'{name}.env' if name else MAIN_ENV_PATH
config_path = CHATTOOL_ENV_DIR / f'{name}.env' if name else CHATTOOL_ENV_FILE
if not config_path.exists():
click.echo(f"Environment '{config_path}' not found.\n" +\
"Use `askenv new` to create a new environment." )
Expand Down
Loading