diff --git a/.gitignore b/.gitignore index ae84d1d..84a03cf 100644 --- a/.gitignore +++ b/.gitignore @@ -6,9 +6,8 @@ __pycache__/ source.asn* # Distutils artifacts -MANIFEST -build/ -dist/ +/build/ +/dist/ # Patches *.patch @@ -17,7 +16,9 @@ dist/ .ropeproject env/ dbg/ -_testdir +/_testdir # TODO todo.txt + +/uv.lock diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 300545f..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,3 +0,0 @@ -include *.txt - -prune testdata diff --git a/README.txt b/README.rst similarity index 84% rename from README.txt rename to README.rst index 5013834..dbee57e 100644 --- a/README.txt +++ b/README.rst @@ -1,5 +1,5 @@ asn1ate -- ASN.1 translation library. -Copyright (c) 2013-2019, Schneider Electric Buildings AB +Copyright (c) 2013-2025, Schneider Electric Buildings AB Introduction ------------ @@ -111,3 +111,45 @@ includes the generally useful one, ``asn1ate.pyasn1gen``. The most notable members of ``asn1ate.support`` are probably the ``PythonWriter`` and ``PythonFragment`` classes, which simplify generation of correctly indented Python code. + +Building and testing with uv +---------------------------- +Run tests: +```sh +# Make sure uv is installed +./basic_test.sh # or .\basic_test.bat on Windows +``` + +Build .whl +```sh +uv build +``` + +Building and testing with native Python +--------------------------------------- +Create a virtual environment +```sh +# 1) Create a venv +python -m venv .venv +# 2) Use the virtual environment +## Linux/MacOS +source .venv/bin/activate +## Windows +.\.venv\Script\activate.ps1 (or activate.bat on cmd) +# 3) Install dependencies +pip install pyproject.toml +``` +For building the project: +```sh +pip install build +python -m build +``` +Run tests (make sure to use .venv first) +```sh +# On Linux/MacOS +./basic_test.sh +``` +```powershell +# On Windows +.\basic_test.bat +``` diff --git a/asn1ate/__init__.py b/asn1ate/__init__.py deleted file mode 100644 index ac38b86..0000000 --- a/asn1ate/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ - -# asn1ate version -__version__ = '0.6.1.dev0' diff --git a/basic_test.bat b/basic_test.bat index 4d680e1..5dedc52 100644 --- a/basic_test.bat +++ b/basic_test.bat @@ -8,19 +8,29 @@ REM 2) The end result is valid Python REM Note that it does not say anything about correctness or REM completeness of the generated code. +REM Check if uv is installed +WHERE uv >NUL 2>&1 +IF %ERRORLEVEL%==0 ( + REM uv automatically uses .venv and installs dependencies + SET runpy=uv run +) ELSE ( + SET runpy=python +) + FOR %%t IN (testdata\*.asn) DO ( @ECHO Checking %%t RD /s /q _testdir MD _testdir - python asn1ate\test.py --outdir=_testdir --gen %%t + %runpy% src\asn1ate\test.py --outdir=_testdir --gen %%t IF %ERRORLEVEL% NEQ 0 ( - EXIT /B %ERRORLEVEL% + EXIT /B %ERRORLEVEL% ) FOR %%m IN (_testdir\*.py) DO ( - python %%m + %runpy% %%m + ) IF %ERRORLEVEL% NEQ 0 ( - EXIT /B %ERRORLEVEL% + EXIT /B %ERRORLEVEL% ) ) ) diff --git a/basic_test.sh b/basic_test.sh index b64a8fa..0addd18 100755 --- a/basic_test.sh +++ b/basic_test.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/env sh # For every *.asn file, run it through test.py and pipe # the result back to Python. @@ -10,16 +10,29 @@ set -e -export PYTHONPATH=`pwd` +PYTHONPATH="$(pwd)" +export PYTHONPATH +if command -v uv >/dev/null 2>&1 +then + # Automatically uses .venv and install dependencies + RUNPY='uv run' +elif command -v python >/dev/null 2>&1 +then + RUNPY='python' +else + # Debian/Ubuntu doesn't call Python "python" + RUNPY='python3' +fi + for f in testdata/*.asn; do echo "Checking $f"; rm -rf _testdir/ - mkdir -p _testdir/ - python asn1ate/test.py --outdir=_testdir --gen $f + mkdir _testdir/ + $RUNPY src/asn1ate/test.py --outdir=_testdir --gen "$f" # Run python over _testdir/*.py for m in _testdir/*.py; do - python $m + $RUNPY "$m" done done diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..cade11c --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,44 @@ +[build-system] +requires = ["uv_build>=0.8.0,<0.10.0"] +build-backend = "uv_build" + +[project] +name = "asn1ate" +version = "0.6.2" +license = "BSD-3-Clause" +license-files = ["LICENSE.txt"] +description = "ASN.1 translation library." +readme = "README.rst" +authors = [ + { name = "Schneider Electric", email = "OSPO@se.com" }, + { name = "Kim Gräsman", email = "kim.grasman@gmail.com" } +] + +classifiers = [ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Topic :: Software Development :: Code Generators" +] + +requires-python = ">=3.10" +dependencies = [ + "pyparsing >=2.0.0, !=3.0.5, !=3.0.6", +] + +[dependency-groups] +dev = [ + "pyasn1", + "build" +] + +[project.urls] +Repository = "https://github.com/schneider-electric/asn1ate" + +[project.scripts] +asn1ate = "asn1ate.pyasn1gen:main_cli" + +[tool.uv.build-backend] +source-exclude = ["src/asn1ate/test.py"] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 49db703..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -pyasn1>=0.1.8 --e . diff --git a/setup.py b/setup.py deleted file mode 100644 index fe42b0e..0000000 --- a/setup.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import os - -try: - from setuptools import setup -except: - from distutils.core import setup - - -def get_version(): - version_file = os.path.join(os.path.dirname(__file__), - 'asn1ate', '__init__.py') - - environment = {} - with open(version_file) as fp: - exec(fp.read(), environment) - - return environment['__version__'] - - -setup( - name='asn1ate', - version=get_version(), - description='ASN.1 translation library.', - author='Kim Gräsman', - author_email='kim.grasman@gmail.com', - license='BSD', - long_description=open('README.txt').read(), - url='http://github.com/kimgr/asn1ate', - packages=[ - 'asn1ate', - 'asn1ate.support', - ], - platforms=['any'], - install_requires=[ - 'pyparsing >=2.0.0, !=3.0.5, !=3.0.6', - ], - classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Topic :: Software Development :: Code Generators', - ], - entry_points={ - 'console_scripts': [ - 'asn1ate = asn1ate.pyasn1gen:main_cli' - ] - } -) diff --git a/src/asn1ate/__init__.py b/src/asn1ate/__init__.py new file mode 100644 index 0000000..b4182bd --- /dev/null +++ b/src/asn1ate/__init__.py @@ -0,0 +1,4 @@ +import importlib.metadata + +# asn1ate version +__version__ = importlib.metadata.version("asn1ate") diff --git a/asn1ate/parser.py b/src/asn1ate/parser.py similarity index 100% rename from asn1ate/parser.py rename to src/asn1ate/parser.py diff --git a/asn1ate/pyasn1gen.py b/src/asn1ate/pyasn1gen.py similarity index 100% rename from asn1ate/pyasn1gen.py rename to src/asn1ate/pyasn1gen.py diff --git a/asn1ate/sema.py b/src/asn1ate/sema.py similarity index 100% rename from asn1ate/sema.py rename to src/asn1ate/sema.py diff --git a/asn1ate/support/__init__.py b/src/asn1ate/support/__init__.py similarity index 100% rename from asn1ate/support/__init__.py rename to src/asn1ate/support/__init__.py diff --git a/asn1ate/support/pygen.py b/src/asn1ate/support/pygen.py similarity index 100% rename from asn1ate/support/pygen.py rename to src/asn1ate/support/pygen.py diff --git a/asn1ate/test.py b/src/asn1ate/test.py similarity index 100% rename from asn1ate/test.py rename to src/asn1ate/test.py