Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
configure.bat eol=crlf
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ python:
install:
- ./configure
script:
- tmp/bin/pytest
- tmp/bin/pytest
45 changes: 45 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

################################################################################
# We use Azure to run the full tests suites on Python 3.6
# on Windows (32 and 64), macOS and Linux (64 various distro)
################################################################################

jobs:

################################################################################
# These jobs are using VMs and Azure-provided Python 3.6
################################################################################

- template: etc/ci/azure-linux.yml
parameters:
job_name: ubuntu18_py36
image_name: ubuntu-18.04
python_versions: ['3.6']
test_suites:
all: tmp/bin/pytest -n 2 -vvs

- template: etc/ci/azure-mac.yml
parameters:
job_name: macos1015_py36
image_name: macos-10.15
python_versions: ['3.6']
test_suites:
all: tmp/bin/pytest -n 2 -vvs

- template: etc/ci/azure-win.yml
parameters:
job_name: win2019_32_py36
image_name: windows-2019
python_versions: ['3.6']
python_architecture: x86
test_suites:
all: tmp\Scripts\pytest -vvs

- template: etc/ci/azure-win.yml
parameters:
job_name: win2019_64_py36
image_name: windows-2019
python_versions: ['3.6']
python_architecture: x64
test_suites:
all: tmp\Scripts\pytest -vvs
1 change: 0 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function setup {
setup

$CONFIGURE_ROOT_DIR/tmp/bin/pip install -e .[testing]
$CONFIGURE_ROOT_DIR/tmp/bin/pip install typecode_libmagic

if [ -f "$CONFIGURE_ROOT_DIR/tmp/bin/activate" ]; then
source "$CONFIGURE_ROOT_DIR/tmp/bin/activate"
Expand Down
121 changes: 121 additions & 0 deletions configure.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
@echo OFF
@setlocal
@rem Copyright (c) nexB Inc. http://www.nexb.com/ - All rights reserved.

@rem ################################
@rem # A configuration script for Windows
@rem #
@rem # The options and (optional) arguments are:
@rem # --clean : this is exclusive of anything else and cleans the environment
@rem # from built and installed files
@rem #
@rem # --python < path to python.exe> : this must be the first argument and set
@rem # the path to the Python executable to use. If < path to python.exe> is
@rem # set to "path", then the executable will be the python.exe available
@rem # in the PATH.
@rem ################################

@rem Current directory where this .bat files lives
set CFG_ROOT_DIR=%~dp0
@rem path where a configured Python should live in the current virtualenv if installed
set CONFIGURED_PYTHON=%CFG_ROOT_DIR%tmp\Scripts\python.exe
set PYTHON_EXECUTABLE=


@rem parse command line options and arguments
:collectopts
if "%1" EQU "--help" (goto cli_help)
if "%1" EQU "--clean" (call rmdir /s /q "%CFG_ROOT_DIR%tmp") && call exit /b
if "%1" EQU "--python" (set PROVIDED_PYTHON=%~2) && shift && shift && goto collectopts

@rem If we have a pre-configured Python in our virtualenv, reuse this as-is and run
if exist ""%CONFIGURED_PYTHON%"" (
set PYTHON_EXECUTABLE=%CONFIGURED_PYTHON%
goto run
)

@rem If we have a command arg for Python use this as-is
if ""%PROVIDED_PYTHON%""==""path"" (
@rem use a bare python available in the PATH
set PYTHON_EXECUTABLE=python
goto run
)
if exist ""%PROVIDED_PYTHON%"" (
set PYTHON_EXECUTABLE=%PROVIDED_PYTHON%
goto run
)


@rem otherwise we search for a suitable Python interpreter
:find_python
@rem First check the existence of the "py" launcher (available in Python 3)
@rem if we have it, check if we have a py -3 installed with the good version or a py 2.7
@rem if not, check if we have an old py 2.7
@rem exist if all fails

where py >nul 2>nul
if %ERRORLEVEL% == 0 (
@rem we have a py launcher, check for the availability of our required Python 3 version
py -3.6 --version >nul 2>nul
if %ERRORLEVEL% == 0 (
set PYTHON_EXECUTABLE=py -3.6
) else (
@rem we have no required python 3, let's try python 2:
py -2 --version >nul 2>nul
if %ERRORLEVEL% == 0 (
set PYTHON_EXECUTABLE=py -2
) else (
@rem we have py and no python 3 and 2, exit
echo * Unable to find an installation of Python.
exit /b 1
)
)
) else (
@rem we have no py launcher, check for a default Python 2 installation
if not exist ""%DEFAULT_PYTHON2%"" (
echo * Unable to find an installation of Python.
exit /b 1
) else (
set PYTHON_EXECUTABLE=%DEFAULT_PYTHON2%
)
)


:run
@rem without this things may not always work on Windows 10, but this makes things slower
set PYTHONDONTWRITEBYTECODE=1

call mkdir "%CFG_ROOT_DIR%tmp"
call curl -o "%CFG_ROOT_DIR%tmp\virtualenv.pyz" https://bootstrap.pypa.io/virtualenv.pyz
call %PYTHON_EXECUTABLE% "%CFG_ROOT_DIR%tmp\virtualenv.pyz" "%CFG_ROOT_DIR%tmp"
call "%CFG_ROOT_DIR%tmp\Scripts\activate"
call "%CFG_ROOT_DIR%tmp\Scripts\pip" install --upgrade pip virtualenv setuptools wheel
call "%CFG_ROOT_DIR%tmp\Scripts\pip" install -e .[testing]

@rem Return a proper return code on failure
if %ERRORLEVEL% neq 0 (
exit /b %ERRORLEVEL%
)
endlocal
goto activate


:cli_help
echo A configuration script for Windows
echo usage: configure [options] [path/to/config/directory]
echo.
echo The options and arguments are:
echo --clean : this is exclusive of anything else and cleans the environment
echo from built and installed files
echo.
echo --python path/to/python.exe : this is set to the path of an alternative
echo Python executable to use. If path/to/python.exe is set to "path",
echo then the executable will be the python.exe available in the PATH.
echo.


:activate
@rem Activate the virtualenv
if exist "%CFG_ROOT_DIR%tmp\Scripts\activate" (
"%CFG_ROOT_DIR%tmp\Scripts\activate"
)
37 changes: 37 additions & 0 deletions etc/ci/azure-linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
parameters:
job_name: ''
image_name: 'ubuntu-16.04'
python_versions: []
test_suites: {}
python_architecture: x64

jobs:
- job: ${{ parameters.job_name }}

pool:
vmImage: ${{ parameters.image_name }}

strategy:
matrix:
${{ each pyver in parameters.python_versions }}:
${{ each tsuite in parameters.test_suites }}:
${{ format('py{0} {1}', pyver, tsuite.key) }}:
python_version: ${{ pyver }}
test_suite_label: ${{ tsuite.key }}
test_suite: ${{ tsuite.value }}

steps:
- checkout: self
fetchDepth: 10

- task: UsePythonVersion@0
inputs:
versionSpec: '$(python_version)'
architecture: '${{ parameters.python_architecture }}'
displayName: 'Install Python $(python_version)'

- script: ./configure
displayName: 'Run Configure'

- script: $(test_suite)
displayName: 'Run $(test_suite_label) tests with py$(python_version) on ${{ parameters.job_name }}'
36 changes: 36 additions & 0 deletions etc/ci/azure-mac.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
parameters:
job_name: ''
image_name: ''
python_versions: []
test_suites: {}
python_architecture: x64

jobs:
- job: ${{ parameters.job_name }}

pool:
vmImage: ${{ parameters.image_name }}

strategy:
matrix:
${{ each pyver in parameters.python_versions }}:
${{ each tsuite in parameters.test_suites }}:
${{ format('py{0} {1}', pyver, tsuite.key) }}:
python_version: ${{ pyver }}
test_suite_label: ${{ tsuite.key }}
test_suite: ${{ tsuite.value }}
steps:
- checkout: self
fetchDepth: 10

- task: UsePythonVersion@0
inputs:
versionSpec: '$(python_version)'
architecture: '${{ parameters.python_architecture }}'
displayName: 'Install Python $(python_version)'

- script: ./configure
displayName: 'Run Configure'

- script: $(test_suite)
displayName: 'Run $(test_suite_label) tests with py$(python_version) on ${{ parameters.job_name }}'
40 changes: 40 additions & 0 deletions etc/ci/azure-win.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
parameters:
job_name: ''
image_name: ''
python_versions: []
test_suites: {}
python_architecture: x86

jobs:
- job: ${{ parameters.job_name }}

pool:
vmImage: ${{ parameters.image_name }}

strategy:
matrix:
${{ each pyver in parameters.python_versions }}:
${{ each tsuite in parameters.test_suites }}:
${{ format('py{0} {1}', pyver, tsuite.key) }}:
python_version: ${{ pyver }}
test_suite_label: ${{ tsuite.key }}
test_suite: ${{ tsuite.value }}
steps:
- script: |
git config --global core.autocrlf false
set

- checkout: self
fetchDepth: 10

- task: UsePythonVersion@0
inputs:
versionSpec: '$(python_version)'
architecture: '${{ parameters.python_architecture }}'
displayName: 'Install Python $(python_version)'

- script: configure --python path
displayName: 'Run Configure'

- script: $(test_suite)
displayName: 'Run $(test_suite_label) tests with py$(python_version) on ${{ parameters.job_name }}'
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ where=src
testing =
pytest
pytest-xdist
typecode-libmagic
full =
typecode-libmagic
minimal =
Expand Down
14 changes: 11 additions & 3 deletions tests/typecode/test_contenttype.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ def test_code_c_1(self):
'ti-xx graphing calculator (flash)',
# correct in libmagic 5.39+
'c source, ascii text',
# libmagic 5.39+ on Windows
'c source, ascii text, with crlf line terminators',
)
assert get_filetype(test_file) in expected
assert 'C' == get_filetype_pygment(test_file)
Expand All @@ -206,6 +208,8 @@ def test_code_c_7(self):
'ti-xx graphing calculator (flash)',
# correct in libmagic 5.39+
'c source, ascii text',
# libmagic 5.39+ on Windows
'c source, ascii text, with crlf line terminators',
)
assert get_filetype(test_file) in expected
assert is_source(test_file)
Expand All @@ -216,13 +220,17 @@ def test_code_python_2(self):
assert is_source(test_file)
assert is_text(test_file)
assert 'Python' == get_filetype_pygment(test_file)
assert 'python script, ascii text executable' == get_filetype(test_file)
expected = (
filetype_expected = (
'python script, ascii text executable',
'python script, ascii text executable, with crlf line terminators',
)
assert get_filetype(test_file) in filetype_expected
mimetype_expected = (
'text/x-python',
# new in libmagic 5.39
'text/x-script.python',
)
assert get_mimetype_file(test_file) in expected
assert get_mimetype_file(test_file) in mimetype_expected
assert get_filetype_file(test_file).startswith('Python script')

def test_compiled_elf_so(self):
Expand Down