diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1af6572..50aad27 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,7 @@ # Deploys to PyPi on new tags. name: Build, test and publish -on: [push, pull_request] +on: [ push, pull_request ] jobs: build: @@ -17,21 +17,18 @@ jobs: - name: Rewrite version for dev if not tag if: "!startsWith(github.ref, 'refs/tags/')" run: | - perl -i -pe "s/__version__\s*=\s*'(.*?)(\.rc.*|\.a.*|\.post.*)?'/__version__='\1.dev0+${GITHUB_SHA::8}'/" setup.py + perl -i -pe "s/version\s*=\s*\"(.*?)(\.rc.*|\.a.*|\.post.*)?\"/version=\"\1.dev0+${GITHUB_SHA::8}\"/" pyproject.toml - name: Note version run: | - echo "PACKAGE_VERSION=$(python3 -- ./setup.py --version)" >> $GITHUB_ENV - - name: Set up Python 3.8 + echo "PACKAGE_VERSION=$(tomlq '.project.version' pyproject.toml -r)" >> $GITHUB_ENV + - name: Set up Python 3.12 uses: actions/setup-python@v5 with: - python-version: 3.8 - - name: Upgrade pip + python-version: 3.12 + - name: Build wheels run: | - python -m pip install --upgrade pip - - name: Build Python wheels - uses: RalfG/python-wheels-manylinux-build@v0.5.0-manylinux2014_x86_64 - with: - python-versions: 'cp36-cp36m cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310 cp311-cp311 cp312-cp312' + python3 -m pip install --upgrade pip build + python3 -m build - name: Upload wheels uses: actions/upload-artifact@v4 with: @@ -47,10 +44,10 @@ jobs: uses: actions/download-artifact@v4 with: name: wheels - - name: Set up Python 3.8 + - name: Set up Python 3.12 uses: actions/setup-python@v5 with: - python-version: 3.8 + python-version: 3.12 - name: Upgrade pip run: | python -m pip install --upgrade pip diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..8af6ea0 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +graft riptide/assets \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..8208c78 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,45 @@ +[build-system] +requires = ["setuptools"] +build-backend = "setuptools.build_meta" + +[project] +name = "riptide-lib" +version = "0.9.0" +description = "Tool to manage development environments for web applications using containers - Library Package" +readme = "README.rst" +requires-python = ">=3.8" +license = { file = "LICENSE" } +authors = [ + { name = "Marco Köpcke", email = "hello@capypara.de" } +] +classifiers = [ + "Development Status :: 4 - Beta", + "Programming Language :: Python", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", +] +dependencies = [ + "configcrunch >= 1.0.3", + "schema >= 0.7", + "pyyaml >= 5.4", + "appdirs >= 1.4", + "janus >= 0.7", + "psutil >= 5.8", + "GitPython >= 3.1", + "pywinpty >= 0.5.5; sys_platform == 'win32'", + "python-hosts >= 0.4", + "python-dotenv >= 0.19.0" +] + +[project.urls] +Repository = "https://github.com/theCapypara/riptide-lib" +Documentation = "https://riptide-docs.readthedocs.io" + +[tool.setuptools.packages.find] +exclude = ["test_assets"] diff --git a/requirements.txt b/requirements.txt index eedd2f8..f4914e7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,10 @@ -schema==0.7.5 -pyyaml==6.0.1 -configcrunch==1.0.5 +schema==0.7.7 +pyyaml==6.0.2 +configcrunch==1.1.0.post1 appdirs==1.4.4 janus==1.0.0 -psutil==5.9.8 -GitPython==3.1.42 -pywinpty==2.0.12; sys_platform == 'win32' -python-hosts==1.0.5 +psutil==6.0.0 +GitPython==3.1.43 +pywinpty==2.0.13; sys_platform == 'win32' +python-hosts==1.0.7 python-dotenv==1.0.1 diff --git a/riptide/config/document/command.py b/riptide/config/document/command.py index 2e38fe9..9fa794e 100644 --- a/riptide/config/document/command.py +++ b/riptide/config/document/command.py @@ -1,13 +1,12 @@ -from collections import OrderedDict - import os +from collections import OrderedDict from pathlib import PurePosixPath +from typing import TYPE_CHECKING, Union +from configcrunch import variable_helper from dotenv import dotenv_values from schema import Schema, Optional, Or -from typing import TYPE_CHECKING, Union -from configcrunch import variable_helper from riptide.config.document.common_service_command import ContainerDefinitionYamlConfigDocument from riptide.config.files import get_project_meta_folder, CONTAINER_SRC_PATH from riptide.config.service.config_files import process_config @@ -18,7 +17,6 @@ from riptide.config.document.project import Project from riptide.config.document.app import App - HEADER = 'command' KEY_IDENTIFIER_IN_SERVICE_COMMAND = 'in_service_with_role' @@ -30,6 +28,7 @@ class Command(ContainerDefinitionYamlConfigDocument): Placed inside an :class:`riptide.config.document.app.App`. """ + @classmethod def header(cls) -> str: return HEADER @@ -273,7 +272,8 @@ def collect_volumes(self) -> OrderedDict: services_already_checked.append(service) for config_name, config in service["config"].items(): force_recreate = False - if "force_recreate" in service["config"][config_name] and service["config"][config_name]["force_recreate"]: + if "force_recreate" in service["config"][config_name] and service["config"][config_name][ + "force_recreate"]: force_recreate = True bind_path = str(PurePosixPath('/src/').joinpath(PurePosixPath(config["to"]))) process_config(volumes, config_name, config, service, bind_path, regenerate=force_recreate) @@ -308,7 +308,23 @@ def collect_environment(self) -> dict: :return: dict. Returned format is ``{key1: value1, key2: value2}``. """ env = os.environ.copy() - keys_to_remove = {"PATH", "PS1", "USERNAME", "PWD", "SHELL", "HOME", "TMPDIR"}.intersection(set(env.keys())) + keys_to_remove = { + "PATH", + "PS1", + "USER", + "USERNAME", + "PWD", + "SHELL", + "HOME", + "TMPDIR", + "XDG_CACHE_HOME", + "XDG_CONFIG_DIRS", + "XDG_CONFIG_HOME", + "XDG_DATA_DIRS", + "XDG_DATA_HOME", + "XDG_RUNTIME_DIR", + "XDG_STATE_HOME" + }.intersection(set(env.keys())) for key in keys_to_remove: del env[key] @@ -395,6 +411,7 @@ def volume_path(self) -> str: host: '/home/peter/my_projects/project1/_riptide/cmd_data/command_name/command_cache' container: '/foo/bar/cache' """ - path = os.path.join(get_project_meta_folder(self.get_project().folder()), 'cmd_data', self.internal_get("$name")) + path = os.path.join(get_project_meta_folder(self.get_project().folder()), 'cmd_data', + self.internal_get("$name")) os.makedirs(path, exist_ok=True) return path diff --git a/riptide/config/document/config.py b/riptide/config/document/config.py index 94d04d0..7e37a27 100644 --- a/riptide/config/document/config.py +++ b/riptide/config/document/config.py @@ -64,10 +64,13 @@ def schema(cls) -> Schema: List of URLs to Git repositories containing `Riptide Repositories `_. - update_hosts_file: bool + update_hosts_file: Or[bool,str] Whether or not Riptide should automatically update the `system's host file `_. + This may be set to string, in which case the string must be a path to a hosts file to update. If it + is set to `true`, the system's default hosts file is updated. + [project]: :class:`~riptide.config.document.project.Project` If a project is loaded, Riptide inserts the project here. Do not manually insert a project into the actual system configuration file. @@ -143,7 +146,7 @@ def schema(cls) -> Schema: Optional('compression'): bool, Optional('autoexit'): int # TODO: Not used, deprecated. }, - 'update_hosts_file': bool, + 'update_hosts_file': Or(bool, str), 'engine': str, 'repos': [str], Optional('project'): DocReference(Project), # Added and overwritten by system diff --git a/riptide/config/hosts.py b/riptide/config/hosts.py index 51e78d6..5b52e5f 100644 --- a/riptide/config/hosts.py +++ b/riptide/config/hosts.py @@ -1,11 +1,12 @@ """Management of hosts-file entries for project services""" +import platform + from python_hosts import Hosts, HostsEntry from python_hosts.exception import UnableToWriteHosts from riptide.config.document.config import Config from riptide.engine.abstract import RIPTIDE_HOST_HOSTNAME - IGNORE_LOCAL_HOSTNAMES = [ "localhost", "localhost.localdomain" ] @@ -23,9 +24,17 @@ def update_hosts_file(system_config: Config, warning_callback=lambda msg: None): :param system_config: System configuration """ - if system_config["update_hosts_file"]: + if system_config["update_hosts_file"] is not False: if "project" in system_config: - hosts = Hosts() + if isinstance(system_config["update_hosts_file"], str): + hosts = Hosts(system_config["update_hosts_file"]) + else: + if platform.system() == "Darwin": + hosts = Hosts("/private/etc/hosts") + elif platform.system() == "Windows": + hosts = Hosts(r"C:\Windows\System32\Drivers\etc\hosts") + else: + hosts = Hosts() new_entries = [] changes = False @@ -50,10 +59,11 @@ def update_hosts_file(system_config: Config, warning_callback=lambda msg: None): hosts.write() except UnableToWriteHosts: entries = "\n".join([f"{e.address}\t{e.names[0]}" for e in new_entries]) - warning_callback(f"Could not update the hosts-file ({hosts.hosts_path}) to configure proxy server routing.\n" - f"> Give your user permission to edit this file, to remove this warning.\n" - f"> If you wish to manually add the entries instead, " - f"add the following entries to {hosts.hosts_path}:\n{entries}\n") + warning_callback( + f"Could not update the hosts-file ({hosts.path}) to configure proxy server routing.\n" + f"> Give your user permission to edit this file, to remove this warning.\n" + f"> If you wish to manually add the entries instead, " + f"add the following entries to {hosts.path}:\n{entries}\n") def get_localhost_hosts(): diff --git a/setup.py b/setup.py deleted file mode 100644 index 732c93e..0000000 --- a/setup.py +++ /dev/null @@ -1,43 +0,0 @@ -__version__ = '0.8.2' -from setuptools import setup, find_packages - -# README read-in -from os import path -this_directory = path.abspath(path.dirname(__file__)) -with open(path.join(this_directory, 'README.rst'), encoding='utf-8') as f: - long_description = f.read() -# END README read-in - -setup( - name='riptide-lib', - version=__version__, - packages=find_packages(), - package_data={'riptide': ['assets/*']}, - description='Tool to manage development environments for web applications using containers - Library Package', - long_description=long_description, - long_description_content_type='text/x-rst', - url='https://github.com/theCapypara/riptide-lib/', - install_requires=[ - 'configcrunch >= 1.0.3', - 'schema >= 0.7', - 'pyyaml >= 5.4', - 'appdirs >= 1.4', - 'janus >= 0.7', - 'psutil >= 5.8', - 'GitPython >= 3.1', - 'pywinpty >= 0.5.5; sys_platform == "win32"', - 'python-hosts >= 0.4', - 'python-dotenv >= 0.19.0' - ], - classifiers=[ - 'Development Status :: 3 - Alpha', - 'Programming Language :: Python', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - 'Programming Language :: Python :: 3.12', - ], -)