Skip to content

Commit

Permalink
add poetry support
Browse files Browse the repository at this point in the history
  • Loading branch information
an-li-the-dev authored and kidylee committed Dec 20, 2022
1 parent 42774bf commit e7b7724
Show file tree
Hide file tree
Showing 10 changed files with 2,226 additions and 29 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'poetry'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install setuptools wheel twine build
run: poetry install
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
python -m build
python -m twine upload --repository pypi dist/*
poetry config pypi-token.pypi "$PYPI_TOKEN"
poetry build
poetry publish
15 changes: 9 additions & 6 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ jobs:
runs-on: ${{ matrix.platform }}
strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
platform: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@v1
- name: Install poetry
run: pipx install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox-gh-actions
pip install tox
poetry add -D tox-gh-actions
poetry install
- name: Test with tox
run: tox
run: poetry run tox

2,037 changes: 2,037 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

60 changes: 55 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,59 @@
[tool.poetry]
name = "tidy3d"
version = "1.8.0"
description = ""
authors = ["Tyler Hughes <tyler@flexcompute.com>"]
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.7.2,<3.11"
shapely = [{ python = "<3.10", version = "1.8.0" },
{ python = "^3.10",version = "^1.8.1"}]
scipy = [{ python = "~3.7", version = "^1.6.0" },
{ python = "~3.8", version = "^1.8.0" },
{ python = "^3.9", version = "^1.9.0" }]
numpy = [{ python = "~3.7", version = "^1.19.0" },
{ python = "~3.8", version = "^1.20.0" },
{ python = "^3.9", version = "^1.23.0" }]
matplotlib = [{ python = "~3.7", version = "~3.5" },
{ python = "^3.8", version = "^3.6" }]
pandas = [{ python = "~3.7", version = "^1.3.0"}, {python = "^3.8", version = "^1.5.0"}]
xarray = "0.20.2"
pyroots = "^0.5.0"
importlib-metadata = "<5.0.0"
h5netcdf = "^1.1.0"
h5py = "^3.7.0"
rich = "^12.6.0"
pydantic = "^1.10.2"
pyyaml = "^6.0"
dask = "~2022.02.0"
boto3 = "^1.26.31"
requests = "^2.28.1"
pyjwt = "^2.6.0"
toml = "^0.10.2"

[tool.poetry.group.dev.dependencies]
click = "^8.1.3"
black = "^22.12.0"
pylint = "^2.15.8"
pytest = "^7.2.0"
pytest-timeout = "^2.1.0"
gdspy = "^1.6.12"
memory-profiler = "^0.61.0"
dill = "^0.3.6"
tox = "^3.0.0"

[build-system]
requires = [
"setuptools>=42",
"wheel"
]
build-backend = "setuptools.build_meta"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


[tool.black]
line-length = 100


[tool.pytest.ini_options]
filterwarnings = 'ignore::DeprecationWarning'

[tool.poetry.scripts]
tidy3d = "tidy3d.plugins.cli:tidy3d_cli"
3 changes: 0 additions & 3 deletions pytest.ini

This file was deleted.

24 changes: 24 additions & 0 deletions tests/test_plugins/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import os.path
import shutil
from os.path import expanduser

from click.testing import CliRunner
from tidy3d.plugins.cli import tidy3d_cli
import toml


def test_tidy3d_cli():
home = expanduser("~")
if os.path.exists(f"{home}/.tidy3d/config"):
shutil.move(f"{home}/.tidy3d/config", f"{home}/.tidy3d/config.bak")
runner = CliRunner()
result = runner.invoke(tidy3d_cli, ['configure'], input="apikey")
assert result.exit_code == 0

with open(f"{home}/.tidy3d/config", "r", encoding="utf-8") as f:
content = f.read()
config = toml.loads(content)
assert config.get('apikey', '') == "apikey"

if os.path.exists(f"{home}/.tidy3d/config.bak"):
shutil.move(f"{home}/.tidy3d/config.bak", f"{home}/.tidy3d/config")
4 changes: 4 additions & 0 deletions tidy3d/plugins/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
tidy3d command line tool.
"""
from .app import tidy3d_cli
45 changes: 45 additions & 0 deletions tidy3d/plugins/cli/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
Commandline interface for tidy3d.
"""
import os.path
from os.path import expanduser

import click
import toml

home = expanduser("~")
if os.path.exists(f"{home}/.tidy3d/config"):
with open(f"{home}/.tidy3d/config", "r", encoding="utf-8") as f:
content = f.read()
config = toml.loads(content)
config_description = f"API Key[{config.get('apikey', '')}]"


@click.group()
def tidy3d_cli():
"""
Tidy3d command line tool.
"""


@click.command()
@click.option(
"--apikey", prompt=config_description if "config_description" in globals() else "API Key"
)
def configure(apikey):
"""
Configure Tidy3d credentials,eg: tidy3d configure
:param apikey:
:return:
"""
if not os.path.exists(f"{home}/.tidy3d"):
os.mkdir(f"{home}/.tidy3d")
with open(f"{home}/.tidy3d/config", "w+", encoding="utf-8") as config_file:
toml_config = toml.loads(config_file.read())
toml_config.update({"apikey": apikey})
config_file.write(toml.dumps(toml_config))
click.echo("done.")


tidy3d_cli.add_command(configure)
38 changes: 38 additions & 0 deletions tidy3d/web/httputils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
""" handles communication with server """
import os
# import os
import time
from os.path import expanduser
from typing import Dict
from enum import Enum

import jwt
import requests
import toml

from .auth import get_credentials, MAX_ATTEMPTS
from .config import DEFAULT_CONFIG as Config
from ..log import WebError
from ..version import __version__


SIMCLOUD_APIKEY = "SIMCLOUD_APIKEY"

def api_key():
"""
Get the api key for the current environment.
:return:
"""
if os.environ.get(SIMCLOUD_APIKEY):
return os.environ.get(SIMCLOUD_APIKEY)
if os.path.exists(f"{expanduser('~')}/.tidy3d/config"):
with open(f"{expanduser('~')}/.tidy3d/config", "r", encoding="utf-8") as config_file:
config = toml.loads(config_file.read())
return config.get("apikey", "")

return None


def api_key_auth(request):
"""
Set the authentication.
:param request:
:return:
"""
key = api_key()
if not key:
raise ValueError(
"API key not found, please set it by commandline or environment, eg: tidy3d configure or export "
"SIMCLOUD_APIKEY=xxx"
)
request.headers["simcloud-api-key"] = key
request.headers["tidy3d-python-version"] = __version__
return request


class ResponseCodes(Enum):
Expand Down
10 changes: 3 additions & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ python =
3.11: python3.11

[testenv]
setenv =
MPLBACKEND=agg
deps =
-rrequirements/dev.txt
commands =
pip install requests
whitelist_externals = poetry
commands =
black --check --diff . --line-length 100
python lint.py

Expand Down Expand Up @@ -56,4 +52,4 @@ commands =
pytest -rA tests/test_plugins/test_resonance_finder.py
pytest -rA tests/test_web/test_auth.py
pytest -rA tests/test_web/test_task.py
pytest -rA tests/test_web/test_webapi.py
pytest -rA tests/test_web/test_webapi.py

0 comments on commit e7b7724

Please sign in to comment.