diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..bf7ac78 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,67 @@ +name-template: 'v$RESOLVED_VERSION' +tag-template: 'v$RESOLVED_VERSION' +change-template: '- $TITLE [#$NUMBER](https://github.com/gdsfactory/kweb/pull/$NUMBER)' +template: | + # What's Changed + + $CHANGES + + **Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION + +categories: + - title: 'Breaking' + label: 'breaking' + - title: 'New' + labels: + - 'enhancement' + - 'feature' + - title: 'Bug Fixes' + label: 'bug' + - title: 'Maintenance' + label: 'maintenance' + - title: 'Documentation' + label: 'documentation' + - title: 'Other changes' + - title: 'Dependency Updates' + label: 'dependencies' + collapse-after: 5 + +# Change major/breaking to major and enhancement/minor to minor after v1.0 +version-resolver: + minor: + labels: + - 'breaking' + patch: + labels: + - 'enhancement' + - 'bug' + - 'maintenance' + - 'documentation' + - 'dependencies' + - 'security' + default: patch + +exclude-labels: + - 'github_actions' + +autolabeler: + - label: 'documentation' + files: + - '*.md' + branch: + - '/docs-.+/' + - label: 'bug' + branch: + - '/^fix-.+/' + title: + - '/^fix/i' + - label: 'enhancement' + branch: + - '/^feature-.+/' + - '/^add-.+/' + - '/^improve-.+/' + title: + - '/^add\s/i' + - label: 'github_actions' + files: + - '.github/**/*.yml' diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml new file mode 100644 index 0000000..b7ac8fc --- /dev/null +++ b/.github/workflows/changelog.yml @@ -0,0 +1,18 @@ +name: Update Changelog + +on: + pull_request: + types: [ closed ] + +jobs: + changelog: + name: Update changelog + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: main + - uses: rhysd/changelog-from-release/action@v3 + with: + file: CHANGELOG.md + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 0000000..f599bac --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,37 @@ +name: Release Drafter and Labels + +on: + push: + branches: + - main + pull_request: + types: [edited, opened, reopened, synchronize, unlabeled, labeled] + +permissions: + contents: read + +jobs: + update_release_draft: + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-latest + steps: + # Drafts your next Release notes as Pull Requests are merged into "master" + - uses: release-drafter/release-drafter@v6 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + require_label: + if: github.event.pull_request + needs: update_release_draft + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: mheap/github-action-required-labels@v5 + with: + mode: minimum + count: 1 + labels: "breaking, bug, github_actions, documentation, dependencies, enhancement, feature, maintenance, security" + add_comment: true diff --git a/.github/workflows/test_code.yml b/.github/workflows/test_code.yml index 04f8eb1..57683e1 100644 --- a/.github/workflows/test_code.yml +++ b/.github/workflows/test_code.yml @@ -54,28 +54,3 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: false - # test_docs: - # needs: [pre-commit] - # runs-on: ${{ matrix.os }} - # strategy: - # max-parallel: 12 - # matrix: - # python-version: ['3.10'] - # os: [ubuntu-latest] - - # steps: - # - uses: actions/checkout@v3 - # - name: Set up Python - # uses: actions/setup-python@v4 - # with: - # python-version: '3.11' - # - name: Install dependencies - # run: | - # python -m pip install --upgrade pip - # sudo apt install pandoc - # make install - # pip install -e .[docs] - # - name: Test documentation - # run: | - # cd docs - # make html diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bd19646..0d9cfec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,147 +1,68 @@ -exclude: | - (?x)( - ^src/kweb/static/bootstrap/ - ) repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: "v4.4.0" + rev: "v4.5.0" hooks: - id: check-added-large-files + exclude: | + (?x)^( + dodata/docs/_static/.* + )$ - id: check-case-conflict - id: check-merge-conflict - id: check-symlinks - id: check-yaml - id: debug-statements - - id: end-of-file-fixer - exclude: 'changelog\.d/.*|CHANGLEOG\.md' - - id: mixed-line-ending - - id: name-tests-test - args: ["--pytest-test-first"] - - id: requirements-txt-fixer - - id: trailing-whitespace + # - id: end-of-file-fixer + # - id: mixed-line-ending + # - id: name-tests-test + # args: ["--pytest-test-first"] + # - id: trailing-whitespace + + - repo: https://github.com/charliermarsh/ruff-pre-commit + rev: "v0.2.0" + hooks: + - id: ruff + - repo: https://github.com/djlint/djLint + rev: v1.34.1 + hooks: + - id: djlint-reformat-jinja + files: "\\.html" + types_or: ['html'] exclude: | (?x)^( - changelog\.d/.*| - CHANGELOG\.md + src/kweb/static/bootstrap/.* )$ - - - repo: https://github.com/pycqa/isort - rev: "5.12.0" + - id: djlint-jinja + files: "\\.html" + types_or: ['html'] + exclude: | + (?x)^( + src/kweb/static/bootstrap/.* + )$ + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.9.0.6 hooks: - - id: isort - files: "kweb/.*" - args: ["--profile", "black", "--filter-files"] - - - repo: https://github.com/psf/black - rev: "23.7.0" + - id: shellcheck + + - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.12.0 hooks: - - id: black - - # - repo: https://github.com/pycqa/flake8 - # rev: "647996c743f9e77368ce46cc74abe98549dd4c3a" - # hooks: - # - id: flake8 + - id: pretty-format-toml + args: [--autofix] + - repo: https://github.com/codespell-project/codespell + rev: v2.2.6 + hooks: + - id: codespell + additional_dependencies: + - tomli + exclude: | + (?x)^( + src/kweb/static/bootstrap/.* + )$ + - repo: https://github.com/kynan/nbstripout - rev: 0.6.1 + rev: 0.7.1 hooks: - id: nbstripout files: ".ipynb" - - - repo: https://github.com/asottile/pyupgrade - rev: v3.10.1 - hooks: - - id: pyupgrade - args: [--py310-plus, --keep-runtime-typing] - - # - repo: https://github.com/codespell-project/codespell - # rev: 3841ffe24aba604a5d16439c8216b018a7ec649a - # hooks: - # - id: codespell - # args: ["-L TE,TE/TM,te,ba,FPR,fpr_spacing,ro,donot"] - - - repo: https://github.com/shellcheck-py/shellcheck-py - rev: v0.9.0.5 - hooks: - - id: shellcheck - - # - repo: https://github.com/pre-commit/pygrep-hooks - # rev: 7b4409161486c6956bb3206ce96db5d56731b1b9 # Use the ref you want to point at - # hooks: - # - id: python-use-type-annotations - - - repo: https://github.com/PyCQA/bandit - rev: 1.7.5 - hooks: - - id: bandit - args: [--exit-zero] - # ignore all tests, not just tests data - exclude: ^tests/ - # - repo: https://github.com/pre-commit/mirrors-mypy - # rev: "v0.991" - # hooks: - # - id: mypy - # exclude: ^(docs/|example-plugin/|tests/fixtures) - # additional_dependencies: - # - "pydantic" - # - repo: https://github.com/terrencepreilly/darglint - # rev: master - # hooks: - # - id: darglint - # - repo: https://github.com/pycqa/pydocstyle - # rev: "a6fe4222012e990042c86cdaaa904a8d059752ee" - # hooks: - # - id: pydocstyle - # additional_dependencies: ["pydocstyle[toml]"] - # - repo: https://github.com/asottile/reorder_python_imports - # rev: 2b2f0c74acdb3de316e23ceb7dd0d7945c354050 - # hooks: - # - id: reorder-python-imports - # - repo: https://github.com/PyCQA/pylint - # rev: v2.14.1 - # hooks: - # - id: pylint - # args: [--exit-zero] - # - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - # rev: 6565d773ca281682d7062d4c0be74538cc474cc9 - # hooks: - # - id: pretty-format-java - # args: [--autofix] - # - id: pretty-format-kotlin - # args: [--autofix] - # - id: pretty-format-yaml - # args: [--autofix, --indent, "2"] - # - repo: https://github.com/adrienverge/yamllint.git - # rev: v1.21.0 # or higher tag - # hooks: - # - id: yamllint - # args: [--format, parsable, --strict] - # - repo: https://github.com/jumanjihouse/pre-commit-hook-yamlfmt - # rev: 0.1.0 # or specific tag - # hooks: - # - id: yamlfmt - - repo: https://github.com/pre-commit/pygrep-hooks - rev: "v1.10.0" - hooks: - - id: python-check-blanket-noqa - - id: python-check-blanket-type-ignore - - id: python-no-log-warn - - id: python-no-eval - - id: python-use-type-annotations - - id: rst-backticks - - id: rst-directive-colons - - id: rst-inline-touching-normal - # - repo: https://github.com/nbQA-dev/nbQA - # rev: 3e5186603806260939b5f1b0372c058203c65553 - # hooks: - # - id: nbqa-black - # additional_dependencies: [jupytext, black] # optional, only if you're using Jupytext - # - id: nbqa-pyupgrade - # args: ["--py37-plus"] - # # - id: nbqa-flake8 - # # - id: nbqa-isort - # # args: ["--float-to-top"] - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.0.285" - hooks: - - id: ruff diff --git a/README.md b/README.md index f2ebce9..c0ac140 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ KWeb offers two basic apps: - Browser: A version that provides a version with a file browser for a folder and the kweb viewer for viewing the gds file in that folder. - This can be used by importing the funciton `kweb.browser.get_app` and settings the `KWEB_FILESLOCATION` env variable of passing + This can be used by importing the function `kweb.browser.get_app` and settings the `KWEB_FILESLOCATION` env variable of passing `fileslocation=` to the function. Alternatively there is a default one in `kweb.default.app` that will only look for the env variable. @@ -40,7 +40,7 @@ KWeb offers two basic apps: ```bash # Clone the repository to your local git clone https://github.com/gdsfactory/kweb.git -# Install the necessary dependecies +# Install the necessary dependencies cd /kweb python -m pip install -e .[dev] ``` @@ -63,7 +63,7 @@ Copy the link http://127.0.0.1:8000/gds/file.gds (or http://localhost:8000/gds/f #### Contributing -Pleas make sure you have also installed pre-commit before committing: +Please make sure you have also installed pre-commit before committing: ```bash python -m pip install pre-commit diff --git a/changelog.d/changelog_template.jinja b/changelog.d/changelog_template.jinja deleted file mode 100644 index 0cf429a..0000000 --- a/changelog.d/changelog_template.jinja +++ /dev/null @@ -1,15 +0,0 @@ -{% if sections[""] %} -{% for category, val in definitions.items() if category in sections[""] %} - -### {{ definitions[category]['name'] }} - -{% for text, values in sections[""][category].items() %} -- {{ text }} {{ values|join(', ') }} -{% endfor %} - -{% endfor %} -{% else %} -No significant changes. - - -{% endif %} diff --git a/pyproject.toml b/pyproject.toml index 3ddec80..e13380d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,68 +1,61 @@ [build-system] -requires = ["setuptools>=60", "wheel", "build", "setuptools_scm[toml]>=6.2"] build-backend = "setuptools.build_meta" +requires = ["setuptools>=60", "wheel", "build"] [project] -name = "kweb" -description = "KLayout API implementation of gdsfactory" -readme = "README.md" -classifiers = [ - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Operating System :: OS Independent", -] -requires-python = ">=3.10" -version = "1.2.1" authors = [ - {name = "gdsfactory community", email = "contact@gdsfactory.com"}, + {name = "gdsfactory community", email = "contact@gdsfactory.com"} +] +classifiers = [ + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Operating System :: OS Independent" ] dependencies = [ "klayout >= 0.28.11", "fastapi", "uvicorn[standard]", - "jinja2", + "jinja2" ] +description = "KLayout API implementation of gdsfactory" +name = "kweb" +readme = "README.md" +requires-python = ">=3.10" +version = "1.2.1" [project.optional-dependencies] dev = [ - "mypy", - "pre-commit", - "gitpython", - "pylsp-mypy", - "types-cachetools", - "towncrier", - "tbump" + "mypy", + "pre-commit", + "gitpython", + "pylsp-mypy", + "types-cachetools", + "towncrier", + "tbump" ] -tests = ["pytest", "pytest-cov"] docs = [ - "sphinx", - "docutils==0.17.1", - "sphinx_rtd_theme", - "sphinxcontrib-video", - "sphinx-autodoc-typehints", - "sphinx-book-theme==0.3.3", - "sphinx-click", - "sphinx-copybutton", - "sphinx-markdown-tables==0.0.17", - "myst-parser", - "matplotlib", - "nbsphinx", - "autodoc_pydantic" - ] + "sphinx", + "docutils==0.17.1", + "sphinx_rtd_theme", + "sphinxcontrib-video", + "sphinx-autodoc-typehints", + "sphinx-book-theme==0.3.3", + "sphinx-click", + "sphinx-copybutton", + "sphinx-markdown-tables==0.0.17", + "myst-parser", + "matplotlib", + "nbsphinx", + "autodoc_pydantic" +] ipy = [ - "ipython", - "ipywidgets", - "ipyevents", + "ipython", + "ipywidgets", + "ipyevents" ] - - -[tool.setuptools.packages.find] -where = ["src"] +tests = ["pytest", "pytest-cov"] [tool.black] -line-length = 88 # Specify the line length -target-version = ['py310'] # Specify your Python version -include = '\.pyi?$' exclude = ''' # Specify the files/dirs that should be ignored by the black formatter /( \.eggs @@ -78,49 +71,64 @@ exclude = ''' # Specify the files/dirs that should be ignored by the black form | dist )/ ''' +include = '\.pyi?$' +line-length = 88 # Specify the line length +target-version = ['py310'] # Specify your Python version + +[tool.djlint] +extension = "html" +format_css = true +ignore = "H021,H006,H013" + +[tool.isort] +include_trailing_comma = true +line_length = 88 +multi_line_output = 3 +skip = ["kweb/__init__.py"] [tool.mypy] +plugins = "pydantic.mypy" python_version = "3.10" strict = true -plugins = "pydantic.mypy" + +[[tool.mypy.overrides]] +implicit_reexport = true +module = "kweb" [tool.pylsp-mypy] enabled = true live_mode = true strict = true -[[tool.mypy.overrides]] -module = "kweb" -implicit_reexport = true - -[tool.isort] -multi_line_output = 3 -line_length = 88 -include_trailing_comma = true -skip = ["kweb/__init__.py"] - [tool.pytest.ini_options] -testpaths = ["tests"] # addopts = --tb=no addopts = '--tb=short' -python_files = ["src/*.py", "tests/*.py"] norecursedirs = ["extra/*.py"] +python_files = ["src/*.py", "tests/*.py"] +testpaths = ["tests"] -# [tool.pytest.ini_options] -# minversion = "6.0" -# addopts = "-ra -q" -# testpaths = [ -# "tests", -# "integration", -# ] +[tool.setuptools.packages.find] +where = ["src"] [tool.tbump] -# Uncomment this if your project is hosted on GitHub: -# github_url = "https://github.com///" + +[[tool.tbump.file]] +src = "README.md" + +[[tool.tbump.file]] +search = 'version = "{current_version}"' +src = "pyproject.toml" + +[[tool.tbump.file]] +search = '__version__ = "{current_version}"' +src = "src/kweb/__init__.py" + +[tool.tbump.git] +message_template = "Bump to {new_version}" +tag_template = "v{new_version}" [tool.tbump.version] current = "1.2.1" - # Example of a semver regexp. # Make sure this matches current_version before # using tbump @@ -131,75 +139,3 @@ regex = ''' \. (?P\d+) ''' - - -[tool.towncrier] -directory = "changelog.d" -filename = "CHANGELOG.md" -start_string = "\n" -underlines = ["", "", ""] -template = "changelog.d/changelog_template.jinja" -title_format = "## [{version}](https://github.com/gdsfactory/kweb/tree/{version}) - {project_date}" -issue_format = "[#{issue}](https://github.com/gdsfactory/kweb/issues/{issue})" - -[[tool.towncrier.type]] -directory = "security" -name = "Security" -showcontent = true - -[[tool.towncrier.type]] -directory = "removed" -name = "Removed" -showcontent = true - -[[tool.towncrier.type]] -directory = "deprecated" -name = "Deprecated" -showcontent = true - -[[tool.towncrier.type]] -directory = "added" -name = "Added" -showcontent = true - -[[tool.towncrier.type]] -directory = "changed" -name = "Changed" -showcontent = true - -[[tool.towncrier.type]] -directory = "fixed" -name = "Fixed" -showcontent = true - - -[tool.tbump.git] -message_template = "Bump to {new_version}" -tag_template = "v{new_version}" - -# For each file to patch, add a [[file]] config -# section containing the path of the file, relative to the -# tbump.toml location. -[[tool.tbump.file]] -src = "README.md" - -[[tool.tbump.file]] -src = "pyproject.toml" - -[[tool.tbump.file]] -src = "src/kweb/__init__.py" -# You can specify a list of commands to -# run after the files have been patched -# and before the git commit is made - -[[tool.tbump.before_commit]] -name = "create & check changelog" -cmd = "towncrier build --yes --version {new_version}" - -[[tool.tbump.before_commit]] -name = "create & check changelog" -cmd = "git add CHANGELOG.md" - -[[tool.tbump.before_commit]] -name = "create & check changelog" -cmd = "grep -q -F {new_version} CHANGELOG.md" diff --git a/src/kweb/api/viewer.py b/src/kweb/api/viewer.py index ee25b2c..76dfb01 100644 --- a/src/kweb/api/viewer.py +++ b/src/kweb/api/viewer.py @@ -25,9 +25,8 @@ async def gds_view_static( gds_file = (settings.fileslocation / f"{gds_name}").with_suffix(".gds") exists = ( - gds_file.exists() - and gds_file.is_file() - and gds_file.stat().st_mode # type: ignore[misc, operator] + gds_file.is_file() + and gds_file.stat().st_mode ) if not exists: @@ -51,9 +50,8 @@ async def file_view_static( file = settings.fileslocation / f"{file_name}" exists = ( - file.exists() - and file.is_file() - and file.stat().st_mode # type: ignore[misc, operator] + file.is_file() + and file.stat().st_mode ) if not exists: diff --git a/src/kweb/templates/browser.html b/src/kweb/templates/browser.html index 43b24f6..a861d32 100644 --- a/src/kweb/templates/browser.html +++ b/src/kweb/templates/browser.html @@ -1,22 +1,27 @@ - + - - - - KWeb GDS File Viewer - - - - - - {% include 'nav.html' %} + + + + + + KWeb GDS File Viewer + + + + + + + + + {% include "nav.html" %}
- {% for file in folder_files %} -
- {{file}} -
- {% endfor %} + {% for file in folder_files %} + + {% endfor %}
- + diff --git a/src/kweb/templates/nav.html b/src/kweb/templates/nav.html index 8832ad6..be80f79 100644 --- a/src/kweb/templates/nav.html +++ b/src/kweb/templates/nav.html @@ -1,14 +1,16 @@ diff --git a/src/kweb/templates/viewer.html b/src/kweb/templates/viewer.html index 707ab79..5f5fa22 100644 --- a/src/kweb/templates/viewer.html +++ b/src/kweb/templates/viewer.html @@ -1,54 +1,89 @@ - + - - - - KWeb GDS File Viewer - - - - - - - + + + + + + KWeb GDS File Viewer + + + + + + +
-
-
- -
-
- -
-
-
- -
-
-
-
- - +
+
+ +
+
+ +
+
+
+ +
+
+
+
+ + +
+
+
+
-
-
-
-
{% if cell is defined %} - + {% else %} - + {% endif %} - +