-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from mostypc123/req2
Requirements.txt Generation
- Loading branch information
Showing
6 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
def main(code): | ||
requirements = set() | ||
for line in code.split("\n"): | ||
line = line.strip() | ||
if line.startswith("import ") or line.startswith("from "): | ||
# Extract the module name | ||
if line.startswith("import "): | ||
module = line.replace("import ", "").split()[0] | ||
else: # from ... import ... | ||
module = line.split()[1] | ||
|
||
# Remove any potential alias | ||
module = module.split(" as ")[0] | ||
|
||
# Add to requirements (using a set to avoid duplicates) | ||
requirements.add(module) | ||
|
||
# Convert requirements to a format suitable for requirements.txt | ||
return "\n".join(sorted(requirements)) |