瀏覽代碼

Create file listener

Arkadiusz Ryś 3 年之前
父節點
當前提交
8eff6bddc4
共有 14 個文件被更改,包括 289 次插入92 次删除
  1. 18 0
      .editorconfig
  2. 5 0
      .gitignore
  3. 26 0
      .gitlab-ci.yml
  4. 13 0
      AUTHORS.rst
  5. 7 0
      HISTORY.rst
  6. 22 0
      LICENSE
  7. 0 92
      README.md
  8. 15 0
      README.rst
  9. 46 0
      docs/templates/pyproject.toml
  10. 3 0
      ontopoint/__init__.py
  11. 32 0
      ontopoint/main.py
  12. 18 0
      requirements.txt
  13. 73 0
      tasks.py
  14. 11 0
      tests/test_main.http

+ 18 - 0
.editorconfig

@@ -0,0 +1,18 @@
+root = true
+
+[*]
+charset = utf-8
+end_of_line = lf
+indent_size = 4
+indent_style = space
+insert_final_newline = true
+trim_trailing_whitespace = true
+
+[*.{css, html, yml, yaml, js, xml}]
+indent_size = 2
+
+[{*.log, LICENSE}]
+insert_final_newline = false
+
+[*.rst]
+indent_size = 3

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+__pycache__/
+venv/
+build/
+dist/
+*.egg-info

+ 26 - 0
.gitlab-ci.yml

@@ -0,0 +1,26 @@
+image: python:latest
+stages:
+  - build
+
+before_script:
+  - python -V
+  - echo "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi"
+  - apt-get update && apt-get install -y git
+
+build-upload:
+  stage: build
+  script:
+    - pip install build twine flit
+    - FLIT_INDEX_URL=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi flit build
+    - TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
+  only:
+    - tags
+
+build-upload-pypi:
+  stage: build
+  script:
+    - pip install build twine flit
+    - flit build
+    - python -m twine upload dist/*
+  only:
+    - tags

+ 13 - 0
AUTHORS.rst

@@ -0,0 +1,13 @@
+=======
+Credits
+=======
+
+Development Lead
+----------------
+
+* Arkadiusz Michał Ryś <Arkadiusz.Michal.Rys@gmail.com>
+
+Contributors
+------------
+
+None yet. Why not be the first?

+ 7 - 0
HISTORY.rst

@@ -0,0 +1,7 @@
+=======
+History
+=======
+
+0.0.0 (yyyy-mm-dd)
+------------------
+* No historty yet.

+ 22 - 0
LICENSE

@@ -0,0 +1,22 @@
+MIT License
+
+Copyright (c) 2022, Arkadiusz Michał Ryś
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+

文件差異過大導致無法顯示
+ 0 - 92
README.md


+ 15 - 0
README.rst

@@ -0,0 +1,15 @@
+ArkFast
+#######
+
+Installation
+------------
+
+.. code-block:: shell
+
+   pip install ontopoint
+
+or
+
+.. code-block:: shell
+
+   pip install --index-url https://pip:glpat-m8mNfhxZAUnWvy7rLS1x@git.rys.one/api/v4/projects/242/packages/pypi/simple --no-deps ontopoint

+ 46 - 0
docs/templates/pyproject.toml

@@ -0,0 +1,46 @@
+[build-system]
+requires = ["flit_core >=3.2,<4"]
+build-backend = "flit_core.buildapi"
+
+[project]
+name = "octopoint"
+authors = [
+    {name = "Arkadiusz Michał Ryś", email = "Arkadiusz.Michal.Rys@gmail.com"},
+]
+readme = "README.rst"
+requires-python = ">=3.9"
+classifiers = [
+    "License :: OSI Approved :: MIT License",
+    "Programming Language :: Python :: 3",
+    "Development Status :: 2 - Pre-Alpha",
+    "Intended Audience :: Developers",
+    "Natural Language :: English",
+]
+dynamic = ["version", "description"]
+license = {file = "LICENSE"}
+keywords = ["octopoint"]
+dependencies = [
+{%- for dependency in requirements.octopoint %}
+    "{{ dependency }}",
+{%- endfor %}
+]
+
+[project.optional-dependencies]
+test = [
+{%- for dependency in requirements.test %}
+    "{{ dependency }}",
+{%- endfor %}
+]
+doc = [
+{%- for dependency in requirements.doc %}
+    "{{ dependency }}",
+{%- endfor %}
+]
+dev = [
+{%- for dependency in requirements.dev %}
+    "{{ dependency }}",
+{%- endfor %}
+]
+
+[project.urls]
+source = "https://git.rys.one/dtdesign/octopoint"

+ 3 - 0
ontopoint/__init__.py

@@ -0,0 +1,3 @@
+"""."""
+__version__ = "0.0.1"
+__version_info__ = tuple((int(num) if num.isdigit() else num for num in __version__.replace("-", ".", 1).split(".")))

+ 32 - 0
ontopoint/main.py

@@ -0,0 +1,32 @@
+from pathlib import Path
+# import magic
+from fastapi import FastAPI, BackgroundTasks
+from starlette.responses import FileResponse
+# http://127.0.0.1:8000/
+# http://127.0.0.1:8000/docs
+# http://127.0.0.1:8000/redoc
+# http://127.0.0.1:8000/openapi.json
+app = FastAPI()
+
+data_path = Path("data")
+
+
+def write_notification(email: str, message=""):
+    with open("log.txt", mode="w") as email_file:
+        content = f"notification for {email}: {message}"
+        email_file.write(content)
+
+
+@app.get("/")
+async def root():
+    return {"ontologies": [file_path.name for file_path in data_path.glob("*")]}
+
+
+@app.get("/{name}")
+async def ontology(name: str, background_tasks: BackgroundTasks):
+    file_path = data_path / Path(name)
+    # mime = magic.Magic(mime=True)
+    # media_type = mime.from_file(file_path)
+    media_type = "text/xml"
+    background_tasks.add_task(write_notification, name, message="some notification")
+    return FileResponse(file_path, filename=file_path.name, media_type=media_type)

+ 18 - 0
requirements.txt

@@ -0,0 +1,18 @@
+# OctoPoint
+fastapi           ~= 0.85.0
+starlette         ~= 0.20.4
+python-magic      ~= 0.4.27
+uvicorn[standard] ~= 0.18.3
+# Test
+pytest ~= 7.1.3
+# Doc
+sphinx ~= 5.1.1
+# Dev
+tox      ~= 3.25.1
+pip      ~= 22.2.2
+flit     ~= 3.7.1
+twine    ~= 4.0.1
+invoke   ~= 1.7.1
+jinja2   ~= 3.1.2
+flake8   ~= 5.0.4
+coverage ~= 6.4.4

+ 73 - 0
tasks.py

@@ -0,0 +1,73 @@
+from pathlib import Path
+
+from invoke import task
+from jinja2 import Template
+
+
+@task(name="docs")
+def documentation(c):
+    """Build the documentation."""
+    c.run("python3 -m sphinx docs docs/build/html")
+
+
+@task
+def test(c):
+    """Run all tests under the tests directory."""
+    c.run("python3 -m unittest discover tests 'test_*' -v")
+
+
+@task(name="migrate")
+def migrate_requirements(c):
+    """Copy requirements from the requirements.txt file to pyproject.toml."""
+    lines = Path("requirements.txt").read_text().split("\n")
+    requirements = {"arklog": [], "test": [], "doc": [], "dev": []}
+    current = "arklog"
+    for line in lines:
+        if line.startswith("#"):
+            candidate = line[1:].lower().strip()
+            if candidate in requirements.keys():
+                current = candidate
+                continue
+        if line.strip() == "":
+            continue
+        requirements[current].append("".join(line.split()))
+    template = Template(Path("docs/templates/pyproject.toml").read_text())
+    Path("pyproject.toml").write_text(template.render(requirements=requirements))
+
+
+@task
+def release(c, version):
+    """"""
+    if version not in ["minor", "major", "patch"]:
+        print("Version can be either major, minor or patch.")
+        return
+
+    from arklog import __version_info__, __version__
+    _major, _minor, _patch = __version_info__
+
+    if version == "patch":
+        _patch = _patch + 1
+    elif version == "minor":
+        _minor = _minor + 1
+        _patch = 0
+    elif version == "major":
+        _major = _major + 1
+        _minor = 0
+        _patch = 0
+
+    c.run(f"git checkout -b release-{_major}.{_minor}.{_patch} dev")
+    c.run(f"sed -i 's/{__version__}/{_major}.{_minor}.{_patch}/g' arklog/__init__.py")
+    print(f"Update the readme for version {_major}.{_minor}.{_patch}.")
+    input("Press enter when ready.")
+    c.run(f"git add -u")
+    c.run(f'git commit -m "Update changelog version {_major}.{_minor}.{_patch}"')
+    c.run(f"git push --set-upstream origin release-{_major}.{_minor}.{_patch}")
+    c.run(f"git checkout master")
+    c.run(f"git merge --no-ff release-{_major}.{_minor}.{_patch}")
+    c.run(f'git tag -a {_major}.{_minor}.{_patch} -m "Release {_major}.{_minor}.{_patch}"')
+    c.run(f"git push")
+    c.run(f"git checkout dev")
+    c.run(f"git merge --no-ff release-{_major}.{_minor}.{_patch}")
+    c.run(f"git push")
+    c.run(f"git branch -d release-{_major}.{_minor}.{_patch}")
+    c.run(f"git push origin --tags")

+ 11 - 0
tests/test_main.http

@@ -0,0 +1,11 @@
+# Test your FastAPI endpoints
+
+GET http://127.0.0.1:8000/
+Accept: application/json
+
+###
+
+GET http://127.0.0.1:8000/hello/User
+Accept: application/json
+
+###