Skip to content

Commit

Permalink
Merge pull request #396 from phenobarbital/new_pyproject_support
Browse files Browse the repository at this point in the history
New pyproject support
  • Loading branch information
phenobarbital authored Jan 17, 2024
2 parents 1ef22cb + b386341 commit 8802d73
Show file tree
Hide file tree
Showing 34 changed files with 659 additions and 655 deletions.
118 changes: 91 additions & 27 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,98 @@
name: Build and Publish Python 🐍 distributions 📦 to PyPI and TestPyPI
name: Python package build and publish

on:
release:
types: [created]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v2

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install twine
- name: Build wheels on Ubuntu
if: matrix.os == 'ubuntu-latest'
uses: RalfG/python-wheels-manylinux-build@v0.5.0-manylinux2014_x86_64
with:
python-versions: 'cp39-cp39 cp310-cp310 cp311-cp311 cp312-cp312'
build-requirements: 'cython numpy'

- name: Build wheels on Windows
if: matrix.os == 'windows-latest'
run: |
pip install cibuildwheel
cibuildwheel --output-dir dist
# You may need to adjust the above command based on your package's specific requirements
- name: Upload wheel artifacts
uses: actions/upload-artifact@v2
with:
name: wheels-${{ matrix.os }}-py${{ matrix.python-version }}
path: dist/*.whl

deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install twine
- name: Build manylinux Python wheels
uses: RalfG/python-wheels-manylinux-build@v0.5.0-manylinux2014_x86_64
with:
python-versions: 'cp39-cp39 cp310-cp310 cp311-cp311'
build-requirements: 'cython numpy'
- name: Publish wheels to Test PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.NAVCONFIG_TEST_PYPI_API_TOKEN }}
run: |
twine upload -r testpypi dist/*-manylinux*.whl
- name: Publish wheels to Production PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.NAVCONFIG_PYPI_API_TOKEN }}
run: |
twine upload dist/*-manylinux*.whl
- uses: actions/checkout@v2

- name: Download all artifacts
uses: actions/download-artifact@v2
with:
path: dist

- name: Move wheel files to 'dist' directory
run: |
find dist -name '*.whl' -exec mv {} dist \;
- name: Check for wheel types
id: check_wheels
run: |
echo "Checking for wheel types..."
if ls dist/*-manylinux*.whl 1> /dev/null 2>&1; then
echo "Found manylinux wheels."
echo "HAS_MANYLINUX_WHEELS=true" >> $GITHUB_ENV
fi
if ls dist/*-win_*.whl 1> /dev/null 2>&1; then
echo "Found Windows wheels."
echo "HAS_WINDOWS_WHEELS=true" >> $GITHUB_ENV
fi
- name: List files in dist
run: ls -l dist

- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.x'

- name: Install twine
run: pip install twine

- name: Publish manylinux wheels to Production PyPI
if: env.HAS_MANYLINUX_WHEELS == 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.NAVCONFIG_PYPI_API_TOKEN }}
run: twine upload dist/*-manylinux*.whl

- name: Publish Windows wheels to Production PyPI
if: env.HAS_WINDOWS_WHEELS == 'true'
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.NAVCONFIG_PYPI_API_TOKEN }}
run: twine upload dist/*-win_*.whl
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'navconfig'
copyright = '2022, Jesus Lara G.'
copyright = '2021, Jesus Lara G.'
author = 'Jesus Lara G.'
release = 'Dual License BSD and Apache 2.0'

Expand Down
43 changes: 43 additions & 0 deletions examples/migrate_vault.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import sys
from pathlib import Path
from navconfig import config


def process_config_file(file_path):
# Check if the file exists
if not Path(file_path).is_file():
print(f"File not found: {file_path}")
return

with open(file_path, 'r') as file:
for line in file:
# Strip whitespace from the beginning and end of the line
line = line.strip()

# Skip blank lines and lines that start with '['
if not line or line.startswith('['):
continue

# Split the line into key and value at the first '='
parts = line.split('=', 1)
if len(parts) == 2:
key, value = parts
key = key.strip()
value = value.strip()
vault = config.source('vault')
if vault:
try:
vault.set(key, value)
print(f"Saved Key: {key}, Value: {value}")
except Exception as e:
print(
f"Error saving Key: {key}={value} on Vault: {e}"
)

if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python script.py <path_to_config_file>")
sys.exit(1)

config_file_path = sys.argv[1]
process_config_file(config_file_path)
19 changes: 9 additions & 10 deletions navconfig/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,35 @@

# PROJECT PATH IS DEFINED?
SITE_ROOT = project_root(__file__)
BASE_DIR = os.getenv('BASE_DIR', None)
BASE_DIR = os.getenv("BASE_DIR", None)
if not BASE_DIR:
BASE_DIR = SITE_ROOT
else:
BASE_DIR = Path(BASE_DIR).resolve()

SETTINGS_DIR = BASE_DIR.joinpath('settings')
# configuration of the environment type:
# environment type can be a file (.env) an encrypted file (crypt)
ENV_TYPE = os.getenv('ENV_TYPE', 'file')
ENV_TYPE = os.getenv("ENV_TYPE", "file")

# check if create is True (default: false), create the required directories:
CREATE = os.getenv('CONFIG_CREATE', None)
CREATE = os.getenv("CONFIG_CREATE", None)

"""
Loading main Configuration Object.
"""
config = Kardex(
SITE_ROOT,
env_type=ENV_TYPE,
create=CREATE
)
config = Kardex(SITE_ROOT, env_type=ENV_TYPE, create=CREATE)

# ENV version (dev, prod, staging)
ENV = config.ENV

# DEBUG VERSION
DEBUG = config.debug

# Settings Directory
SETTINGS_DIR = BASE_DIR.joinpath("settings")

# SECURITY WARNING: keep the secret keys used in production secret!
PRODUCTION = config.getboolean('PRODUCTION', fallback=bool(not DEBUG))
PRODUCTION = config.getboolean("PRODUCTION", fallback=bool(not DEBUG))

# Add Path Navigator to Sys path
sys.path.append(str(BASE_DIR))
Expand Down
26 changes: 13 additions & 13 deletions navconfig/conf.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import os
import logging
from navconfig import (
BASE_DIR
)
from navconfig import BASE_DIR

os.chdir(str(BASE_DIR))

### Global-Settings.
try:
from settings.settings import * # pylint: disable=W0401,W0614
from settings.settings import * # pylint: disable=W0401,W0614
except ImportError as err:
try:
from settings import settings
logging.error(f'Cannot loaded a settings Module {err}, module: {settings}')

logging.error(f"Cannot loaded a settings Module {err}, module: {settings}")
print(
'Settings.py File is missing.'
'Hint: Its recommended to use a settings/settings.py module to customize '
' NAV Configuration.'
"Settings.py File is missing."
"Hint: Its recommended to use a settings/settings.py module to customize "
" NAV Configuration."
)
except ImportError as ex:
logging.error("There is no *settings/* module in project.")
print(
'Settings.py module is missing.'
'Hint: Its recommended to use a settings/settings.py module to customize '
' NAV Configuration.'
"Settings.py module is missing."
"Hint: Its recommended to use a settings/settings.py module to customize "
" NAV Configuration."
)
### User Local Settings
try:
from settings.local_settings import * # pylint: disable=W0401,W0614
except (ImportError) as err:
from settings.local_settings import * # pylint: disable=W0401,W0614
except ImportError as err:
pass
Loading

0 comments on commit 8802d73

Please sign in to comment.