Skip to content

Commit

Permalink
fix asset names for windows and linux
Browse files Browse the repository at this point in the history
  • Loading branch information
rawandahmad698 committed Jan 8, 2024
1 parent 6ec09af commit c6d8a9c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ jobs:
env:
PYPI_API_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: |
twine upload dist/* --skip-existing -u __token__ -p $PYPI_API_TOKEN
twine upload dist/* --skip-existing -u __token__ -p $PYPI_API_TOKEN --verbose
2 changes: 1 addition & 1 deletion noble_tls/__version__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__title__ = "Noble TLS"
__description__ = "Advanced TLS/SSL wrapper for Python"
__version__ = "0.0.93"
__version__ = "0.0.95"
__author__ = "Rawand Ahmed Shaswar"
__license__ = "MIT"
31 changes: 12 additions & 19 deletions noble_tls/tests/test_asset.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
import pytest
from ..utils.asset import root_dir, generate_asset_name

from noble_tls.utils.asset import root_dir, generate_asset_name # Update the import path as necessary

def test_root_dir():
# Test that the root_dir function returns the expected path
# This will be a simple test to check if the returned path ends with the correct folder name
expected_part = 'noble_tls' # Assuming the root directory name is 'NobleTLS'
assert root_dir().endswith(expected_part)


def test_generate_asset_name_linux_amd64(mocker):
mocker.patch('noble_tls.utils.asset.get_system_platform', return_value='linux')
mocker.patch('platform.machine', return_value='x86_64')
mocker.patch('platform.system', return_value='Linux')
mocker.patch('platform.machine', return_value='amd64')
# Test that the asset name is correctly generated for Linux amd64
mocker.patch('ctypes.sizeof', return_value=8) # This will simulate 64-bit architecture
expected_asset_name = 'tls-client-linux-amd64-v1.7.2.so'
assert generate_asset_name() == expected_asset_name


def test_generate_asset_name_windows_x86(mocker):
# Test that the asset name is correctly generated for Windows x86
mocker.patch('noble_tls.utils.asset.get_system_platform', return_value='win32')
mocker.patch('platform.system', return_value='Windows')
mocker.patch('platform.machine', return_value='i686')
mocker.patch('platform.architecture', return_value=('32bit', ''))

expected_asset_name = 'tls-client-windows-x86-v1.7.2-32.dll'
mocker.patch('ctypes.sizeof', return_value=4) # This will simulate 32-bit architecture
expected_asset_name = 'tls-client-windows-32-v1.7.2.dll'
assert generate_asset_name() == expected_asset_name


def test_generate_asset_name_macos_arm64(mocker):
# Test that the asset name is correctly generated for macOS arm64
mocker.patch('noble_tls.utils.asset.get_system_platform', return_value='darwin')
mocker.patch('platform.system', return_value='Darwin')
mocker.patch('platform.machine', return_value='arm64')

expected_asset_name = 'tls-client-darwin-arm64-v1.7.2.dylib'
assert generate_asset_name() == expected_asset_name


def test_generate_asset_name_unknown_architecture(mocker):
# Test that the asset name is correctly generated for an unknown architecture
mocker.patch('noble_tls.utils.asset.get_system_platform', return_value='linux')
mocker.patch('platform.system', return_value='Linux')
mocker.patch('platform.machine', return_value='unknown_arch')
mocker.patch('platform.system', return_value='darwin')

expected_asset_name = 'tls-client-darwin-unknown-v1.7.2.dylib'
mocker.patch('ctypes.sizeof', return_value=8) # Assuming 64-bit for an unknown architecture
expected_asset_name = 'tls-client-linux-amd64-v1.7.2.so'
assert generate_asset_name() == expected_asset_name

49 changes: 20 additions & 29 deletions noble_tls/utils/asset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ctypes
import os
import platform

import sys

def root_dir():
# Get the absolute path of the current file
Expand All @@ -13,6 +14,9 @@ def root_dir():
root_dir = os.path.dirname(current_dir_path)
return root_dir

def get_system_platform():
return sys.platform


def generate_asset_name(
custom_part: str = 'tls-client',
Expand All @@ -28,38 +32,25 @@ def generate_asset_name(
# Get the system's OS name and architecture
system_os = platform.system().lower()
architecture = platform.machine().lower()
sys_platform = get_system_platform()

# Common architecture names to the ones used in the assets
arch_map = {
'x86_64': 'amd64',
'amd64': 'amd64',
'arm64': 'arm64',
'aarch64': 'arm64',
'i386': 'x86',
'i686': 'x86',
'x86': 'x86'
}

# Check if we have a corresponding architecture in the map
asset_arch = arch_map.get(architecture, 'unknown')

# Determine file extension based on OS
if system_os == 'darwin': # macOS
# Correct the platform checks and architecture determination
if sys_platform == 'darwin':
file_extension = '.dylib'
elif system_os == 'windows':
# Check pointer size to determine if the architecture is 64-bit or 32-bit
file_extension = '-64.dll' if platform.architecture()[0] == '64bit' else '-32.dll'
elif system_os == 'linux':
file_extension = '.so'
# Debian
if 'debian' in platform.version().lower():
system_os = 'debian'
asset_arch = 'arm64' if architecture == "arm64" else 'amd64'
elif sys_platform in ('win32', 'cygwin'):
file_extension = '.dll'
asset_arch = '64' if 8 == ctypes.sizeof(ctypes.c_voidp) else '32'
else:
file_extension = '.so' # Default to .so for other Unix-like systems
# I don't possess a Linux machine to test this on, so I'm not sure if this is correct
file_extension = '.so'

# Handle special case for x86 architecture on non-Windows systems
if system_os == 'darwin' and 'x86' in architecture:
asset_arch = 'amd64'
if architecture == "aarch64":
asset_arch = 'arm64'
elif "x86" in architecture:
asset_arch = 'amd64'
else:
asset_arch = 'amd64'

return f"{custom_part}-{system_os}-{asset_arch}-v{version}{file_extension}"

Expand Down

0 comments on commit c6d8a9c

Please sign in to comment.