pyMSVC


NamepyMSVC JSON
Version 0.5.4 PyPI version JSON
download
home_pageNone
SummarySimple to use MSVC build environment setup tool.
upload_time2024-08-06 05:00:04
maintainerNone
docs_urlNone
authorKevin Schlosser
requires_pythonNone
license*********************************************************************************** MIT License Copyright (c) 2020 Kevin G. Schlosser Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ***********************************************************************************
keywords windows setuptools msvc compiler build extension module
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyMSVC

A fairly stupid proof build environment setup for compiling c extensions using pythons distutils or setuptools.

I created this module because distutils does not do a good job at setting up a Windows build environment.
Distutils relies on static paths for the MSVC compiler It does not detect Visual Studio Build tools installations. And 
the largest problem with it is that it uses the vcvars*.bat files included with the compiler. It runs a subprocess 
takes a snapshot of the computer's environment then runs vcvarsall and takes another snapshot of the environment. It 
then compares the before and after and stores the differences between the 2. Now this would be a fantastic approach if
Microsoft had made the vcvars*.bat files in a manner that would et up a correct build environment. There have been known issues
using these files in the past.

The single largest problem with the vcvars files is NONE of them check to see if any of the components actually exist.
We all know how good applications are when they get uninstalled. They do a very thorough job of removing all traces 
from the registry. NOT. Microsoft is the biggest offender of this.

My system does not use the vcvars* files the information is obtained from the registry. The paths that are obtained are 
checked to ensure they exist.

Setuptools is an improvement over distutils but still relies on those vcvars* files.

`pyMSVC.Environment(strict_visual_c_version=None, minimum_visual_c_version=None)`

If both strict_visual_c_version and minimum_visual_c_version are None that the program runs as a free for all and 
whichever installation it finds first is the winner.

Both parameters accept either None or a float that is the version number fo the MSVC compiler that you want to use.

* 10.0 Visual Studio 2010
* 11.0 Visual Studio 2012
* 12.0 Visual Studio 2013
* 14.0 Visual Studio 2015
* 14.1x Visual Studio 2017
* 14.2x Visual Studio 2019
* 14.3x Visual Studio 2022

Python recommends that any extensions that are compiled on Windows should be compiled with the same MSVC version
that was used to compile Python. This is due to incompatibilities in the common runtime language between the 
compiler versions. You may or may not experience any issues if you do not use the same compiler version. Your extension 
would have to use that portion of the CLR in order to have an issue. This is why it is a recommendation.


Python versions 3.9 and 3.10 use MSVC Version 14.2
Python versions 3.5, 3.6, 3.7, 3.8 use any of the MSVC compiler version 14.x 
Python version 3.4 uses MSVC compiler version 10.0

If you would like to have the above done for you automatically and have the environment set up. You can use 
`environment = pyMSVC.setup_environment()`. This will rise an exception if the msvc version that is needed based on the 
python version is not found. This will set up the environment for you as well without the need for any additional steps.

I added the minimum_visual_c_version parameter which allows you to specify a minimum compiler version to use. 
You may have code that will compile using MSVC 10.0 but will fail if compiled using MSVC 9.0.

So to sum it up.
strict_visual_c_version you will use if only a specific compiler version is to be used to compile.
minimum_visual_c_version you will use if compiler versions that are the same or higher as the one specified are ok to use 

Here is an example of using pyMSVC to only set up the build environment.

    import os
    import pyMSVC

    environment = pyMSVC.Environment()
    print(environment)
    
    os.environ.update(environment)


You will want to set up the environment before you import distutils or setuptools.

Now onto the goodies. This module provides access to a bucket load of information. 
    
    
Here are the properties and attributes available


###### class ***Environment***
* ***machine_architecture***: Windows architecture x86 or x64
* ***platform***: x86 or x64, if running Windows x86 this will be x86. if running Windows x64 and Python x86 this will return x86.    
* ***build_environment***: returns a `dict` of the environment
* ***visual_c***: instance of VisualCInfo
* ***visual_studio***: instance of VisualStudioInfo 
* ***windows_sdk***: instance of WindowsSDKInfo
* ***dot_net***: instance of NETInfo
* ***python***: instance of PythonInfo


###### class ***NETInfo***
* ***version***: .NET version based on the platform architecture
* ***version_32***: 32bit .NET version
* ***version_64***: 64bit .NET version 
* ***directory***: directory to .NET based on preffered bitness
* ***directory_32***: 32bit .NET directory 
* ***directory_64***: 64bit .NET directory
* ***preferred_bitness***: .NET bitness
* ***netfx_sdk_directory***: .NET FX SDK path
* ***net_fx_tools_directory***: .NET FX tools path using preffered bitness
* ***net_tools***: .NET tools paths 
* ***executable_path_x64***: 64bit executable path
* ***executable_path_x86***: 32 bit execitable path
* ***lib***: library paths
   
    
###### class ***WindowsSDKInfo***
* ***extension_sdk_directory***: Extension SDK path
* ***ucrt_version***: UCRT version
* ***ucrt_sdk_directory***: Path to the UCRT libraries
* ***bin_path***: BIN path
* ***lib***: paths to the libraries.
* ***type_script_path***: path to TypeScript
* ***include***: include paths
* ***sdk_lib_path***: 
* ***windows_sdks***: Acceptable SDK versions based on compiler version
* ***version***: SDK version
* ***sdk_version***: Actual SDK version
* ***directory***: path to the Windows SDK


###### class ***VisualStudioInfo***
* ***install_directory***: installation directory
* ***dev_env_directory***: directory where devenv.exe is located
* ***common_tools***: path to tools
* ***common_version***: example - 2019 
* ***uncommon_version***: example - 16.4.5
* ***version***: VS major version


###### class ***VisualCInfo***
* ***f_sharp_path***: FSharp path
* ***ide_install_directory***: path to Visual C ide
* ***install_directory***: path to Visual C
* ***version***: Visual C version
* ***tools_version***: Visual C tool version
* ***toolset_version***: Visual C Toolset Version - v141, v140, v120 etc...
* ***msvc_dll_version***: MSVC dll version
* ***msvc_dll_path***: Location of the MSVC dll
* ***tools_redist_directory***: Visual C redist path
* ***tools_install_directory***: Visual C tools installation folder
* ***msbuild_version***: MSBuild version
* ***msbuild_path***: MSBuild path
* ***html_help_path***: HTML Help path
* ***atlmfc_lib_path***:  ATLMFC library path
* ***lib***: Visual C library path
* ***atlmfc_path***: ATLMFC path 
* ***atlmfc_include_path***: ATLMFC include path
* ***include***: Visual C include folders


###### class ***PythonInfo***
* ***architecture***: x86 or x64
* ***version***: Python version
* ***dependency***: library name.. Python27.lib
* ***includes***: include paths
* ***libraries***: library paths


Starting with Visual Studio 2017 Microsoft has added a COM interface that I am able to use
to collect information about the installed versions of Visual Studio. 

In order to collect pyMSVC to be able to use it in your build system you will 
need to create a pyproject.toml file. In that file you need to have the following lines.

    [build-system]
    requires=["setuptools", "wheel", "pyMSVC;sys_platform=='win32'"]
    build-backend="setuptools.build_meta"

This will instruct pip to collect pyMSVC if the OS is Windows.
In your setup.py file you want this at the top

    import sys

    if sys.platform.startswith('win'):
        import pyMSVC
        environment = pyMSVC.setup_environment()
        print(environment)

    import setuptools

    # rest of setup code here

The code above does everything for you. you do not need to create the 
environment using `os.environ` and you do not have to pass any versions. 
It will locate the compiler needed automatically if it is instaleld.  

It's really that easy to use. You really don't have know the inner working of
this library in order for it to be able to set up a proper build environment.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyMSVC",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "windows, setuptools, msvc, compiler, build, extension module",
    "author": "Kevin Schlosser",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/1f/a3/cf633befe53f1344d412a3a68195fd8e906205b8907a180334f95c277d62/pymsvc-0.5.4.tar.gz",
    "platform": null,
    "description": "# pyMSVC\r\n\r\nA fairly stupid proof build environment setup for compiling c extensions using pythons distutils or setuptools.\r\n\r\nI created this module because distutils does not do a good job at setting up a Windows build environment.\r\nDistutils relies on static paths for the MSVC compiler It does not detect Visual Studio Build tools installations. And \r\nthe largest problem with it is that it uses the vcvars*.bat files included with the compiler. It runs a subprocess \r\ntakes a snapshot of the computer's environment then runs vcvarsall and takes another snapshot of the environment. It \r\nthen compares the before and after and stores the differences between the 2. Now this would be a fantastic approach if\r\nMicrosoft had made the vcvars*.bat files in a manner that would et up a correct build environment. There have been known issues\r\nusing these files in the past.\r\n\r\nThe single largest problem with the vcvars files is NONE of them check to see if any of the components actually exist.\r\nWe all know how good applications are when they get uninstalled. They do a very thorough job of removing all traces \r\nfrom the registry. NOT. Microsoft is the biggest offender of this.\r\n\r\nMy system does not use the vcvars* files the information is obtained from the registry. The paths that are obtained are \r\nchecked to ensure they exist.\r\n\r\nSetuptools is an improvement over distutils but still relies on those vcvars* files.\r\n\r\n`pyMSVC.Environment(strict_visual_c_version=None, minimum_visual_c_version=None)`\r\n\r\nIf both strict_visual_c_version and minimum_visual_c_version are None that the program runs as a free for all and \r\nwhichever installation it finds first is the winner.\r\n\r\nBoth parameters accept either None or a float that is the version number fo the MSVC compiler that you want to use.\r\n\r\n* 10.0 Visual Studio 2010\r\n* 11.0 Visual Studio 2012\r\n* 12.0 Visual Studio 2013\r\n* 14.0 Visual Studio 2015\r\n* 14.1x Visual Studio 2017\r\n* 14.2x Visual Studio 2019\r\n* 14.3x Visual Studio 2022\r\n\r\nPython recommends that any extensions that are compiled on Windows should be compiled with the same MSVC version\r\nthat was used to compile Python. This is due to incompatibilities in the common runtime language between the \r\ncompiler versions. You may or may not experience any issues if you do not use the same compiler version. Your extension \r\nwould have to use that portion of the CLR in order to have an issue. This is why it is a recommendation.\r\n\r\n\r\nPython versions 3.9 and 3.10 use MSVC Version 14.2\r\nPython versions 3.5, 3.6, 3.7, 3.8 use any of the MSVC compiler version 14.x \r\nPython version 3.4 uses MSVC compiler version 10.0\r\n\r\nIf you would like to have the above done for you automatically and have the environment set up. You can use \r\n`environment = pyMSVC.setup_environment()`. This will rise an exception if the msvc version that is needed based on the \r\npython version is not found. This will set up the environment for you as well without the need for any additional steps.\r\n\r\nI added the minimum_visual_c_version parameter which allows you to specify a minimum compiler version to use. \r\nYou may have code that will compile using MSVC 10.0 but will fail if compiled using MSVC 9.0.\r\n\r\nSo to sum it up.\r\nstrict_visual_c_version you will use if only a specific compiler version is to be used to compile.\r\nminimum_visual_c_version you will use if compiler versions that are the same or higher as the one specified are ok to use \r\n\r\nHere is an example of using pyMSVC to only set up the build environment.\r\n\r\n    import os\r\n    import pyMSVC\r\n\r\n    environment = pyMSVC.Environment()\r\n    print(environment)\r\n    \r\n    os.environ.update(environment)\r\n\r\n\r\nYou will want to set up the environment before you import distutils or setuptools.\r\n\r\nNow onto the goodies. This module provides access to a bucket load of information. \r\n    \r\n    \r\nHere are the properties and attributes available\r\n\r\n\r\n###### class ***Environment***\r\n* ***machine_architecture***: Windows architecture x86 or x64\r\n* ***platform***: x86 or x64, if running Windows x86 this will be x86. if running Windows x64 and Python x86 this will return x86.    \r\n* ***build_environment***: returns a `dict` of the environment\r\n* ***visual_c***: instance of VisualCInfo\r\n* ***visual_studio***: instance of VisualStudioInfo \r\n* ***windows_sdk***: instance of WindowsSDKInfo\r\n* ***dot_net***: instance of NETInfo\r\n* ***python***: instance of PythonInfo\r\n\r\n\r\n###### class ***NETInfo***\r\n* ***version***: .NET version based on the platform architecture\r\n* ***version_32***: 32bit .NET version\r\n* ***version_64***: 64bit .NET version \r\n* ***directory***: directory to .NET based on preffered bitness\r\n* ***directory_32***: 32bit .NET directory \r\n* ***directory_64***: 64bit .NET directory\r\n* ***preferred_bitness***: .NET bitness\r\n* ***netfx_sdk_directory***: .NET FX SDK path\r\n* ***net_fx_tools_directory***: .NET FX tools path using preffered bitness\r\n* ***net_tools***: .NET tools paths \r\n* ***executable_path_x64***: 64bit executable path\r\n* ***executable_path_x86***: 32 bit execitable path\r\n* ***lib***: library paths\r\n   \r\n    \r\n###### class ***WindowsSDKInfo***\r\n* ***extension_sdk_directory***: Extension SDK path\r\n* ***ucrt_version***: UCRT version\r\n* ***ucrt_sdk_directory***: Path to the UCRT libraries\r\n* ***bin_path***: BIN path\r\n* ***lib***: paths to the libraries.\r\n* ***type_script_path***: path to TypeScript\r\n* ***include***: include paths\r\n* ***sdk_lib_path***: \r\n* ***windows_sdks***: Acceptable SDK versions based on compiler version\r\n* ***version***: SDK version\r\n* ***sdk_version***: Actual SDK version\r\n* ***directory***: path to the Windows SDK\r\n\r\n\r\n###### class ***VisualStudioInfo***\r\n* ***install_directory***: installation directory\r\n* ***dev_env_directory***: directory where devenv.exe is located\r\n* ***common_tools***: path to tools\r\n* ***common_version***: example - 2019 \r\n* ***uncommon_version***: example - 16.4.5\r\n* ***version***: VS major version\r\n\r\n\r\n###### class ***VisualCInfo***\r\n* ***f_sharp_path***: FSharp path\r\n* ***ide_install_directory***: path to Visual C ide\r\n* ***install_directory***: path to Visual C\r\n* ***version***: Visual C version\r\n* ***tools_version***: Visual C tool version\r\n* ***toolset_version***: Visual C Toolset Version - v141, v140, v120 etc...\r\n* ***msvc_dll_version***: MSVC dll version\r\n* ***msvc_dll_path***: Location of the MSVC dll\r\n* ***tools_redist_directory***: Visual C redist path\r\n* ***tools_install_directory***: Visual C tools installation folder\r\n* ***msbuild_version***: MSBuild version\r\n* ***msbuild_path***: MSBuild path\r\n* ***html_help_path***: HTML Help path\r\n* ***atlmfc_lib_path***:  ATLMFC library path\r\n* ***lib***: Visual C library path\r\n* ***atlmfc_path***: ATLMFC path \r\n* ***atlmfc_include_path***: ATLMFC include path\r\n* ***include***: Visual C include folders\r\n\r\n\r\n###### class ***PythonInfo***\r\n* ***architecture***: x86 or x64\r\n* ***version***: Python version\r\n* ***dependency***: library name.. Python27.lib\r\n* ***includes***: include paths\r\n* ***libraries***: library paths\r\n\r\n\r\nStarting with Visual Studio 2017 Microsoft has added a COM interface that I am able to use\r\nto collect information about the installed versions of Visual Studio. \r\n\r\nIn order to collect pyMSVC to be able to use it in your build system you will \r\nneed to create a pyproject.toml file. In that file you need to have the following lines.\r\n\r\n    [build-system]\r\n    requires=[\"setuptools\", \"wheel\", \"pyMSVC;sys_platform=='win32'\"]\r\n    build-backend=\"setuptools.build_meta\"\r\n\r\nThis will instruct pip to collect pyMSVC if the OS is Windows.\r\nIn your setup.py file you want this at the top\r\n\r\n    import sys\r\n\r\n    if sys.platform.startswith('win'):\r\n        import pyMSVC\r\n        environment = pyMSVC.setup_environment()\r\n        print(environment)\r\n\r\n    import setuptools\r\n\r\n    # rest of setup code here\r\n\r\nThe code above does everything for you. you do not need to create the \r\nenvironment using `os.environ` and you do not have to pass any versions. \r\nIt will locate the compiler needed automatically if it is instaleld.  \r\n\r\nIt's really that easy to use. You really don't have know the inner working of\r\nthis library in order for it to be able to set up a proper build environment.\r\n\r\n",
    "bugtrack_url": null,
    "license": "*********************************************************************************** MIT License  Copyright (c) 2020 Kevin G. Schlosser  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  ***********************************************************************************",
    "summary": "Simple to use MSVC build environment setup tool.",
    "version": "0.5.4",
    "project_urls": {
        "Homepage": "https://github.com/kdschlosser/python_msvc"
    },
    "split_keywords": [
        "windows",
        " setuptools",
        " msvc",
        " compiler",
        " build",
        " extension module"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d4af02b780a79e3ace561217df5bc08c5169aa45a1a6bf3f45ced3c47a900538",
                "md5": "bc56f9f1e15b63c1be92842120a493ef",
                "sha256": "43bc80b1c0835733591f7cc6ed03bbdcc66d0df9512228a082dd2d34e9680a4f"
            },
            "downloads": -1,
            "filename": "pyMSVC-0.5.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bc56f9f1e15b63c1be92842120a493ef",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 34251,
            "upload_time": "2024-08-06T05:00:02",
            "upload_time_iso_8601": "2024-08-06T05:00:02.327988Z",
            "url": "https://files.pythonhosted.org/packages/d4/af/02b780a79e3ace561217df5bc08c5169aa45a1a6bf3f45ced3c47a900538/pyMSVC-0.5.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1fa3cf633befe53f1344d412a3a68195fd8e906205b8907a180334f95c277d62",
                "md5": "5bd1693d7c0452b2beac2d99f3a956bd",
                "sha256": "3fc97c348a04a93e415e3d20d0194baf5327d4805b2e9a9717bfecf432be8056"
            },
            "downloads": -1,
            "filename": "pymsvc-0.5.4.tar.gz",
            "has_sig": false,
            "md5_digest": "5bd1693d7c0452b2beac2d99f3a956bd",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 36473,
            "upload_time": "2024-08-06T05:00:04",
            "upload_time_iso_8601": "2024-08-06T05:00:04.098576Z",
            "url": "https://files.pythonhosted.org/packages/1f/a3/cf633befe53f1344d412a3a68195fd8e906205b8907a180334f95c277d62/pymsvc-0.5.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-06 05:00:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kdschlosser",
    "github_project": "python_msvc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pymsvc"
}
        
Elapsed time: 0.30972s