Skip to content

Commit

Permalink
Replaced deprecated setup.py with setup.cfg
Browse files Browse the repository at this point in the history
Also bumped version to 0.7.5, with packaging being the
only change.

The old setup.py method is deprecated and will be removed
in future python3 versions. The rationale behind this is
that the setup.py script runs arbitrary code at install time.

Our setup.py file used to dynamically determine the current
version at install time by querying git. While this makes
it more forgiving as a developer (setting a new tag is enough,
no version update in any file is necessary) it's generally bad
practice.

I suggest setting a github action that fills this role, if
possible. Otherwise we must remember to manually update the
"version" attribute in the setup.cfg file when releasing a
new version.
  • Loading branch information
Björn Wärmedal committed Oct 10, 2023
1 parent 58ee7b7 commit 41ea724
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 71 deletions.
2 changes: 1 addition & 1 deletion nml/expression/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

is_valid_id = re.compile("[a-zA-Z_][a-zA-Z0-9_]{3}$")


def identifier_to_print(name):
"""
Check whether the given name is a valid 4 letter identifier to print
Expand All @@ -50,3 +49,4 @@ def identifier_to_print(name):
if is_valid_id.match(name):
return name
return '"{}"'.format(name)

6 changes: 0 additions & 6 deletions nmlc

This file was deleted.

30 changes: 30 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[metadata]
name = nml
version = 0.7.5
description = An OpenTTD NewGRF compiler for the nml language
long_description = file: README.md
long_description_content_type = text/markdown
home_page = https://github.com/OpenTTD/nml
author = NML Development Team
author_email = [email protected]
license = GPL-2.0+
classifiers =
Development Status :: 2 - Pre-Alpha
Intended Audience :: Developers
License :: OSI Approved :: GNU General Public License (GPL)
Operating System :: OS Independent
Programming Language :: Python :: 3
Topic :: Software Development :: Compilers

[options]
packages = nml,nml.actions,nml.ast,nml.editors,nml.expression,nml.generated
python_requires = >= 3.5
setup_requires =
setuptools >= 38.3.0
install_requires =
Pillow>=3.4
ply

[options.entry_points]
console_scripts =
nmlc = nml.main:run
66 changes: 2 additions & 64 deletions setup.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,64 +1,2 @@
#!/usr/bin/env python3

from setuptools import Extension, find_packages, setup
from setuptools.command.build_py import build_py

try:
# Update the version by querying git if possible.
from nml import version_update

NML_VERSION = version_update.get_and_write_version()
except ImportError:
# version_update is excluded from released tarballs, so that
# only the predetermined version is used when building from one.
from nml import version_info

NML_VERSION = version_info.get_nml_version()


class NMLBuildPy(build_py):
def run(self):
# Create a parser so that nml/generated/{parse,lex}tab.py are generated.
from nml import parser

parser.NMLParser(rebuild=True)
# Then continue with the normal setuptools build.
super().run()


setup(
name="nml",
version=NML_VERSION,
packages=find_packages(),
description="An OpenTTD NewGRF compiler for the nml language",
long_description=(
"A tool to compile NewGRFs for OpenTTD from nml files"
"NML is a meta-language that aims to be a lot simpler to"
" learn and use than nfo used traditionally to write NewGRFs."
),
license="GPL-2.0+",
classifiers=[
"Development Status :: 2 - Pre-Alpha",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Software Development :: Compilers",
],
url="https://github.com/OpenTTD/nml",
author="NML Development Team",
author_email="[email protected]",
entry_points={"console_scripts": ["nmlc = nml.main:run"]},
ext_modules=[Extension("nml_lz77", ["nml/_lz77.c"], optional=True)],
python_requires=">=3.5",
install_requires=[
"Pillow>=3.4",
"ply",
],
cmdclass={"build_py": NMLBuildPy},
)
from setuptools import setup
setup()

0 comments on commit 41ea724

Please sign in to comment.