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.

Add support for absolute imports

See original GitHub issue

Currently only relative imports are supported for local packages, however that is definitely not the pythonic way to do things. In Python absolute imports are preferred over relative imports.
Also few things are difficult by just using relative imports:

# file: constants.py
A = "a"
B = "b"

# file: main.py
from .constants import A, B  # works fine
import .constants   # Doesn't work!

By this behaviour, Python functions app forces from ... import ... syntax which is not always preferred and many times against organization specific style guidelines.

Repro steps

Covered above.

Expected behavior

Absolute imports should be supported as per python guidelines.

Actual behavior

It fails!

Known workarounds

Use relative imports

Related information

On issue #81, relative imports are suggested.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
brettcannoncommented, Mar 19, 2019

One key point that I want to make sure gets documented is if you’re going to require __app__ as the top-level directory, then anyone who wants to run their Function code outside of the Function runtime (e.g. CI for unit tests) must keep their entire Function directory in an __app__ folder in order for those imports to resolve appropriately. IOW this will will essentially dictate the folder name that everyone’s Function-related files must be kept in if anyone chooses to use absolute imports.

1reaction
Kagigzcommented, Apr 3, 2019

@maiqbal11 no problem! I’ve created another issue: #374

Read more comments on GitHub >

github_iconTop Results From Across the Web

Making Life Easier with Absolute Imports - React in Javascript ...
According to create-react-app Docs, We can use absolute imports in our react project by configuring a jsconfig.json / tsconfig.json (for ...
Read more >
Why and How to Use Absolute Imports in React
Using absolute imports to better organize your React project is a great way. Relative imports are hard to follow and break during ...
Read more >
Adding Support For Absolute Imports | halesworth.org
How to add support for absolute imports in your React apps. ... Add the following to your jsconfig.json or tsconfig.json at the root...
Read more >
Absolute Import in React | create-react-app - BezKoder
In this tutorial, I will show you how to configure your React application to support 'Absolute Import' (Javascript and Typescript) with ...
Read more >
Advanced Features: Absolute Imports and Module Path Aliases
Configure module path aliases that allow you to remap certain import paths. ... Next.js automatically supports the tsconfig.json and jsconfig.json "paths" ...
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