Skip to content

Commit

Permalink
Merge pull request #38 from mostypc123/req2
Browse files Browse the repository at this point in the history
Requirements.txt Generation
  • Loading branch information
mostypc123 authored Dec 14, 2024
2 parents 5602c38 + b008d42 commit 880984d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ To contribute:
- Automatic labeling based on description content
- PRs prefixed with ```[WIP]``` will automatically bypass the review process.

## Adding a README translation
In the /readme-translations folder, add a new file, e. g. ja-README.md.
Then add it to the list in the README.

## Frequently Asked Questions

### Where is the source code?
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
![](https://github.com/mostypc123/XediX/blob/main/images/xediximage.png?raw=true)
# XediX - Python Text Editor

XediX is a lightweight, open-source text editor designed specifically for Python developers. Combining simplicity with essential features, XediX aims to enhance your Python coding experience.

![GitHub stars](https://img.shields.io/github/stars/mostypc123/XediX?style=plastic)
Expand All @@ -12,6 +11,15 @@ XediX is a lightweight, open-source text editor designed specifically for Python
![GitHub contributors](https://img.shields.io/github/contributors/mostypc123/XediX.svg?style=plastic)
![Top language](https://img.shields.io/github/languages/top/mostypc123/XediX.svg?style=plastic)

<div align="center">

**English** - [Slovak](https://github.com/mostypc123/XediX/blob/req2/readme-translations/sk-README.md)

Want to add your own translation? [Contributing guidelines](https://github.com/mostypc123/XediX/blob/main/CONTRIBUTING.md)

</div>


> [!IMPORTANT]\
> If you find XediX helpful and want to support the project, please give it a star on GitHub! Your star helps others discover XediX and motivates continued development.
Expand Down
1 change: 0 additions & 1 deletion readme-translations/sk-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ XediX je ľahký, open-source textový editor navrhnutý špeciálne pre Python
![Top language](https://img.shields.io/github/languages/top/mostypc123/XediX.svg)

## Prehľad
![](http://github-profile-summary-cards.vercel.app/api/cards/profile-details?username=mostypc123)

XediX poskytuje výkonné, čisté a nerušené prostredie pre Python programovanie, čím je ideálny pre začiatočníkov aj skúsených vývojárov. Tu sú dôvody, prečo si XediX zamilujete:

Expand Down
2 changes: 2 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ In this folder, you can find the source code of XediX. **Here is a explanation o
really? do you need a description of a file that is called main?!
### tools.py
The tools selector in XediX, when you press <kbd>Ctrl</kbd>+<kbd>T</kbd>, or select _Tools_ / _Tools_ in the menu.
### requirements.py
A requirements.txt generator.
### tools/*
The tools included in XediX.
### requirements.txt
Expand Down
21 changes: 19 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Library imports
import wx
import wx.stc as stc
import os
Expand All @@ -7,11 +8,12 @@
import pywinstyles
import psutil
import webbrowser

# Local imports
import extension_menubar
import extension_mainfn
import extension_mainclass


import requirements

class TextEditor(wx.Frame):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -185,6 +187,9 @@ def CreateMenuBar(self):

toolsMenu = wx.Menu()
tools_item = toolsMenu.Append(wx.ID_ANY, '&Tools\tCtrl+T', 'Run Tools')
deployment_submenu = wx.Menu()
req_item = deployment_submenu.Append(wx.ID_ANY, 'Generate requirements.txt')
toolsMenu.AppendSubMenu(deployment_submenu, 'Deployment Tools')
customize_item = toolsMenu.Append(wx.ID_ANY, '&Customize\tCtrl+Shift+C', 'Customize the UI')


Expand All @@ -207,6 +212,7 @@ def CreateMenuBar(self):
self.Bind(wx.EVT_MENU, self.OnRunCode, run_item)
self.Bind(wx.EVT_MENU, self.run_tools_script, tools_item)
self.Bind(wx.EVT_MENU, self.OnCustomize, customize_item)
self.Bind(wx.EVT_MENU, self.RequirementsGeneration, req_item)
self.Bind(wx.EVT_MENU, self.OnExit, exit_item)
self.Bind(wx.EVT_MENU, self.OnCut, cut_item)
self.Bind(wx.EVT_MENU, self.OnCopy, copy_item)
Expand Down Expand Up @@ -239,6 +245,17 @@ def Homepage(self, event):
webbrowser.open("https://xedix.w3spaces.com")
self.SetStatusText(" Webpage opened", 2)

def RequirementsGeneration(self, event):
current_tab = self.notebook.GetCurrentPage()
if current_tab:
text_area = current_tab.GetChildren()[0]
code = text_area.GetValue()
with open("requirements.txt", "w") as file:
file.write(requirements.main(code))
self.SetStatusText("Saved requirements.txt")
else:
self.SetStatusText("Error saving requirements")

def OnJumpToLine(self, event):
current_tab = self.notebook.GetCurrentPage()
if current_tab:
Expand Down
19 changes: 19 additions & 0 deletions src/requirements.py
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))

0 comments on commit 880984d

Please sign in to comment.