#!/usr/bin/env python3
"""This script create a pip package from the NcpSemApi sources."""
print("please run: ./setup.py sdist bdist_wheel")

import setuptools
import os
import glob
import sys
try:
	# this path is executed when creating the package
	sys.path.append("../../../../tools/python")
	import ncp.git
	def get_revision():
		return ncp.git.getCommitCount(".")
	
	def handle_version_file():
		version = "1.0."+str(get_revision())
		with open("NcpSemApi/version.py", "w") as file:
			file.write("# this file is generated by setup.py during package creation.\n")
			file.write("__version__ = '"+version+"'\n")
		return version

	def get_version():
		return handle_version_file()

except:
	def get_version():
		return "0.0.99999"

with open("README.md", "r") as fh:
	long_description = fh.read()

old_files = glob.glob("dist/*")
for file in old_files:
	os.remove(file)

setuptools.setup(
	name="NcpSemApi",
	version=get_version(),
	author="NCP engineering GmbH",
	author_email="info@ncp-e.com",
	description="Python API of the NCP secure enterprise management server",
	long_description=long_description,
	long_description_content_type="text/markdown",
	url="https://ncp-e.com",
	extras_require={
		"ldap-support": ["ldap3"]
	},
	install_requires=[],
	packages=["NcpSemApi"],
	license="Proprietary",
	license_files = ("LICNESE.txt",),
	classifiers=[
		"Programming Language :: Python :: 3",
		"License :: Other/Proprietary License",
		"Operating System :: OS Independent",
	],
	python_requires='>=3.7',
)
# the above command aborts when errors occure

print()
print("the package files can be found in dist/")
print("to upload them to PyPi, run 'twine upload dist/*'")
print("to try the upload without modifying the official release, upload to TestPyPi:")
print("run 'twine upload --repository-url https://test.pypi.org/legacy/ dist/*'")


