question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for custom commands and functions

See original GitHub issue

Hello,

When using setup.py, it is possible to customize commands or use functions to get some results dynamically.

For instance, to run a post install script (that requires dependencies to be installed) one can write this:

class CustomInstallCommand(install):
    def _post_install(self):
        # Some stuff to do

    def __init__(self, *args, **kwargs):
        super(CustomInstallCommand, self).__init__(*args, **kwargs)
        atexit.register(self._post_install)

and use this class as keyword argument value in the setup() call:

cmdclass={'install': CustomInstallCommand}

(other commands like clean, test, tox can be customized this way too).

Second example, in order to compile translation files (po files) into mo files at setup time:

def create_mo_files():
    data_files = []
    # do stuff
    return data_files

and use the result as keyword argument value in the setup() call:

data_files=create_mo_files()

It looks quite obvious that it’s not possible to do such things if one uses only a pyproject.toml file: how would it import a class or a function, or know about it, how to run it? (Or is there a way?)

From reading the code, I’ve seen that the keyword arguments list passed to setup() is hard coded (to build a sdist), so cmdclass and data_files are not usable at the moment (if I’m not wrong).

I guess this is not the easiest feature to implement. Is it planned or already discussed?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:9
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

18reactions
stinovlascommented, Sep 25, 2019

I was just researching Poetry as one of possibilities for our new workflow and I bumped into this issue. Up until now, we’ve been using good old setup.py with several custom build cases:

  • compiling translation files .po → .mo (has already been mentioned)
  • compiling grpc protocol buffers to python modules
  • calling webpack to transpile and bundle the JavaScript code in our django apps

If Poetry doesn’t plan to support these custom build steps, we could:

  1. add generated binary/minified files to our versioning system (ugh…)
  2. call these build steps manually (let’s say from a Makefile) before running calling poetry build; unfortunately, that clashes with Poetry excluding files mentioned in .gitignore, but maybe there is a way around it; still, this way seems to be prone to errors (what if I forget to call them?), but kind of OK for the CI use i guess
  3. not use Poetry for the projects that require this (unfortunately, most of our projects requires at least the translations build step – so that would basically mean not using Poetry at all)

I really like Poetry and I thought it could be a solution to our current problems. But without these custom build steps, I’m afraid we won’t be able to use it. @sdispater, do you think that there is any way around this? Any chance we could add a hook that would run before each call of poetry build (basically option 2 above, but without the manual component)? That wouldn’t necessarily mean adding some executable files to Poetry itself, just being able to call a python function (or a shell script, but I’m much more inclined to Python callable). Or could this be somehow achieved by plugins?

1reaction
sdispatercommented, Mar 2, 2019

I don’t plan on supporting this. The whole idea of Poetry and pyproject.toml in general is to not have executable files to setup a project so it’s unlikely it will ever be implemented.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Commands - Cypress Documentation
Cypress comes with its own API for creating custom commands and overwriting existing commands. The built in Cypress commands use the very same...
Read more >
Cypress - Custom Commands - Tutorialspoint
Cypress custom commands are described by users and not the default commands from Cypress. These customized commands are used to create the test...
Read more >
Custom Commands in Cypress - Tools QA
What are custom commands in Cypress and the recommended best practices? How to add Custom commands documentation in Cypress Intellisense?
Read more >
Write your own Cypress custom commands - Level Up Coding
Custom Commands. In your Cypress project, you would have a 'cypress > support > commands' folder. Within this folder you can create a...
Read more >
Cypress - Create My Own Cypress Commands - Justin James
Angular Material Grid Is Sorted By Column & Direction. Custom Command Code: Copy export function gridSortValidateSortOrder(columnName, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found