Arkadiusz Ryś 3 лет назад
Родитель
Сommit
ec8fca1b54
17 измененных файлов с 402 добавлено и 92 удалено
  1. 10 0
      .dockerignore
  2. 18 0
      .editorconfig
  3. 7 0
      .gitignore
  4. 65 0
      .gitlab-ci.yml
  5. 13 0
      AUTHORS.rst
  6. 14 0
      Dockerfile
  7. 11 0
      HISTORY.rst
  8. 22 0
      LICENSE
  9. 0 92
      README.md
  10. 15 0
      README.rst
  11. 46 0
      docs/templates/pyproject.toml
  12. 3 0
      ontopoint/__init__.py
  13. 32 0
      ontopoint/main.py
  14. 44 0
      pyproject.toml
  15. 18 0
      requirements.txt
  16. 73 0
      tasks.py
  17. 11 0
      tests/test_main.http

+ 10 - 0
.dockerignore

@@ -0,0 +1,10 @@
+__pycache__/
+*$py.class
+/.git
+/.idea
+/docs
+/data
+/.dockerignore
+/.gitignore
+/.gitlab-ci.yml
+/README.md

+ 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

+ 7 - 0
.gitignore

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

+ 65 - 0
.gitlab-ci.yml

@@ -0,0 +1,65 @@
+image: python:latest
+
+variables:
+  DOCKER_DRIVER: overlay2
+  DOCKER_TLS_CERTDIR: "/certs"
+  DOCKER_HOST: tcp://docker:2376
+  # Where to publish this build's tagged working container.
+  DOCKER_SHA: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
+  DOCKER_BRANCH: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
+  DOCKER_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
+  DOCKER_LATEST: $CI_REGISTRY_IMAGE:latest
+
+stages:
+  - build
+  - test
+  - release
+
+before_script:
+  - python -V
+  - echo "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi"
+  - apt-get update && apt-get install -y git
+  - docker info
+  # Because we use a private registry (registry.rys.one), we first need to provide credentials.
+  # This gives us access to pull and push to the registry.
+  - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
+
+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
+
+build_docker:
+  stage: build
+  script:
+    - docker pull $DOCKER_BRANCH || true
+    - docker build --cache-from $DOCKER_BRANCH -f ./Dockerfile --tag $DOCKER_BRANCH .
+    - docker push $DOCKER_BRANCH
+  only:
+    refs:
+      - master
+      - tags
+
+build_tagged_docker:
+  stage: build
+  script:
+    - docker pull $DOCKER_BRANCH || true
+    - docker tag $DOCKER_BRANCH $DOCKER_LATEST
+    - docker push $DOCKER_LATEST
+    - docker tag $DOCKER_BRANCH $DOCKER_TAG
+    - docker push $DOCKER_TAG
+  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?

+ 14 - 0
Dockerfile

@@ -0,0 +1,14 @@
+ARG PYTHON_VERSION=3.11-slim-bullseye
+FROM python:${PYTHON_VERSION}
+ARG APP_HOME=/app
+ENV PYTHONUNBUFFERED 1
+ENV PYTHONDONTWRITEBYTECODE 1
+COPY . ${APP_HOME}
+WORKDIR ${APP_HOME}
+#RUN apt-get update && apt-get install --no-install-recommends -y \
+#  libpq-dev \
+#  && apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
+#  && rm -rf /var/lib/apt/lists/*
+RUN pip install requirement.txt
+ENTRYPOINT ["python3 -m ontopoint"]
+#CMD ["/start.sh"]

+ 11 - 0
HISTORY.rst

@@ -0,0 +1,11 @@
+=======
+History
+=======
+
+0.0.2 (2023-01-13)
+------------------
+* Add release engineering.
+
+0.0.0 (yyyy-mm-dd)
+------------------
+* No history yet.

+ 22 - 0
LICENSE

@@ -0,0 +1,22 @@
+MIT License
+
+Copyright (c) 2023, 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.2"
+__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(name: str):
+    with open("access.log", mode="w") as log_file:
+        log_file.write(f"Accessed: {name}")
+
+
+@app.get("/")
+async def root():
+    ontologies = [file_path.name for file_path in data_path.glob("*")]
+    return {"ontologies": ontologies}
+
+
+@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)
+    return FileResponse(file_path, filename=file_path.name, media_type=media_type)

+ 44 - 0
pyproject.toml

@@ -0,0 +1,44 @@
+[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 = [
+]
+
+[project.optional-dependencies]
+test = [
+    "pytest~=7.2.0",
+]
+doc = [
+    "sphinx~=6.1.3",
+]
+dev = [
+    "tox~=4.2.8",
+    "pip~=22.3.1",
+    "flit~=3.8.0",
+    "twine~=4.0.2",
+    "invoke~=1.7.3",
+    "jinja2~=3.1.2",
+    "flake8~=6.0.0",
+    "coverage~=7.0.5",
+]
+
+[project.urls]
+source = "https://git.rys.one/dtdesign/octopoint"

+ 18 - 0
requirements.txt

@@ -0,0 +1,18 @@
+# OctoPoint
+fastapi           ~= 0.89.1
+starlette         ~= 0.23.1
+python-magic      ~= 0.4.27
+uvicorn[standard] ~= 0.20.0
+# Test
+pytest ~= 7.2.0
+# Doc
+sphinx ~= 6.1.3
+# Dev
+tox      ~= 4.2.8
+pip      ~= 22.3.1
+flit     ~= 3.8.0
+twine    ~= 4.0.2
+invoke   ~= 1.7.3
+jinja2   ~= 3.1.2
+flake8   ~= 6.0.0
+coverage ~= 7.0.5

+ 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 ontopoint 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' ontopoint/__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 main")
+    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
+
+###