-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] finalize_distribution_options #3447
Comments
Hi @gentlegiantJGC, thank you very much for opening this discussion. There are 2 facts in play regarding this issue.
Is the project that you are working with opensource? Could I have a look on it? |
I am trying to add code that runs during the build step to modify the files. I added a minimal reproducible example as a zip above the console logs in the report but it just prints a line. The project I am using this in is here. |
Hi @gentlegiantJGC thank you very much for the extra info.
If you want to do that for a single project, maybe instead of If you want to do that for multiple projects, than you can use the SuggestionLet's keep the custom build steps code into a private folder
On # setup.py
import os
import sys
from setuptools import setup
from setuptools.command.build import build as orig_build
sys.path.append(os.path.join(os.path.dirname(__name__), "_build_steps"))
from custom_finalise import Finalise
class build(orig_build):
sub_commands = [
*orig_build.sub_commands,
("custom_finalise", None)
]
setup(
cmdclass={"build": build, "custom_finalise": Finalise}
) Then in # _build_steps/custom_finalise.py
from setuptools import Command
from setuptools.dist import Distribution
class Finalise(Command):
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
print("*********** do some things **************") Don't forget to add this file to the sdist either via recursive-include my_package *.py
recursive-include _build_steps *.py |
Thanks. That is nicer than the original subclassing system I had. Do you know why |
If I am not wrong, this happens because I think it is problematic to add the customisation to your project’s own entry-points, right? This would mean that setuptools will try to use the custom build step you define with every single package you try to build in that env...
I don't think it is bug. Setuptools uses this trick to add build-time only entry-points for its own build (you can see in the repository it has a |
Okay. Thanks for the help. I think for this to work in editable mode as well the command would need to be registered as a subcommand of the develop command as well. |
setuptools version
63.1.0
Python version
3.9.13
OS
Windows
Additional environment information
No response
Description
I am trying to implement a sub-command to extend setuptools to add a compile step however this is only run if the local path is added to the python path. This may be an issue in conjunction with the build library.
I am trying to implement this behaviour as was linked to in #2899
I have defined the function in the
setup.cfg
file however this is only run if the local path is added to sys.path in thesetup.py
fileWhen running
python -m build
that function is not run.If the following line is added to the
setup.py
file the function will get called and everything will run as expected.sys.path.append(os.path.dirname(__name__))
Sorry if there is something I am misunderstanding here.
Expected behavior
finalize_distribution_options should be able to work with build without modifying the python path.
How to Reproduce
build
python -m build
custom_finalise
was not runpython -m build
againcustom_finalise
was run with the following line being*********** do some things **************
finalize_distribution_options.zip
Output
Console output with
sys.path.append(os.path.dirname(__name__))
commented outConsole output after with
sys.path.append(os.path.dirname(__name__))
uncommentedThe text was updated successfully, but these errors were encountered: