Skip to content

Commit

Permalink
pyrobird works on pypi
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Jul 27, 2024
1 parent 9bad737 commit 2dabfe3
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,5 @@ dist
pyrobird/requirements-dev.lock

pyrobird/requirements.lock

pyrobird/src/pyrobird/server/static/
16 changes: 0 additions & 16 deletions firebird-ng/src/app/app-config.service.spec.ts

This file was deleted.

9 changes: 0 additions & 9 deletions firebird-ng/src/app/app-config.service.ts

This file was deleted.

2 changes: 1 addition & 1 deletion firebird-ng/src/assets/config.jsonc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
// Flag indicates if python Flask server from Pyrobird package is in used. Set automatically by Pyrobird
"servedByPyrobird": true
"servedByPyrobird": false
}
3 changes: 3 additions & 0 deletions pyrobird/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# MANIFEST.in

# pyrobird library
recursive-include src/pyrobird *.py

# Include YAML files
include src/pyrobird/data/*.yaml

Expand Down
51 changes: 51 additions & 0 deletions pyrobird/ng_build_copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import os
import shutil
import subprocess
import sys


def main():
# Identify the script's path
script_path = os.path.dirname(os.path.abspath(__file__))

# Define the paths
firebird_ng_path = os.path.join(script_path, '..', 'firebird-ng')
dist_path = os.path.join(firebird_ng_path, 'dist', 'firebird')
static_path = os.path.join(script_path, 'src', 'pyrobird', 'server', 'static')
# Fancy print the paths
print(f"Script Path: {script_path}")
print(f"Firebird NG Path: {firebird_ng_path}")
print(f"Dist Path: {dist_path}")
print(f"Static Path: {static_path}")

# Run `ng build` in script_path/../firebird-ng directory
try:
print("Running ng build at firebird-ng")
subprocess.run(['ng', 'build'], cwd=firebird_ng_path, check=True)
except subprocess.CalledProcessError as e:
print(f"Error running 'ng build': {e}")
sys.exit(1)

# Remove all files and folders in script_path/src/pyrobird/server/static
print("removing existing src/pyrobird/server/static")
if os.path.exists(static_path):
shutil.rmtree(static_path)
os.makedirs(static_path)

# Copy all files and directories from script_path/../firebird-ng/dist/firebird to script_path/src/pyrobird/server/static
print("copying firebird-ng/dist/firebird to src/pyrobird/server/static")
if os.path.exists(dist_path):
for item in os.listdir(dist_path):
s = os.path.join(dist_path, item)
d = os.path.join(static_path, item)
if os.path.isdir(s):
shutil.copytree(s, d)
else:
shutil.copy2(s, d)
else:
print(f"Source directory {dist_path} does not exist.")
sys.exit(1)


if __name__ == "__main__":
main()
12 changes: 10 additions & 2 deletions pyrobird/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ keywords = []
authors = [
{ name = "Dmitry Romanov", email = "[email protected]" },
]
packages = [{ include = "pyrobird" }]
classifiers = [
"Development Status :: 4 - Beta",
"Programming Language :: Python",
Expand All @@ -25,7 +26,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"click", "rich", "pyyaml", "flask_cors"
"click", "rich", "pyyaml", "flask_cors", "json5"
]

#[project.urls]
Expand All @@ -34,7 +35,8 @@ dependencies = [
#Source = "https://github.com/eic/firebird"

[project.scripts]
fbd = "pyrobird.cli:pyrobird"
fbd = "pyrobird.cli:cli_app"
pyrobird = "pyrobird.cli:cli_app"

[tool.hatch.version]
path = "src/pyrobird/__about__.py"
Expand Down Expand Up @@ -79,6 +81,11 @@ exclude_lines = [
"if TYPE_CHECKING:",
]

[tool.hatch.build]
packages = [
"src/pyrobird"
]

[tool.hatch.publish.index]
disable = true
repository = "https://upload.pypi.org/legacy/"
Expand All @@ -93,3 +100,4 @@ include = [
"src/pyrobird/server/static/**/*",
"src/pyrobird/server/templates/**/*"
]

2 changes: 1 addition & 1 deletion pyrobird/src/pyrobird/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# This file is part of Firebird Event Display and is licensed under the LGPLv3.
# See the LICENSE file in the project root for full license information.

__version__ = "0.0.7"
__version__ = "0.1.5"
2 changes: 2 additions & 0 deletions pyrobird/src/pyrobird/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
# This file is part of Firebird Event Display and is licensed under the LGPLv3.
# See the LICENSE file in the project root for full license information.

from pyrobird.__about__ import __version__

44 changes: 41 additions & 3 deletions pyrobird/src/pyrobird/server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
from csv import excel

import werkzeug.exceptions
from flask import render_template, send_from_directory, Flask, send_file, abort, Config, current_app
from flask import render_template, send_from_directory, Flask, send_file, abort, Config, jsonify, request
import flask
import json5


# Configure logging
logging.basicConfig(level=logging.INFO)
Expand Down Expand Up @@ -52,7 +54,7 @@ def _can_user_download_file(filename):
if unrestricted_download:
return True

# if allowed/disable checks are done and we are here,
# if allowed/disable checks are done, and we are here,
# if relative path is given, it will be joined with DOWNLOAD_PATH
if not os.path.isabs(filename):
return True
Expand Down Expand Up @@ -100,6 +102,42 @@ def download_file(filename):
abort(404) # Return 404 if the file does not exist


@flask_app.route('/assets/config.jsonc', methods=['GET'])
def asset_config():
config_path = 'assets/config.jsonc'

config_dict = {}

try:
# Open the config file and load its content using jsonc
with open(config_path, 'r') as file:
config_dict = json5.load(file)
except Exception as ex:
logger.error(f"error opening {config_path}: {ex}")

host = request.host.split(':')[0]
port = request.host.split(':')[1]

if not port:
port = 5454

"""
serverPort: number;
serverHost: string;
servedByPyrobird: boolean;
apiAvailable: boolean;
"""

# Modify the fields in the dictionary as needed
config_dict['serverPort'] = int(port)
config_dict['serverHost'] = host
config_dict['servedByPyrobird'] = True
config_dict['apiAvailable'] = True

# Convert the updated dictionary to JSON
return jsonify(config_dict)


@flask_app.route('/')
def index():
return static_file("index.html")
Expand All @@ -122,7 +160,7 @@ def static_file(path):
return send_from_directory(static_dir, "index.html")


def run(config=None, host=None, port=None, debug=True, load_dotenv=True):
def run(config=None, host=None, port=5454, debug=True, load_dotenv=True):
if config:
if isinstance(config, Config) or isinstance(config, map):
flask_app.config.from_mapping(config)
Expand Down
3 changes: 0 additions & 3 deletions pyrobird/src/pyrobird/server/static/.gitignore

This file was deleted.

0 comments on commit 2dabfe3

Please sign in to comment.