-
Notifications
You must be signed in to change notification settings - Fork 202
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
Draft: Add repository directory to path when importing files from repository #1805
base: master
Are you sure you want to change the base?
Conversation
@lriesebos by the way this actually (kind of) allows git integration with our directory structure if you add a top-level |
Here's what I've done to test so far (repos are public):
Some potential points for discussion:
|
Hi @b-bondurant, thanks for taking some steps forwards on this! One comment: my suggestion of using an If instead we're adding the repository path to
, linters and IDEs will expect |
How about something like this instead? def file_import(filename, prefix="file_import_", repository_path=None):
filename = pathlib.Path(filename)
modname = prefix + filename.stem
if repository_path:
# find any importable modules
for path in os.listdir(repository_path):
if os.path.isdir(path) and (pathlib.Path(path) / "__init__.py").exists():
sys.path.insert(0, path) |
Okay just kidding, nothing that I did in a151b57 actually fixed anything and I wasn't actually testing the thing that needed to be tested (i.e. the original scenario presented in the issue). This is why we don't start new work late on a Friday afternoon. But, tweaking the way that imports are done for in-repo experiments seems to do the trick at first glance, and doesn't actually require any extraneous Using the original example file structure from #1543 (minus the
For importing $ cd experiments/foo
$ python -c "import bar" new structure: $ cd experiments
$ python -c "import foo.bar" IMO it seems like an intuitive change, and all existing unit tests still pass so hopefully I haven't broken anything. |
|
LGTM. You're exploiting python's namespaced packages mechanism for the import of modules in subdirectories; I can't think of a problem with that. With
I still personally think that
Does it? The path-altering code is unaltered from before and protected by a try/finally (and runs in the worker). |
FWIW, that's relatively easy to get around with most tools - e.g. in PyCharm, a simple right click on
Yeah, originally I forgot to add the
Still true with my most recent commit, but I'd argue that it's kind of an intuitive discrepancy. In the case of an in-repo experiment, I think it makes sense that files would be imported with "knowledge" of the surrounding repository, or to put it in a different way, imported with the repository as the working directory. Whereas for standalone files submitted from outside the repository, I would have no such expectation. However, we could mitigate that discrepancy by adding an extra field in the out-of-repo file browser to allow users to specify an effective "repository" directory for the file. For As for modifying |
I don't understand the user workflow with patches like this. How do you debug an experiment that relies on this? Do you commit it every time? |
^ Meh? Obviously the UI could use some work but the basic functionality seems to be there. edit: Never mind, I got ahead of myself and didn't test well enough. Will try to see if it's fixable. |
Hm. So, the above commit works for the To make things work for submission as well, I think we'd need to consider bumping up the resolution of |
I'm not sure if there's a solution other than (1) adding an option in the GUI and elsewhere to specify a "repository folder" when submitting outside repos or (2) adding a repository path that is discovered based on the file being submitted or its location. |
My vote here would be (1). (2) seems like it could introduce strange failures which are confusing to debug. @b-bondurant That sounds pretty inevitable: if (for out-of-repo experiments) the root directory is a controllable parameter, it has to be part of the information passed to the scheduler (via
Sounds spot on to me. @sbourdeauducq I guess the workflow for testing would be one of
A better workflow would be to push your feature branch to the ARTIQ bare repo, and then call your experiments by setting the "Revision" in the experiment call to the name of your branch. That doesn't currently work, but could be another PR. |
P.S. |
Additionally, adding |
Happy Christmas, BTW 🙂 |
…dashboard-side variable names
…ia expid["repo_dir"]
Okay I think that takes care of things for submissions from the dashboard (functionally, at least). Now, for other interfaces:
|
Perhaps the master could support different sources at the same time then, and configuring them without restarting? Then you'd set up one in git mode and one in non-git mode. |
I could see that being really useful. If, instead of having the |
ARTIQ Pull Request
Description of Changes
When importing experiments from the repository, add the repository path to
sys.path
if it contains an__init__.py
. Very much a draft at this point, quickly thrown together as a proof-of-concept in order to get feedback.Related Issue
Closes #1543
Type of Changes
Steps (Choose relevant, delete irrelevant before submitting)
All Pull Requests
git commit --signoff
, see copyright).Code Changes
flake8
to check code style (follow PEP-8 style).flake8
has issues with parsing Migen/gateware code, ignore as necessary.Existing tests pass, but this probably warrants the addition of a few tests. I've done some local testing and imports seem to work for in-repo experiments (with git and file system repos).
Documentation Changes
cd doc/manual/; make html
) to ensure no errors.Git Logistics
git rebase --interactive
). Merge/squash/fixup commits that just fix or amend previous commits. Remove unintended changes & cleanup. See tutorial.git show
). Format:Licensing
See copyright & licensing for more info.
ARTIQ files that do not contain a license header are copyrighted by M-Labs Limited and are licensed under LGPLv3+.