Skip to content

Commit

Permalink
fix(ci): use pyproject and ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Dec 30, 2024
1 parent de90043 commit 279a0c8
Show file tree
Hide file tree
Showing 17 changed files with 172 additions and 92 deletions.
41 changes: 25 additions & 16 deletions .github/workflows/test_and_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- uses: actions/setup-python@v2
- uses: actions/setup-python@v5
with:
python-version: "3.9"

Expand All @@ -28,7 +28,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
python-version: ["3.9"]
config:
- {
name: "Linux",
Expand All @@ -49,10 +49,10 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -71,9 +71,9 @@ jobs:
seleniumbase install chromedriver
- name: Set Up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18

- name: Build Vue2 App
run: |
Expand Down Expand Up @@ -105,12 +105,12 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set Up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18

- name: Build Vue2 App
run: |
Expand All @@ -128,17 +128,23 @@ jobs:
needs: [pre-commit, pytest, test-npm-build]
runs-on: ubuntu-latest
if: github.event_name == 'push'
environment:
name: pypi
url: https://pypi.org/p/trame-client
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
contents: write # IMPORTANT: mandatory for making GitHub Releases

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set Up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 18

- name: Build Vue2 App
run: |
Expand All @@ -153,8 +159,11 @@ jobs:
npm run build
- name: Python Semantic Release
uses: relekang/python-semantic-release@v7.34.6
id: release
uses: relekang/python-semantic-release@v9.15.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
repository_username: __token__
repository_password: ${{ secrets.PYPI_API_TOKEN }}

- name: Publish package distributions to PyPI
if: steps.release.outputs.released == 'true'
uses: pypa/gh-action-pypi-publish@release/v1
13 changes: 4 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
repos:
- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black
entry: black --check

- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.4
hooks:
- id: flake8
- id: ruff
- id: ruff-format
3 changes: 1 addition & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Tips
####

#. When first creating a new project, it is helpful to run ``pre-commit run --all-files`` to ensure all files pass the pre-commit checks.
#. A quick way to fix ``black`` issues is by installing black (``pip install black``) and running the ``black`` command at the root of your repository.
#. Sometimes, ``black`` and ``flake8`` do not agree. Add options to your ``.flake8`` file to fix these things. See the `flake8 configuration docs <https://flake8.pycqa.org/en/latest/user/configuration.html>`_ for more details.
#. A quick way to fix ``ruff`` issues is by installing ruff (``pip install ruff``) and running the ``ruff check --fix .`` or ``ruff format`` command at the root of your repository.
#. A quick way to fix ``codespell`` issues is by installing codespell (``pip install codespell``) and running the ``codespell -w`` command at the root of your directory.
#. The `.codespellrc file <https://github.com/codespell-project/codespell#using-a-config-file>`_ can be used fix any other codespell issues, such as ignoring certain files, directories, words, or regular expressions.
7 changes: 7 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ graft trame_client/module/vue3-www
recursive-exclude trame_client/module/vue2-www *.map
recursive-exclude trame_client/module/vue3-www *.map
include trame_client/LICENSE
prune examples
prune js-lib
prune tests
prune visual_baseline
prune vue-app
prune vue2-app
prune vue3-app
4 changes: 3 additions & 1 deletion examples/vue2/namespace_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def main():
app.ctrl.plus()
one_of_the_app = app

# root_server.controller.on_server_ready.add(lambda **kwargs: print(json.dumps(root_server.state.to_dict(), indent=2)))
# root_server.controller.on_server_ready.add(
# lambda **kwargs: print(json.dumps(root_server.state.to_dict(), indent=2))
# )
root_server.controller.on_server_ready.add(
lambda **kwargs: print("Root server ready")
)
Expand Down
4 changes: 3 additions & 1 deletion examples/vue3/namespace_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def main():
app.ctrl.plus()
one_of_the_app = app

# root_server.controller.on_server_ready.add(lambda **kwargs: print(json.dumps(root_server.state.to_dict(), indent=2)))
# root_server.controller.on_server_ready.add(
# lambda **kwargs: print(json.dumps(root_server.state.to_dict(), indent=2))
# )
root_server.controller.on_server_ready.add(
lambda **kwargs: print("Root server ready")
)
Expand Down
90 changes: 90 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[project]
name = "trame-client"
version = "3.5.0"
description = "Internal client of trame"
authors = [
{name = "Kitware Inc."},
]
dependencies = [
]
requires-python = ">=3.9"
readme = "README.rst"
license = {text = "MIT"}
keywords = ["Python", "Interactive", "Web", "Application", "Framework"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Web Environment",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Software Development :: Libraries :: Application Frameworks",
"Topic :: Software Development :: Libraries :: Python Modules",
]

[project.optional-dependencies]
test = [
"pytest",
"seleniumbase",
"pytest-xprocess",
"Pillow",
"pixelmatch",
]
dev = [
"pre-commit",
"ruff",
]

[build-system]
requires = ['setuptools', 'wheel']
build-backend = 'setuptools.build_meta'

[tool.setuptools.packages.find]
where = ["."]

[tool.setuptools.package-data]


[tool.semantic_release]
version_toml = [
"pyproject.toml:project.version",
]
build_command = """
python -m venv .venv
source .venv/bin/activate
pip install -U pip build
python -m build .
"""

[semantic_release.publish]
dist_glob_patterns = ["dist/*"]
upload_to_vcs_release = true

[tool.ruff]
line-length = 88
indent-width = 4
target-version = "py39"

[tool.ruff.lint]
select = ["E", "W", "F"]
ignore = []
fixable = ["ALL"]
unfixable = []


[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
docstring-code-format = true

# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"

[tool.ruff.lint.pycodestyle]
max-line-length = 120

[lint.pydocstyle]
convention = "google"
41 changes: 0 additions & 41 deletions setup.cfg

This file was deleted.

3 changes: 0 additions & 3 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion trame/modules/www.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from trame_client.module import *
from trame_client.module import * # noqa F403
2 changes: 1 addition & 1 deletion trame/ui/html.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from trame_client.ui.html import *
from trame_client.ui.html import * # noqa F403
2 changes: 1 addition & 1 deletion trame/widgets/client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from trame_client.widgets.trame import *
from trame_client.widgets.trame import * # noqa F403


def initialize(server):
Expand Down
2 changes: 1 addition & 1 deletion trame/widgets/html.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from trame_client.widgets.html import *
from trame_client.widgets.html import * # noqa F403


def initialize(server):
Expand Down
35 changes: 25 additions & 10 deletions trame_client/ui/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,21 @@ def iframe_url_builder_jupyter_extension(layout):
www_endpoint = os.environ.get("TRAME_JUPYTER_ENDPOINT", "/trame-jupyter-server")
server = layout.server
template_name = layout._template_name
src = f"{www_endpoint}/{server.client_type}/index.html?ui={template_name[16:]}&server={server.name}&wsProxy&reconnect=auto"
url_base = f"{www_endpoint}/{server.client_type}/index.html"
url_query = f"ui={template_name[16:]}&server={server.name}&wsProxy&reconnect=auto"
src = f"{url_base}?{url_query}"
elem_id = f"{server.name}_{template_name}"

# Check if server/kernel are collocated
www_path = os.environ.get("TRAME_JUPYTER_WWW")

if www_path and Path(www_path).exists():
server_www = Path(www_path) / "servers" / server.name
src = f"{www_endpoint}/servers/{server.name}/index.html?ui={template_name[16:]}&server={server.name}&wsProxy&reconnect=auto"
url_base = f"{www_endpoint}/servers/{server.name}/index.html"
url_query = (
f"ui={template_name[16:]}&server={server.name}&wsProxy&reconnect=auto"
)
src = f"{url_base}?{url_query}"
if not server_www.exists():
shutil.copytree(server._www, str(server_www.resolve()), dirs_exist_ok=True)
for sub_path, src_dir in server.serve.items():
Expand All @@ -81,7 +87,11 @@ def iframe_url_builder_jupyter_extension(layout):
def iframe_url_builder_jupyter_hub(layout):
server = layout.server
template_name = layout._template_name
src = f"{os.environ['JUPYTERHUB_SERVICE_PREFIX']}proxy/{server.port}/index.html?ui={template_name[16:]}&reconnect=auto"
url_base = (
f"{os.environ['JUPYTERHUB_SERVICE_PREFIX']}proxy/{server.port}/index.html"
)
url_query = f"ui={template_name[16:]}&reconnect=auto"
src = f"{url_base}?{url_query}"
elem_id = f"{server.name}_{template_name}"

return {
Expand All @@ -96,7 +106,9 @@ def iframe_url_builder_jupyter_hub_host(layout):
host = os.environ.get("HOSTNAME")
server = layout.server
template_name = layout._template_name
src = f"{os.environ['JUPYTERHUB_SERVICE_PREFIX']}proxy/{host}:{server.port}/index.html?ui={template_name[16:]}&reconnect=auto"
url_base = f"{os.environ['JUPYTERHUB_SERVICE_PREFIX']}proxy/{host}:{server.port}/index.html"
url_query = f"ui={template_name[16:]}&reconnect=auto"
src = f"{url_base}?{url_query}"
elem_id = f"{server.name}_{template_name}"

return {
Expand Down Expand Up @@ -181,7 +193,8 @@ def iframe_builder(self, name_or_fn):
@property
def root(self):
"""
Top level Vue component. Useful for providing / injecting into children components. Setting makes old root child of new root.
Top level Vue component. Useful for providing / injecting into children components.
Setting makes old root child of new root.
"""
return self._current_root

Expand Down Expand Up @@ -255,11 +268,13 @@ def __exit__(self, exc_type, exc_value, exc_traceback):

def _jupyter_content(self):
if not self.server.running:
return """<div>
The server is not running. Before displaying a trame layout you should await it to make sure it is ready.
You should run the following code before displaying a layout.
<pre style="padding: 5px; border: solid 1px rgb(224,224,224); background: rgb(245,245,245);">await layout.ready</pre>
</div>"""
return """
<div>
The server is not running.
Before displaying a trame layout you should await it to make sure it is ready.
You should run the following code before displaying a layout.
<pre style="padding: 5px; border: solid 1px rgb(224,224,224); background: rgb(245,245,245);">await layout.ready</pre>
</div>"""

attributes = self.iframe_builder(self)
attributes_str = " ".join(
Expand Down
Loading

0 comments on commit 279a0c8

Please sign in to comment.