Skip to content
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

Replace make + Makefile file with Python Invoke library + tasks.py file #1239

Merged
merged 35 commits into from
Nov 27, 2023

Conversation

ibc
Copy link
Member

@ibc ibc commented Nov 23, 2023

Fixes #701

Details

  • Use Python Invoke package to replace make.
  • Invoke is automatically installed in a local path during mediasoup installation (in Node and Rust).
  • Keep worker/Makefile as a proxy to Invoke tasks defined in worker/tasks.py.
  • Everything works as before, nothing has changed from the user or developer perspective.

Bonus Tracks

Minor Details

  • Get rid of getmake.py and cpu_cores.sh scripts.
  • Update Building.md.

@ibc ibc requested review from jmillan and nazar-pc November 23, 2023 13:49
Copy link
Collaborator

@nazar-pc nazar-pc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally a brave soul decided to tackle it!

package.json Outdated Show resolved Hide resolved
@ibc
Copy link
Member Author

ibc commented Nov 23, 2023

@nazar-pc you know what this is doing exactly?

ifeq ($(OS),Windows_NT)
ifeq ($(MESON_ARGS),"")
	MESON_ARGS = $(subst $\",,"--vsenv")
endif
endif

As per my understanding it's basically doing this:

"If this is Windows and MESON_ARGS env is not set, set "--vsenv" value to it".

But I don't understand that "subst" thing at all...

@nazar-pc
Copy link
Collaborator

But I don't understand that "subst" thing at all...

I vaguely remembered that simple assigning was adding quotes around the value, so it wasn't setting MESON_ARGS="--vsenv", it was doing MESON_ARGS="\"--vsenv\"". Do not ask me why, it makes no sense to me either and I wasted way too much time trying to make sense of it, but I found that snippet somewhere that I can't interpret even after reading docs, that makes it work the way it should. I don't think you need to worry about it in Python though.

worker/tasks.py Outdated Show resolved Hide resolved
@ibc
Copy link
Member Author

ibc commented Nov 24, 2023

@nazar-pc
Copy link
Collaborator

Why not installing all dependencies at once rather than separately if you know you'll need them? Then yo should not hit that issue and shouldn't need to have multiple directories.

@ibc
Copy link
Member Author

ibc commented Nov 24, 2023

Why not installing all dependencies at once rather than separately if you know you'll need them? Then yo should not hit that issue and shouldn't need to have multiple directories.

Because I prefer to not having to install pylint and all its subdependencies (as a requirement) in production environment. It would be sad that we solve that in npm ("dependencies" vs "devDependencies") and not in Python. And also for another reason:

As a solution for TODO 1 (see updated PR description) I'm about to suggest that npm prepare task installs invoke into a custom PIP folder so user doesn't need to do it. Now, if we use a custom pip folder and later try to reuse it for meson and ninja... same problem again. So I think that having separate pip setups for different needs it's ok. I mean, it's PIP fault.

@ibc
Copy link
Member Author

ibc commented Nov 24, 2023

OEEEE OEEEE OEEEE all CI passing!!!

@jmillan @nazar-pc Let's please discuss the TODO 1 in the PR description.

@ibc
Copy link
Member Author

ibc commented Nov 24, 2023

CI is gonna fail now due to this (on purpose): 36a5e90

@ibc
Copy link
Member Author

ibc commented Nov 24, 2023

To play with CI I've created a separate branch https://github.com/versatica/mediasoup/tree/replace-make-with-pip-invoke-ci-playground

@ibc
Copy link
Member Author

ibc commented Nov 24, 2023

Interesting. The "ModuleNotFoundError: No module named 'imp'" in macOS 12 CI tasks happens with these versions in the CI host:

  • Python 3.12.0
  • pip 23.3.1 from /Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pip (python 3.12)

And it works in my macOS:

  • Python 3.11.5
  • pip 23.3.1 from /usr/local/lib/python3.11/site-packages/pip (python 3.11)

Same pip version, which is the latest one: https://pypi.org/project/pip/
:(

UPDATE:

The problem is that Python 3.12 doesn't have imp module anymore. And invoke didn't properly migrated to importlib!!!

@ibc
Copy link
Member Author

ibc commented Nov 24, 2023

So the only remaining thing is installing invoke in worker/pip_invoke in build.rs before calling python -m invoke xxxx (obvious).

I need to replicate in Rust this code:

const PYTHON = getPython();

function getPython()
{
	let python = process.env.PYTHON;

	if (!python)
	{
		try
		{
			execSync('python3 --version', { stdio: [ 'ignore', 'ignore', 'ignore' ] });
			python = 'python3';
		}
		catch (error)
		{
			python = 'python';
		}
	}

	return python;
}

if (fs.existsSync(PIP_INVOKE_DIR))
{
	return;
}

// Install pip invoke into custom location, so we don't depend on system-wide
// installation.
executeCmd(
	`${PYTHON} -m pip install --upgrade --target=${PIP_INVOKE_DIR} invoke==${INVOKE_VERSION}`, /* exitOnError */ true
);

Any help please? Specially getting the python3 executable (unless it's ok if we assume env PYTHON || 'python3').

@ibc
Copy link
Member Author

ibc commented Nov 24, 2023

Rust thing almost done: 00df131 and 61664e5

@ibc ibc changed the title Replace make with pip invoke Replace make & Makefile file with Python Invoke library & tasks.py file Nov 25, 2023
@ibc ibc marked this pull request as ready for review November 25, 2023 10:32
@ibc ibc requested a review from nazar-pc November 25, 2023 10:33
@ibc
Copy link
Member Author

ibc commented Nov 25, 2023

PR completely ready for review.

@ibc ibc changed the title Replace make & Makefile file with Python Invoke library & tasks.py file Replace make + Makefile file with Python Invoke library + tasks.py file Nov 25, 2023
npm-scripts.mjs Outdated Show resolved Hide resolved
Copy link
Member

@jmillan jmillan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@ibc ibc merged commit 3f0594d into v3 Nov 27, 2023
36 checks passed
@ibc ibc deleted the replace-make-with-pip-invoke branch November 27, 2023 12:27
Copy link
Collaborator

@nazar-pc nazar-pc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looked through most things briefly.

I think that needs to change is Makefile. I think we should remove it or mention it in Building.md The fact that we still have it (and you, @ibc, plan to use it) while we're documenting that users need to install and use invoke instead (whose version doesn't guarantee to match actually) is odd. It feels inconsistent right now.

On a similar note I'd say we should remove numerous scripts from package.json too and make users call invoke/make instead there too for consistency. Otherwise right now we have 3 ways to format worker, which makes little sense to me to have.

Comment on lines +112 to +113
let mut pythonpath = if env::var("PYTHONPATH").is_ok() {
let original_pythonpath = env::var("PYTHONPATH").unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not idiomatic, you should do this instead:

Suggested change
let mut pythonpath = if env::var("PYTHONPATH").is_ok() {
let original_pythonpath = env::var("PYTHONPATH").unwrap();
let mut pythonpath = if let Ok(original_pythonpath) = env::var("PYTHONPATH") {

);
// Install Python invoke package in custom folder
let pip_invoke_dir = format!("{out_dir}/pip_invoke");
let invoke_version = "2.2.0";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a good reason why we need this specific version? By not specifying a version we'll get support for future Python versions and bugfixes for free.

If we do need it, this should be a constant at the top of the file instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know yet how Invoke library behaves regarding compatibility or breaking changes. I think it's ok to force version 2.2.0 which we know it works in all archs. This doesn't mean we should never upgrade it. But I'm not confident enough to say ·any future version will work without changes anywhere".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think checking their changelog is a pretty good indicator

.arg("pip")
.arg("install")
.arg("--upgrade")
.arg(format!("--target={pip_invoke_dir}"))
Copy link
Collaborator

@nazar-pc nazar-pc Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be two separate arguments instead?:

Suggested change
.arg(format!("--target={pip_invoke_dir}"))
.arg("--target")
.arg(pip_invoke_dir)

"worker/test/include",
"worker/test/src",
"worker/deps/libwebrtc",
"worker/tasks.py",
Copy link
Collaborator

@nazar-pc nazar-pc Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why most of the files here were changed, they were in alphabetical order before and now they are in random order instead (worker/src is now before worker/include, etc.).

Also Makefile should be removed from this list and similar changes need to be done in worker/Cargo.toml too.

@ibc
Copy link
Member Author

ibc commented Nov 27, 2023

I think that needs to change is Makefile. I think we should remove it or mention it in Building.md The fact that we still have it (and you, @ibc, plan to use it) while we're documenting that users need to install and use invoke instead (whose version doesn't guarantee to match actually) is odd. It feels inconsistent right now.

I'm honoring all comments in a separate branch, but I don't want to git rid of Makefile. It's a simple additional file. It's just a convenient thing in case people don't want to deal with Invoke yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Installation fails under path with whitespaces Replace Makefile with Python script
3 participants