how to execute a script that will modify my package at build time? #3909
-
in ipyvuetify, we have the following package structure:
The main package is ipyvuetify but the content is generated from the vuetify.js API. To buid the source, we need to execute a function that live in generate_source.py. Until now we were adding these source at release time but that makes developping in the lib complicated. We try to make the build of the widget automatic and included in the python build. When we try to importe "genreate_source" module in the setup.py it doesn't work (moduleNotFound). Which prevent us from updating the in case it's an xy issue, is there a better way to include this content in the distrib at build time without storing it in the distant repository ? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
Hi @12rambau maybe a custom build sub-command would work for you? Something like: # setup.py
import os
import sys
from setuptools immport Command, setup
from setuptools.command.build import build
sys.path.append(os.path.dirname(__file__))
from genreate_source import generate_schema, generate_source
class custom_build(build):
sub_commands = [("build_vuetify", None), *build.sub_commands]
class build_vuetify(build):
# See interface in https://setuptools.pypa.io/en/latest/userguide/extension.html
def initialize_options(self):
self.editable_mode = False
self.build_lib = None
...
def finalize_options(self):
self.set_undefined_options('build', ('build_lib', 'build_lib'))
...
def get_source_files(self): ...
def get_outputs(self): ...
def get_output_mapping(self): ...
def run(self): ...
setup(
...
cmdclass={"build": custom_build, "build_vuefy": build_vuetify},
)
# Untested code, written from memory, please review :P |
Beta Was this translation helpful? Give feedback.
-
thanks @abravalheri. This is exactly what we want to do. the only issue for us is that the "generate" method lives in another folder (not something we can change because of the webpack binding). So the main difference between your code and mine (https://github.com/12rambau/ipyvuetify/blob/install/setup.py) is that I try to call a script from another file. When doing so the error is "moduleNotFound" even though the package is just here next to setup.py. Is there a way to import it to setup.py or is there something I misendurstood about installation steps ? |
Beta Was this translation helpful? Give feedback.
-
sorry for asking again about my specific issue. I implemented your suggestions and I'm still facing a challenge. Now I manage to execute NPM packaging operations but I failed to complete the build command. One of the genering operation is populating a js/generated folder.
Diving into my commands it's normal because files where built in /home/ not in tmp/. How can I move these files to the tmp/ build directory after they are created ? |
Beta Was this translation helpful? Give feedback.
Hi @12rambau maybe a custom build sub-command would work for you?
Something like: